在交易中,移动止损策略可以帮助我们更好地保护利润。而今天,我们要讨论的正是如何在MetaTrader 5中使用固定抛物线SAR(Parabolic SAR)来实现这一目标。

参数设置

- 移动模式:无 / 固定移动 / 固定抛物线SAR移动
下面是抛物线SAR的计算部分:
bool CSampleExpert::LongModifiedEx(void) { bool res=false; //--- 检查移动止损 if(m_trailing_max < m_last_bar.high) { double tp=m_position.TakeProfit(); double sl=m_position.StopLoss(); //--- 计算抛物线SAR 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()) { //--- 修改仓位 if(m_trade.PositionModify(Symbol(),sar_stop,tp)) printf("多头仓位 %s 已修改",Symbol()); else { printf("修改仓位 %s 出错:'%s'",Symbol(),m_trade.ResultComment()); printf("修改参数:SL=%f,TP=%f",sar_stop,tp); } //--- 修改后必须退出专家 res=true; } } //--- 返回结果 return(res); }