Russfox:
As part of my trading system I have a buy stop and sell stop pending order concurrently. I have a stop loss trail code for when either trade is activated.
In the event that the price fluctuates and activates both trades then the stop loss trailing code works.
However if only one of the pending orders is activated then my stop loss trailing code starts to trail the opposite pending order stop loss but leaves the active trades stop loss in place.
I have attached the code.
Can any one help to see what I've done wrong and how to fix it?
The orderlots function just ensures that the order has the correct lot amount relative to other trades.
void RegularTrail1(){ double Multiplier=(100.0-BreakenTrailAmount)/BreakenTrailAmount; for(int i=OrdersTotal()-1;i>=0;i--){ if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){ if(OrderMagicNumber()==magic){ if(OrderType()==OP_BUY) {if(OrderLots()>=((TotalOpenBuyLots()*Multiplier))/(2*Multiplier)){ if(Bid-OrderOpenPrice() > (WhenToTrail1*pips)*Point) if(OrderStopLoss() < Bid-(TrailAmount1*pips)*Point) if(!OrderModify(OrderTicket(),OrderOpenPrice(),Bid-(TrailAmount1*pips*Point),0,0,CLR_NONE)){ int err = GetLastError(); Print("Encountered an error during modification!"+(string)err+" "+ErrorDescription(err) ); }//ordermodify }}//buy order else if (OrderType()==OP_SELL){ {if(OrderLots()>=((TotalOpenSellLots()*Multiplier)/(2*Multiplier))){ if(OrderOpenPrice()-Ask > (WhenToTrail1*pips)*Point) if(OrderStopLoss() > Ask+(TrailAmount1*pips)*Point || OrderStopLoss()==0) if(!OrderModify(OrderTicket(),OrderOpenPrice(),Ask+(TrailAmount1*pips)*Point,0,0,CLR_NONE)){ int err = GetLastError(); Print("Encountered an error during modification!"+(string)err+" "+ErrorDescription(err) ); }//ordermodiy }}//sell order }//select an order else{//in case it fails to select an order. int err = GetLastError(); Print("Encountered an error during order selection in: "+ __FUNCTION__+"!"+(string)err+" "+ErrorDescription(err) ); }} }//for loop } }
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
As part of my trading system I have a buy stop and sell stop pending order concurrently. I have a stop loss trail code for when either trade is activated.
In the event that the price fluctuates and activates both trades then the stop loss trailing code works.
However if only one of the pending orders is activated then my stop loss trailing code starts to trail the opposite pending order stop loss but leaves the active trades stop loss in place.
I have attached the code.
Can any one help to see what I've done wrong and how to fix it?
The orderlots function just ensures that the order has the correct lot amount relative to other trades.