You need to check the trailing stops on each tick (not just only after buy/sell):
MqlTick tick; SymbolInfoTick(_Symbol,tick); if(signal==SIGNAL_UP && trend==TREND_UP) trade.Buy (LOTS,_Symbol,tick.ask,tick.ask-30*_Point,0,NULL); if(signal==SIGNAL_DOWN && trend==TREND_DOWN) trade.Sell(LOTS,_Symbol,tick.bid,tick.bid+30*_Point,0,NULL); if(trade.SelectPosition(_Symbol)) { long postype=PositionGetInteger(POSITION_TYPE); if(postype==POSITION_TYPE_BUY) CheckTrailingStopBUY (tick.ask); if(postype==POSITION_TYPE_SELL) CheckTrailingStopSELL(tick.bid); }
lippmaje:
Thank you very much !
You need to check the trailing stops on each tick (not just only after buy/sell):
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
Hello,
I recently coded a trailing stop to complete my simple strategy.
When I compile my code, it shows no error. However, when I run the code to test it, the stop loss does not follow my position but remains fixed.
Can you tell me what does not work in my code? Thanks a lot for your help. LGK