Armin Abolfathi:
can any one help why this code does not work for trailing stop for buy position?in compiler has no error but while back test the EA tester stop working.
i want when the price increase 50point from open price then stoploss move 50point upward.
double StopLossBuy = Bid-100*Point double buy= OrderSend(Symbol(),OP_BUY,lot,Ask,5,StopLossBuy,0,0,0,0,Green); double TrailPoint=50; OrderSelect(OrdersTotal()-1,SELECT_BY_POS,MODE_TRADES); while(OrderTicket()){ if(MarketInfo(OrderSymbol(),MODE_ASK)>OrderOpenPrice()+TrailPoint*Point && OrderType()==OP_BUY) { StopLossBuy = NormalizeDouble(StopLossBuy + 50*Point,MarketInfo(OrderSymbol(),MODE_DIGITS)); if(OrderStopLoss()!=StopLossBuy || OrderStopLoss()==0) { OrderModify(OrderTicket(),OrderOpenPrice(),StopLossBuy,0,0,Green); TrailPoint = TrailPoint + 50; } } }
your original code is wrong.
At the end of "double StopLossBuy = Bid-100*Point"; none. Also, While is in an infinite loop. These were fixed and tested. In this state, he opens an endless order. You need to add a control.
double StopLossBuy = Bid-100*Point; double buy= OrderSend(Symbol(),OP_BUY,lot,Ask,5,StopLossBuy,0,0,0,0,Green); double TrailPoint=50; if(OrderSelect(OrdersTotal()-1,SELECT_BY_POS,MODE_TRADES)) { if(MarketInfo(Symbol(),MODE_ASK)>OrderOpenPrice()+TrailPoint*Point) { StopLossBuy = NormalizeDouble(StopLossBuy + 50*Point,int(MarketInfo(OrderSymbol(),MODE_DIGITS))); bool ticketmdf=OrderModify(OrderTicket(),OrderOpenPrice(),StopLossBuy,0,0,Green); TrailPoint = TrailPoint + 50; } }
//+------------------------------------------------------------------+ //| BB %b & LSMA.mq4 | //| Copyright 2021, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2021, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict extern double lot = 0.1; extern int timeFrame = 15; extern double TrailPoint = 50; double pt = Point; //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { if(Digits==3 || Digits==5){ pt=10*pt; } double superTrendUp = iCustom(Symbol(),timeFrame,"SuperTrend",9,3.9,0,1); double superTrendDown = iCustom(Symbol(),timeFrame,"SuperTrend",9,3.9,1,1); double EMA = iCustom(Symbol(),timeFrame,"ema",55,0,0,5,0,0); double QQEMODE = iCustom(Symbol(),timeFrame,"qqe-histogram",0,5,6,4.236,60.0,40.0,1,1,1,1,1,1,3,1); double minstoplevel=MarketInfo(Symbol(),MODE_STOPLEVEL); int totalOrder = OrdersTotal(); bool positionOfLastOrder=OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY); if(MarketInfo(Symbol(), MODE_BID)>superTrendUp && MarketInfo(Symbol(), MODE_BID)>EMA && QQEMODE>10 && MarketInfo(Symbol(),MODE_SPREAD)<=45 && totalOrder==0 && OrderType()==OP_SELL){ RefreshRates(); double StopLossBuy = EMA-100*Point,Digits; double buy= OrderSend(Symbol(),OP_BUY,lot,Ask,5,StopLossBuy,0,NULL,0,0,Green); if(OrderSelect(OrdersTotal()-1,SELECT_BY_POS,MODE_TRADES)){ if(MarketInfo(Symbol(),MODE_ASK)>OrderOpenPrice()+TrailPoint*Point){ StopLossBuy = NormalizeDouble(StopLossBuy + 50*Point,int(MarketInfo(OrderSymbol(),MODE_DIGITS))); bool TrailModify=OrderModify(OrderTicket(),OrderOpenPrice(),StopLossBuy,0,0,Green); TrailPoint = TrailPoint + 50; Print(TrailPoint); } } } else if(MarketInfo(Symbol(), MODE_BID)<superTrendDown && MarketInfo(Symbol(), MODE_BID)<EMA && QQEMODE<(-10) && MarketInfo(Symbol(),MODE_SPREAD)<=45 && totalOrder==0 && OrderType()==OP_BUY){ double sell= OrderSend(Symbol(),OP_SELL,lot,Bid,5,EMA+100*Point,Bid-200*Point,NULL,0,0,Red); } } //+------------------------------------------------------------------+
This code does not go into below loop
if(MarketInfo(Symbol(),MODE_ASK)>OrderOpenPrice()+TrailPoint*Point){ ... }
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
can any one help why this code does not work for trailing stop for buy position?in compiler has no error but while back test the EA tester stop working.
i want when the price increase 50point from open price then stoploss move 50point upward.