Greetings! I have a problem with my trailing stop settings.
The trailing stop is taken from 0. I want it to be taken when I already have 5 pips earned. Could you help me with that?
That is, call the function when the price is above the 5 pips already earned.
It's like it kicks in after 5 pips won. That if it goes down, always come out with 5 pips earned.
I leave my code:
Always use 'Code Styler ( )' - and your code will look like this:
int posTotal=PositionsTotal(); for(int posIndex=posTotal-1; posIndex>=0; posIndex--) { ulong ticket=PositionGetTicket(posIndex); if(PositionSelectByTicket(ticket) && PositionGetInteger(POSITION_MAGIC)==MagicNumber) { if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY) { if(TrailingStop>0) { if(SymbolInfoDouble(_Symbol,SYMBOL_BID)-PositionGetDouble(POSITION_PRICE_OPEN)>MyPoint*TrailingStop) { if(PositionGetDouble(POSITION_SL)<SymbolInfoDouble(_Symbol,SYMBOL_BID)-MyPoint*TrailingStop) { trade.PositionModify(ticket,SymbolInfoDouble(_Symbol,SYMBOL_BID)-MyPoint*TrailingStop,PositionGetDouble(POSITION_TP)); return; } } } } if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL) { if(TrailingStop>0) { if(PositionGetDouble(POSITION_PRICE_OPEN)-SymbolInfoDouble(_Symbol,SYMBOL_ASK)>MyPoint*TrailingStop) { if(PositionGetDouble(POSITION_SL)>SymbolInfoDouble(_Symbol,SYMBOL_ASK)+MyPoint*TrailingStop) { trade.PositionModify(ticket,SymbolInfoDouble(_Symbol,SYMBOL_ASK)+MyPoint*TrailingStop,PositionGetDouble(POSITION_TP)); return; } } } } } }
Mistake #1: Use ' SymbolInfoDouble ' instead of
- www.mql5.com
Greetings! I have a problem with my trailing stop settings.
The trailing stop is taken from 0. I want it to be taken when I already have 5 pips earned. Could you help me with that?
That is, call the function when the price is above the 5 pips already earned.
It's like it kicks in after 5 pips won. That if it goes down, always come out with 5 pips earned.
I leave my code:
input double TStop = 5.0; input double TStart = 5.0; for(int i=0;i<PositionsTotal();i++){ ulong iTicket=PositionGetTicket(i); if(PositionGetString(POSITION_SYMBOL)==_Symbol &&PositionGetInteger(POSITION_MAGIC)==MagicNumber){ double PosSL=PositionGetDouble(POSITION_SL); double PosTP=PositionGetDouble(POSITION_TP); double PosOpen=PositionGetDouble(POSITION_PRICE_OPEN); if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY){ double TS=NormalizeDouble(Bid-(TStop*10)*_Point,_Digits); if(TS>NormalizeDouble(PosOpen+(TStart*10)*_Point,_Digits){ if(TS>PosSL&&!trade.PositionModify(iTicket,TStop,PosTP)){ Print("PositionModify error ",trade.ResultRetcode()); return; } else{i--;} } if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL){ double TS=NormalizeDouble(Ask+(TStop*10)*_Point,_Digits); if(TS<NormalizeDouble(PosOpen-(TStart*10)*_Point,_Digits){ if((TS>PosSL||PosSL==0)&&!trade.PositionModify(iTicket,TStop,PosTP)){ Print("PositionModify error ",trade.ResultRetcode()); return; } else{i--;} } } } }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Greetings! I have a problem with my trailing stop settings.
The trailing stop is taken from 0. I want it to be taken when I already have 5 pips earned. Could you help me with that?
That is, call the function when the price is above the 5 pips already earned.
It's like it kicks in after 5 pips won. That if it goes down, always come out with 5 pips earned.
I leave my code: