Are you sure? What error do you get?
Note here OrderStopLoss() > (Ask + TrailingStop * pips2dbl) if SL = 0 sells will fail. Make it ( OrderStopLoss() > (Ask + TrailingStop * pips2dbl) || OrderStopLoss() < point)
Hi all,
I have one issue with trailing stop.
In code that follows when I use count down sell trailing do not work, but if start to count up it work fine.
Any clarification regarding the above ?
If your braces are numbered correctly, are they ?, this, and the code that follows it, is outside of the for loop . . .
if(OrderType()==OP_SELL && OrderSymbol()== Symbol()
Are you sure? What error do you get?
Note here OrderStopLoss() > (Ask + TrailingStop * pips2dbl) if SL = 0 sells will fail. Make it ( OrderStopLoss() > (Ask + TrailingStop * pips2dbl) || OrderStopLoss() < point)
Hi cyberfx.org,
Thank you for your prompt attention to my issue.
I have no errors in Journal tab, just when in sell the trail do not start. Right now I'm doing a test with your solution.
Luis
void Trail() {//0 int TrailingStop = 0.25 + StopLevel; double BaseProfit = 0.03; for(int OrderCounter = 0; OrderCounter <= OrdersTotal()-1; OrderCounter++) //for(int OrderCounter = OrdersTotal()-1; OrderCounter >= 0; OrderCounter--) {//23 if(!OrderSelect(OrderCounter,SELECT_BY_POS))continue; if(OrderType()==OP_BUY && OrderSymbol()== Symbol() && OrderMagicNumber()== MagicNumber) {//24 RefreshRates(); if(OrderStopLoss() < (Bid - TrailingStop * pips2dbl) && (Bid - OrderOpenPrice()) >= (MinimumProfit * pips2dbl)) {//25 if(!OrderModify(OrderTicket(),OrderOpenPrice(),Bid - (TrailingStop * pips2dbl), OrderTakeProfit(),0)) Print("Buy TrailingStop Failed, error # ", GetLastError()); }//25 }//24 if(OrderType()==OP_SELL && OrderSymbol()== Symbol() && OrderMagicNumber()== MagicNumber) {//26 RefreshRates(); if((OrderStopLoss() > (Ask + TrailingStop * pips2dbl) || OrderStopLoss() < Point ) && (OrderOpenPrice() - Ask) >= MinimumProfit * pips2dbl)) {//27 if(!OrderModify(OrderTicket(),OrderOpenPrice(),Ask + (TrailingStop * pips2dbl),OrderTakeProfit(),0)) Print("Sell TrailingStop Failed, error # ", GetLastError()); }//27 }//26 }//23 }//0Raptor is right! The sells part was outside of the FOR loop.
Raptor is right! The sells part was outside of the FOR loop.
Hi RaptorUK,
Thank you for your attention to my issue.
In fact I need to learn once for all to get those routines right.
Taking your advice.
cyberfx.org:
Thank you for revised code.
By the way, is there a need to include spread plus stoplevel in this routine or because the order already satisfy the distance from price having those values in mind is not a need here ?
Once these days need to pay all of you a lunch.....
best regards
Luis
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi all,
I have one issue with trailing stop.
In code that follows when I use count down sell trailing do not work, but if start to count up it work fine.
Any clarification regarding the above ?
Thank you for any light on this
Luis