Hi all.
I am new on this forum, but not new to manual trading and EA's. I am pleased to see the activity on ForexFactory and looking forward to get to know you better.
I am just about ready with my little simple EA, but stuck on coding the SL ordermodify for SHORT trades.
What I'm trying to accomplish is this;
When price reaches 20pips profit: adjust SL from -40pip to -20pips. (cut SL in half)
When price reaches 40pips profit: Trailingstop kicks in. (Breake even + +)
This works perfectly well for LONG positions, but not for SHORT positions.
If anyone can spot an obvious error/solution, I'd be forever grateful.
Here's the code :
Thank you in advance,
Oddvin
I am new on this forum, but not new to manual trading and EA's. I am pleased to see the activity on ForexFactory and looking forward to get to know you better.
I am just about ready with my little simple EA, but stuck on coding the SL ordermodify for SHORT trades.
What I'm trying to accomplish is this;
When price reaches 20pips profit: adjust SL from -40pip to -20pips. (cut SL in half)
When price reaches 40pips profit: Trailingstop kicks in. (Breake even + +)
This works perfectly well for LONG positions, but not for SHORT positions.
If anyone can spot an obvious error/solution, I'd be forever grateful.
Here's the code :
Inserted Code
double newSL; { if((Bid-OrderOpenPrice())>=200*Point) newSL=OrderOpenPrice()-200*Point; if((Bid-OrderOpenPrice())>=400*Point) newSL=Bid-(TrailingStop*Point); { newSL=NormalizeDouble(newSL,Digits); if(newSL>OrderStopLoss()) OrderModify(OrderTicket(),OrderOpenPrice(),newSL,OrderTakeProfit(),0,Green); return(0); } } } else // go to short position { if((OrderOpenPrice()-Ask)>=200*Point) newSL=OrderOpenPrice()+200*Point; if((OrderOpenPrice()-Ask)>=400*Point) newSL=(TrailingStop*Point)+Ask; { newSL=NormalizeDouble(newSL,Digits); if(newSL<OrderStopLoss() || OrderStopLoss()==0) OrderModify(OrderTicket(),OrderOpenPrice(),newSL,OrderTakeProfit(),0,Red); return(0); } } }
Thank you in advance,
Oddvin