分享

动态移动止损、止盈代码

 Levy_X 2018-03-23


if(OrderType() == OP_BUY) { dSl=OrderStopLoss(); if( dSl == 0 ) if( dInitialSL != 0) dSl = dnAsk - dInitialSL; ArrayResize(arrSL,5); ArrayInitialize(arrSL,dSl); LogSL('OP_BUY-check',dSl,arrSL[0],arrSL[1],arrSL[2],arrSL[3]); if( dPropSLRatio > 0 ) { if( Bid >= (OrderOpenPrice() dPropSLThreshold) ) { dSl = NormalizeDouble( OrderOpenPrice() dPropSLRatio*(Bid - OrderOpenPrice()) - dSpread,4 ); if(OrderStopLoss() < dSl) arrSL[1]=dSl; } else { if(dTrailingStop != 0) arrSL[2]=dnBid - dTrailingStop; } } dSl=arrSL[ArrayMaximum(arrSL)]; LogSL('OP_BUY - max',dSl,arrSL[0],arrSL[1],arrSL[2],arrSL[3]); if( dSl > OrderStopLoss() || OrderStopLoss() == 0 ) { OrderModify(OrderTicket(), OrderOpenPrice(), dSl, OrderTakeProfit(), 0, Yellow); Log('Buy - modify', OrderOpenPrice(), dSl, OrderTakeProfit()); } // Escape buy //if( dEscape != 0 && dnBid < OrderOpenPrice() - dEscape - 5 * Point ) if( nUseEscape == 1 && dnBid < OrderOpenPrice() - dEscapeLevel - 5 * Point ) { OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), OrderOpenPrice() dEscapeTP, 0, Aqua); Log('Buy - EscapeLevel', OrderOpenPrice(), dSl, OrderTakeProfit()); }



上述代码中,使用dSl = NormalizeDouble( OrderOpenPrice() dPropSLRatio*(Bid - OrderOpenPrice()) - dSpread,4 );进行动态调整,dPropSLRatio可以考虑设置为0.382这个黄金比例。 另外当现价低于一定程度时,设置一个较小的止盈目标位,及时逃脱。


    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多