This forum is in read-only mode now. You may discuss your questions on forums of MQL4.community and MQL5.community
BUY/SELL REVERSEBack to topics list |
|
PaulDawidowicz
2005.07.29 01:17
How can I get the system to reverse in the same bar?, when i exit the position, enter it in the opposit direction?
|
|
calidragon
2005.07.29 06:16
For a stop and reverse, I open a position in the opposite direction with twice the number of lots, then close the previous with the OrderCloseBy() using the newly opened ticket. Note this
may fail if you cant afford having three times the lots open, temporarily. If the newly open position attempt fails, then simply close current ticket and open new ticket during same tick. calidragon |
|
Vooch
2005.07.29 06:35
Here ya go:
/////////////////////////////////////////////////////////////////////////////////////////
// METATRADER 4 SCRIPT
// VoochBlindman.mq4
// Copyright © 2005 Michael Salvucci - All Rights Reserved
// http://www.Quantinetics.com
// Email vooch at vooch dot com
/////////////////////////////////////////////////////////////////////////////////////////
//
// Comments: This script loses money, but the purpose of this script is to provide
// an example of what MetaTrader 4 can do.
//
/////////////////////////////////////////////////////////////////////////////////////////
// 20050728 v1.01 Initial Release
/////////////////////////////////////////////////////////////////////////////////////////
// COPYRIGHTS AND WARRANTIES
// Copyright © 2005 Michael Salvucci - All Rights Reserved
// No reproduction is allowed without the express written consent of the owner
// No warranties are expressed or implied with the use of this product.
// TRADING IS RISKY! YOU CAN LOSE SOME OR ALL OF YOUR MONEY! USE AT YOUR OWN RISK!
/////////////////////////////////////////////////////////////////////////////////////////
extern int reversal=-50; // get out because we lost and reverse
extern int continuing =100; // sell and continue forward
/////////////////////////////////////////////////////////////////////////////////////////
// EXPERT START FUNCTION
/////////////////////////////////////////////////////////////////////////////////////////
int start() {
/////////////////////////////////////////////////////////////////////////////////////////
double lots=0.1;
double order_lots=0.1;
double order_open;
double order_stoploss = 0;
double order_takeprofit = 0;
int MagicNumber=254; // 254 spells Bli: 2=B 5=l 4=i
int ticket;
int z;
string ScriptName = "VoochBlindman-v1.01-"+Period();
int TotalTrades = OrdersTotal();
/////////////////////////////////////////////////////////////////////////////////////////
// Get the ball rolling
if(TotalTrades==0) {
// go long
order_open = Ask;
order_stoploss = 0;
order_takeprofit = 0;
order_lots=lots; // 0.1 Default since I'm just starting out
ticket=OrderSend(Symbol(),OP_BUY,order_lots,order_open,3,order_stoploss,order_takeprofit,ScriptName,MagicNumber,0,Lime);
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) {
// do nothing
} else {
Print("ERROR:",GetLastError()," OP_BUY Ask=",Ask," order_lots=",order_lots," OO=",order_open," SL=",order_stoploss," TP=",order_takeprofit);
}
}
// dump the long and go short
TotalTrades=OrdersTotal();
for(z=0;z<TotalTrades;z++) {
OrderSelect(z, SELECT_BY_POS, MODE_TRADES);
if ( (OrderSymbol()==Symbol()) && (OrderMagicNumber()==MagicNumber) && (OrderType()==0) ) { // 0=OP_BUY
if(Bid-OrderOpenPrice()<(reversal*Point)) {
OrderClose(OrderTicket(),OrderLots(),Bid,3,Orange);
// Do the reversal
ticket=OrderSend(Symbol(),OP_SELL,order_lots,order_open,3,order_stoploss,order_takeprofit,ScriptName,MagicNumber,0,Tomato);
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) {
// do nothing
} else {
Print("ERROR:",GetLastError()," OP_SELL Bid=",Bid," order_lots=",order_lots," OO=",order_open," SL=",order_stoploss," TP=",order_takeprofit);
}
}
}
}
// dump the short and go long
TotalTrades=OrdersTotal();
for(z=0;z<TotalTrades;z++) {
OrderSelect(z, SELECT_BY_POS, MODE_TRADES);
if ( (OrderSymbol()==Symbol()) && (OrderMagicNumber()==MagicNumber) && (OrderType()==1) ) { // 1=OP_SELL
if(OrderOpenPrice()-Ask<(reversal*Point)) {
OrderClose(OrderTicket(),OrderLots(),Ask,3,Orange);
// Do the reversal
ticket=OrderSend(Symbol(),OP_BUY,order_lots,order_open,3,order_stoploss,order_takeprofit,ScriptName,MagicNumber,0,Lime);
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) {
// do nothing
} else {
Print("ERROR:",GetLastError()," OP_BUY Ask=",Ask," order_lots=",order_lots," OO=",order_open," SL=",order_stoploss," TP=",order_takeprofit);
}
}
}
}
// dump the long and continue long
TotalTrades=OrdersTotal();
for(z=0;z<TotalTrades;z++) {
OrderSelect(z, SELECT_BY_POS, MODE_TRADES);
if ( (OrderSymbol()==Symbol()) && (OrderMagicNumber()==MagicNumber) && (OrderType()==0) ) { // 0=OP_BUY
if(Bid-OrderOpenPrice()>(continuing*Point)) {
OrderClose(OrderTicket(),OrderLots(),Bid,3,Orange);
ticket=OrderSend(Symbol(),OP_BUY,order_lots,order_open,3,order_stoploss,order_takeprofit,ScriptName,MagicNumber,0,Lime);
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) {
// do nothing
} else {
Print("ERROR:",GetLastError()," OP_BUY Ask=",Ask," order_lots=",order_lots," OO=",order_open," SL=",order_stoploss," TP=",order_takeprofit);
}
}
}
}
// dump the short and continue short
TotalTrades=OrdersTotal();
for(z=0;z<TotalTrades;z++) {
OrderSelect(z, SELECT_BY_POS, MODE_TRADES);
if ( (OrderSymbol()==Symbol()) && (OrderMagicNumber()==MagicNumber) && (OrderType()==1) ) { // 1=OP_SELL
if(OrderOpenPrice()-Ask>(continuing*Point)) {
OrderClose(OrderTicket(),OrderLots(),Ask,3,Orange);
ticket=OrderSend(Symbol(),OP_SELL,order_lots,order_open,3,order_stoploss,order_takeprofit,ScriptName,MagicNumber,0,Tomato);
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) {
// do nothing
} else {
Print("ERROR:",GetLastError()," OP_SELL Bid=",Bid," order_lots=",order_lots," OO=",order_open," SL=",order_stoploss," TP=",order_takeprofit);
}
}
}
}
/////////////////////////////////////////////////////////////////////////////////////////
// END OF EXPERT START FUNCTION
/////////////////////////////////////////////////////////////////////////////////////////
} // end of start()
/////////////////////////////////////////////////////////////////////////////////////////
|
|
PaulDawidowicz
2005.09.18 07:30
Here ya go:
/////////////////////////////////////////////////////////////////////////////////////////
// METATRADER 4 SCRIPT
// VoochBlindman.mq4
// Copyright © 2005 Michael Salvucci - All Rights Reserved
// http://www.Quantinetics.com
// Email vooch at vooch dot com
/////////////////////////////////////////////////////////////////////////////////////////
//
// Comments: This script loses money, but the purpose of this script is to provide
// an example of what MetaTrader 4 can do.
//
/////////////////////////////////////////////////////////////////////////////////////////
// 20050728 v1.01 Initial Release
/////////////////////////////////////////////////////////////////////////////////////////
// COPYRIGHTS AND WARRANTIES
// Copyright © 2005 Michael Salvucci - All Rights Reserved
// No reproduction is allowed without the express written consent of the owner
// No warranties are expressed or implied with the use of this product.
// TRADING IS RISKY! YOU CAN LOSE SOME OR ALL OF YOUR MONEY! USE AT YOUR OWN RISK!
/////////////////////////////////////////////////////////////////////////////////////////
extern int reversal=-50; // get out because we lost and reverse
extern int continuing =100; // sell and continue forward
/////////////////////////////////////////////////////////////////////////////////////////
// EXPERT START FUNCTION
/////////////////////////////////////////////////////////////////////////////////////////
int start() {
/////////////////////////////////////////////////////////////////////////////////////////
double lots=0.1;
double order_lots=0.1;
double order_open;
double order_stoploss = 0;
double order_takeprofit = 0;
int MagicNumber=254; // 254 spells Bli: 2=B 5=l 4=i
int ticket;
int z;
string ScriptName = "VoochBlindman-v1.01-"+Period();
int TotalTrades = OrdersTotal();
/////////////////////////////////////////////////////////////////////////////////////////
// Get the ball rolling
if(TotalTrades==0) {
// go long
order_open = Ask;
order_stoploss = 0;
order_takeprofit = 0;
order_lots=lots; // 0.1 Default since I'm just starting out
ticket=OrderSend(Symbol(),OP_BUY,order_lots,order_open,3,order_stoploss,order_takeprofit,ScriptName,MagicNumber,0,Lime);
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) {
// do nothing
} else {
Print("ERROR:",GetLastError()," OP_BUY Ask=",Ask," order_lots=",order_lots," OO=",order_open," SL=",order_stoploss," TP=",order_takeprofit);
}
}
// dump the long and go short
TotalTrades=OrdersTotal();
for(z=0;z<TotalTrades;z++) {
OrderSelect(z, SELECT_BY_POS, MODE_TRADES);
if ( (OrderSymbol()==Symbol()) && (OrderMagicNumber()==MagicNumber) && (OrderType()==0) ) { // 0=OP_BUY
if(Bid-OrderOpenPrice()<(reversal*Point)) {
OrderClose(OrderTicket(),OrderLots(),Bid,3,Orange);
// Do the reversal
ticket=OrderSend(Symbol(),OP_SELL,order_lots,order_open,3,order_stoploss,order_takeprofit,ScriptName,MagicNumber,0,Tomato);
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) {
// do nothing
} else {
Print("ERROR:",GetLastError()," OP_SELL Bid=",Bid," order_lots=",order_lots," OO=",order_open," SL=",order_stoploss," TP=",order_takeprofit);
}
}
}
}
// dump the short and go long
TotalTrades=OrdersTotal();
for(z=0;z<TotalTrades;z++) {
OrderSelect(z, SELECT_BY_POS, MODE_TRADES);
if ( (OrderSymbol()==Symbol()) && (OrderMagicNumber()==MagicNumber) && (OrderType()==1) ) { // 1=OP_SELL
if(OrderOpenPrice()-Ask<(reversal*Point)) {
OrderClose(OrderTicket(),OrderLots(),Ask,3,Orange);
// Do the reversal
ticket=OrderSend(Symbol(),OP_BUY,order_lots,order_open,3,order_stoploss,order_takeprofit,ScriptName,MagicNumber,0,Lime);
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) {
// do nothing
} else {
Print("ERROR:",GetLastError()," OP_BUY Ask=",Ask," order_lots=",order_lots," OO=",order_open," SL=",order_stoploss," TP=",order_takeprofit);
}
}
}
}
// dump the long and continue long
TotalTrades=OrdersTotal();
for(z=0;z<TotalTrades;z++) {
OrderSelect(z, SELECT_BY_POS, MODE_TRADES);
if ( (OrderSymbol()==Symbol()) && (OrderMagicNumber()==MagicNumber) && (OrderType()==0) ) { // 0=OP_BUY
if(Bid-OrderOpenPrice()>(continuing*Point)) {
OrderClose(OrderTicket(),OrderLots(),Bid,3,Orange);
ticket=OrderSend(Symbol(),OP_BUY,order_lots,order_open,3,order_stoploss,order_takeprofit,ScriptName,MagicNumber,0,Lime);
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) {
// do nothing
} else {
Print("ERROR:",GetLastError()," OP_BUY Ask=",Ask," order_lots=",order_lots," OO=",order_open," SL=",order_stoploss," TP=",order_takeprofit);
}
}
}
}
// dump the short and continue short
TotalTrades=OrdersTotal();
for(z=0;z<TotalTrades;z++) {
OrderSelect(z, SELECT_BY_POS, MODE_TRADES);
if ( (OrderSymbol()==Symbol()) && (OrderMagicNumber()==MagicNumber) && (OrderType()==1) ) { // 1=OP_SELL
if(OrderOpenPrice()-Ask>(continuing*Point)) {
OrderClose(OrderTicket(),OrderLots(),Ask,3,Orange);
ticket=OrderSend(Symbol(),OP_SELL,order_lots,order_open,3,order_stoploss,order_takeprofit,ScriptName,MagicNumber,0,Tomato);
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) {
// do nothing
} else {
Print("ERROR:",GetLastError()," OP_SELL Bid=",Bid," order_lots=",order_lots," OO=",order_open," SL=",order_stoploss," TP=",order_takeprofit);
}
}
}
}
/////////////////////////////////////////////////////////////////////////////////////////
// END OF EXPERT START FUNCTION
/////////////////////////////////////////////////////////////////////////////////////////
} // end of start()
/////////////////////////////////////////////////////////////////////////////////////////
|
|
PaulDawidowicz
2005.09.18 07:31
Will this doit?
OrderClose(OrderTicket(),OrderLots(),Bid,2,Violet); // close position ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,1,0,Ask+TakeProfit*Point,"Reversed Signal",16384,0,Blue |
Download MetaTrader 5 (450 Kb, web installer) — a new terminal for financial markets
