EA problem with TakeProfit and StopLoss

 

Hello!

This code works ok. Order has no TP and no SL it closes when adxplus and adxminus cross.

extern bool Close_at_ADX_change=true;

if(adx>ADX_more_than && adxplus<adxminus && Close_at_ADX_change ){
                    ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0, "EA",MagicNumber,0,Red);
}

But when I don't want it to close at adxplus and adxminus cross I set Close_at_ADX_change=false and put this code, but it does not open any orders. If I replace StopLoss and TakeProfit place with 0 it opens orders.

if(adx>ADX_more_than && adxplus<adxminus && !Close_at_ADX_change ){
                    ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+(SL*places)*Point,Bid-(TP*places)*Point, "EA",MagicNumber,0,Red);
}
Anyone knows where is the probel?
 

I suspect you are on an ECN broker which won't allow SL and TP to be sent with an instant execution... you need to immediately modify the ticket... search the site, as there are solutions to this... I don't have any links handy.

V

 
Viffer:

I suspect you are on an ECN broker which won't allow SL and TP to be sent with an instant execution... you need to immediately modify the ticket... search the site, as there are solutions to this... I don't have any links handy.

V


Thank you! I add this code and see if it helps.
 

01005379:

I set Close_at_ADX_change=false and put this code, but it does not open any orders.

Anyone knows where is the probel?
Remove the
&& Close_at_ADX_change
at the OrderSend. The Close_at_ADX_change should be at code for a OrderClose.
 

I make code like this. It works but just for first open order.

if(adx>ADX_more_than && adxplus<adxminus && !Close_at_ADX_change ){
            ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3*places,0,0, "EA",MagicNumber,0,Red);
            OrderSelect(SELECT_BY_POS, MODE_TRADES);
            if(OrderType()==OP_SELL && OrderSymbol()== Symbol() && OrderComment()== "EA"){
                   OrderModify(OrderTicket(),8*places,OrderOpenPrice()+((SL*places)*Point),OrderOpenPrice()-((TP*places)*Point),0,CLR_NONE);
            }
}
Any idea what is wrong?