Expert Advisors • Indicators • Scripts • Libraries

MQL.RobotFX.org is the biggest collection of MetaTrader expert advisors (MT5 & MT4), indicators, scripts and libraries that can be used to improve trading results, minimize risks or simply automate trading tasks

MetaTrader 5 Expert Advisor | Trailing Stop by Fixed Parabolic SAR

Modify to allow direct specification of the starting point of the Parabolic SAR.

MetaTrader Experts, Indicators, Scripts and Libraries

Parameters

MetaTrader Experts, Indicators, Scripts and Libraries

  • Trailing Mode ・・・ None / Trailing Fixed / Trailing Fixed Parabolic SAR
calcuration part of Parabolic SAR
bool CSampleExpert::LongModifiedEx(void)    {     bool res=false;  //--- check for trailing stop     if(m_trailing_max < m_last_bar.high)       {        double tp=m_position.TakeProfit();        double sl=m_position.StopLoss();          //--- calcurate ParabolicSAR        m_trailing_max = m_last_bar.high;        m_trailing_step = fmin(InpPSAR_Maximum, m_trailing_step + InpPSAR_Step);        double sar_stop = sl + (m_trailing_max - sl)* m_trailing_step;        sar_stop=NormalizeDouble(sar_stop,m_symbol.Digits());        //---          if((sl==0.0 || sl < sar_stop) && sar_stop < m_symbol.Bid())          {           //--- modify position           if(m_trade.PositionModify(Symbol(),sar_stop,tp))              printf("Long position by %s to be modified",Symbol());           else             {              printf("Error modifying position by %s : '%s'",Symbol(),m_trade.ResultComment());              printf("Modify parameters : SL=%f,TP=%f",sar_stop,tp);             }           //--- modified and must exit from expert           res=true;          }       }  //--- result     return(res);    }   

39931