- www.mql5.com
-
Hello everyone, I am struggling with trading losses and I really need a reliable Trailing Stop Expert Advisor for MetaTrader 5 to help protect my profits and minimize my risks. Could anyone provide a simple, effective Trailing Stop bot or help me optimize one? Your support would be greatly appreciated.
Hello!
One thing I know for sure: reliable means it keeps working over time. A large sample of trades with stable long-term results is probably the closest thing to real evidence.
If you happen to find something like that, please let me know 🙂
-
Hello everyone, I am struggling with trading losses and I really need a reliable Trailing Stop Expert Advisor for MetaTrader 5 to help protect my profits and minimize my risks. Could anyone provide a simple, effective Trailing Stop bot or help me optimize one? Your support would be greatly appreciated.
Forum on trading, automated trading systems and testing trading strategies
Coding Trailing Stop Loss in MQL5
zemo, 2018.06.26 16:59
look the original source and to understand how use it..
I put the peaces of code that you have use too..
original code:
https://www.mql5.com/pt/code/viewcode/19546/178536/ema_6.12.mq5
peace of code for trailing stop with step. //--- #include <Trade\PositionInfo.mqh> #include <Trade\Trade.mqh> #include <Trade\SymbolInfo.mqh> CPositionInfo m_position; // trade position object CTrade m_trade; // trading object CSymbolInfo m_symbol; // symbol info object //--- input parameters input ushort InpTrailingStop = 50; // Trailing Stop (in pips) input ushort InpTrailingStep = 5; // Trailing Step (in pips) double ExtTrailingStop=0.0; double ExtTrailingStep=0.0; -----in the OnInit---- (....) int digits_adjust=1; if(m_symbol.Digits()==3 || m_symbol.Digits()==5) digits_adjust=10; m_adjusted_point=m_symbol.Point()*digits_adjust; ExtTakeProfit=InpTakeProfit*m_adjusted_point; ExtTrailingStop=InpTrailingStop*m_adjusted_point; ExtTrailingStep=InpTrailingStep*m_adjusted_point; (....) -----in the OnTick---- (....) Trailing(); (....) ----------- //+------------------------------------------------------------------+ //| Trailing | //+------------------------------------------------------------------+ void Trailing() { if(ExtTrailingStop==0) return; for(int i=PositionsTotal()-1;i>=0;i--) // returns the number of open positions if(m_position.SelectByIndex(i)) if(m_position.Symbol()==m_symbol.Name() && m_position.Magic()==m_magic) { if(m_position.PositionType()==POSITION_TYPE_BUY) { if(m_position.PriceCurrent()-m_position.PriceOpen()>ExtTrailingStop+ExtTrailingStep) if(m_position.StopLoss()<m_position.PriceCurrent()-(ExtTrailingStop+ExtTrailingStep)) { if(!m_trade.PositionModify(m_position.Ticket(), m_symbol.NormalizePrice(m_position.PriceCurrent()-ExtTrailingStop), m_position.TakeProfit())) Print("Modify ",m_position.Ticket(), " Position -> false. Result Retcode: ",m_trade.ResultRetcode(), ", description of result: ",m_trade.ResultRetcodeDescription()); continue; } } else { if(m_position.PriceOpen()-m_position.PriceCurrent()>ExtTrailingStop+ExtTrailingStep) if((m_position.StopLoss()>(m_position.PriceCurrent()+(ExtTrailingStop+ExtTrailingStep))) || (m_position.StopLoss()==0)) { if(!m_trade.PositionModify(m_position.Ticket(), m_symbol.NormalizePrice(m_position.PriceCurrent()+ExtTrailingStop), m_position.TakeProfit())) Print("Modify ",m_position.Ticket(), " Position -> false. Result Retcode: ",m_trade.ResultRetcode(), ", description of result: ",m_trade.ResultRetcodeDescription()); } } } }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello everyone, I am struggling with trading losses and I really need a reliable Trailing Stop Expert Advisor for MetaTrader 5 to help protect my profits and minimize my risks. Could anyone provide a simple, effective Trailing Stop bot or help me optimize one? Your support would be greatly appreciated.