tried it like this as well :
if(total==0&&triggerline>baseline) { ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,sll,tpl,comment,magic,0,Green); if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice()); } else Print("Error opening BUY order : ",GetLastError()); return(0); } if(total==0&&triggerline<baseline) { ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,sls,tps,comment,magic,Red); if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice()); } else Print("Error opening SELL order : ",GetLastError()); return(0); } return(0); } //---- for(cnt=0;cnt<total;cnt++) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if(OrderType()<=OP_SELL && // check for opened position OrderSymbol()==Symbol()) // check for symbol { if(OrderType()==OP_BUY) // long position is opened { if(TrailingStop>0) { if(Bid-OrderOpenPrice()>Point*TrailingStop) { if(OrderStopLoss()<Bid-Point*TrailingStop) { OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green); return(0); } } } } else // go to short position { if(TrailingStop>0) { if((OrderOpenPrice()-Ask)>(Point*TrailingStop)) { if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0)) { OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red); return(0); } } } } } } //---- return(0); } //+------------------------------------------------------------------+ void check_exit() { if(triggerline<baseline)close_longs=true; if(triggerline>baseline)close_shorts=true; //////////////////////// if(close_longs)close_longs(); if(close_shorts)close_shorts(); } void close_shorts() { /////////////////////////////////// if (total==0)close_shorts=false; int totalorders=OrdersTotal(); for (int i=totalorders-1;i>=0;i--) { OrderSelect(i,SELECT_BY_POS); { if (OrderMagicNumber()==magic&&OrderComment()==comment&&OrderSymbol()==Symbol() &&OrderType()==OP_SELL) OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),100,Red); } } return; ///////////////////////////////// } //+----------------------------------------------------------------------------------+ void close_longs() { /////////////////////////////////// if (total==0)close_longs=false; int totalorders=OrdersTotal(); for (int i=totalorders-1;i>=0;i--) { OrderSelect(i,SELECT_BY_POS); { if (OrderMagicNumber()==magic&&OrderComment()==comment&&OrderSymbol()==Symbol() &&OrderType()==OP_BUY) OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),100,Blue); } } return; ///////////////////////////////// } //+----------------------------------------------------------------------------------+didnt work
What didn't work? The modify part? Have you checked in journal if it's showing any errors?
it takes the first trade but does not close the trade and open a opposite order on a fresh signal...
e.g :
if ma1>ma2 -- Open a buy....time goes bye...now ma1<ma2...soo close the buy and open a sell....etc etc...
hope im making myself understood, im not great at explaining
I havnt been lazy either I have searched 3 forums for stop and revers code but cant find anything of value that will help me understand what i doing wrong
it takes the first trade but does not close the trade and open a opposite order on a fresh signal...
e.g :
if ma1>ma2 -- Open a buy....time goes bye...now ma1<ma2...soo close the buy and open a sell....etc etc...
hope im making myself understood, im not great at explaining
I havnt been lazy either I have searched 3 forums for stop and revers code but cant find anything of value that will help me understand what i doing wrong
Hi,
I don't see you calling the checkexit() fuction anywhere from your main program. How does it get's invoked?
One more thing is that you can actually do the closing if the crossing happens in the main program itself instead of calling the checkexit(). i.e. you can actually do a orderclose() inside the main for(cnt=0;cnt<total;cnt++) { } itself by checking the isCrossed variable for any reversal.
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL && OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY) // long position is opened
{
// check for trailing stop
Here you can check whether the isCrossed variable is 2. if it "2" then you need to close it since "2" means a crossing has definitely happened. Similarlyyou can do for if (OrderType() == OP_SELL) as well.
if crossed
loop through open orders (decrement)
if order magic == magic number and ordersymbol == symbol
if order type == buy
close buy
open sell
if order type == sell
close sell
open buy
if(triggerline<baseline)close_longs=true; if(triggerline>baseline)close_shorts=true;
If close_longs=true then close_shorts must be set to false. Eventually they will both be true.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
any one know how to do a true stop an reverse ea? ...I have been trying like below but hasn't worked:
I have also tried this method :
none of these actually take a trade when the two MA's cross each other and then close the trade and open a opposite trade if the MA's cross the opposite way...
its a simple stop and reverse i want but just is not working...any one hav any ideas?
thanx guys