评论

收藏

动态移动止损、止盈代码

avatar 易源 | 1056 人阅读 | 0 人评论 | 2018-07-08

  1. if(OrderType() == OP_BUY)
  2. {
  3.             dSl=OrderStopLoss();
  4.             if( dSl == 0 )
  5.                if( dInitialSL != 0)
  6.                   dSl = dnAsk - dInitialSL;           
  7.             ArrayResize(arrSL,5);
  8.             ArrayInitialize(arrSL,dSl);
  9.             LogSL("OP_BUY-check",dSl,arrSL[0],arrSL[1],arrSL[2],arrSL[3]);
  10.             if( dPropSLRatio > 0 )
  11.             {
  12.                if( Bid >= (OrderOpenPrice() + dPropSLThreshold) )
  13.                {
  14.                   dSl = NormalizeDouble( OrderOpenPrice() + dPropSLRatio*(Bid - OrderOpenPrice()) - dSpread,4 );
  15.                   if(OrderStopLoss() < dSl)
  16.                   arrSL[1]=dSl;
  17.                }
  18.                else
  19.                {
  20.                   if(dTrailingStop != 0)
  21.                      arrSL[2]=dnBid - dTrailingStop;
  22.                }
  23.             }                        
  24.             dSl=arrSL[ArrayMaximum(arrSL)];
  25.             LogSL("OP_BUY - max",dSl,arrSL[0],arrSL[1],arrSL[2],arrSL[3]);
  26.             if( dSl > OrderStopLoss() || OrderStopLoss() == 0 )
  27.                {
  28.                   OrderModify(OrderTicket(), OrderOpenPrice(),
  29.                      dSl, OrderTakeProfit(), 0, Yellow);
  30.                   Log("Buy - modify", OrderOpenPrice(), dSl, OrderTakeProfit());
  31.                }
  32.             // Escape buy
  33.             //if( dEscape != 0 && dnBid < OrderOpenPrice() - dEscape - 5 * Point )
  34.             if( nUseEscape == 1 && dnBid < OrderOpenPrice() - dEscapeLevel - 5 * Point )
  35.             {
  36.                OrderModify(OrderTicket(), OrderOpenPrice(),
  37.                OrderStopLoss(), OrderOpenPrice() + dEscapeTP, 0, Aqua);
  38.                Log("Buy - EscapeLevel", OrderOpenPrice(), dSl, OrderTakeProfit());
  39.             }
复制代码

上述代码中,使用dSl = NormalizeDouble( OrderOpenPrice() + dPropSLRatio*(Bid - OrderOpenPrice()) - dSpread,4 );进行动态调整,dPropSLRatio可以考虑设置为0.382这个黄金比例。 另外当现价低于一定程度时,设置一个较小的止盈目标位,及时逃脱。
""
还没有人打赏,支持一下
您需要登录后才可以回帖 登录 | 注册 微信登录

EA之家评论守则