How can I get the system to reverse in the same bar?, when i exit the position, enter it in the opposit direction?
- Welcome to the world of XP_EMAs
- How to make a reversal in one trade ?
- Phoenix 2007 (new thread)
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
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
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() /////////////////////////////////////////////////////////////////////////////////////////
- Vooch
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() /////////////////////////////////////////////////////////////////////////////////////////
- Vooch
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
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
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
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register