Cant set StopLoss using OrderModify(), only TakeProfit is working

 

Hi

I have been coding my own EA for the first time and so far all seems good. :)

To open a trade I used the OrderSend() command and it works as accepted. When i tried to

add in the SL and TP levels in the OrderSend() command, no order was being opened. When i set

both of them to 0, then it is fine.

I initially taught that it was a broker issue but i saw that if i use OrserSend together with TP alone, it is fine.

So then i tried to use the OrderModify() to set the StopLoss separately but that also didnt work.

Can someone please advise on what could be wrong and what I am missing.

The code snippet is as shown below:

extern int TakeProfit = 200;

extern int StopLoss = 60;

...

....

res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,0,Ask+TakeProfit*Point,"",MAGICMA,0,Blue);

if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES) == true)

{

OrderModify(OrderTicket(),OrderOpenPrice(),Ask-StopLoss*Point,0,0,Blue);

}

 

You could try

OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-StopLoss*Point,0,0,Blue);

What is the spread of the symbol that you are trying to modify?

Chances are that the stoploss that you are trying to place is too close to the current price.

If the pair has a spread of 30 points (3 pips), as soon as the buy order is opened, it loses 30 points as its value will be the Bid price.

That means that the stoploss that you are trying to place is only 30 points below the current price and probably too close

 
raviragas:

Hi

I have been coding my own EA for the first time and so far all seems good. :)

To open a trade I used the OrderSend() command and it works as accepted. When i tried to

add in the SL and TP levels in the OrderSend() command, no order was being opened. When i set

both of them to 0, then it is fine.

When you post code please use the SRC button: How to use the SRC button.


Why did your OrderModify() fail ? read this: What are Function return values ? How do I use them ?

 
GumRai:

You could try

OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-StopLoss*Point,0,0,Blue);

What is the spread of the symbol that you are trying to modify?

Chances are that the stoploss that you are trying to place is too close to the current price.

If the pair has a spread of 30 points (3 pips), as soon as the buy order is opened, it loses 30 points as its value will be the Bid price.

That means that the stoploss that you are trying to place is only 30 points below the current price and probably too close

what you tell is allright but modifyexample will reset takeprofit
so i would suggest in this case

OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-StopLoss*Point,OrderTakeProfit(),0,Blue);
 
deVries:

what you tell is allright but modifyexample will reset takeprofit
so i would suggest in this case


Yes, of course you are right. I copied and pasted from the OP and then just changed Ask to OrderOpenPrice and didn't look at TP.

This from the OP

OrderModify(OrderTicket(),OrderOpenPrice(),Ask-StopLoss*Point,0,0,Blue);
Reason: