📅 财经日历 📊 实时波动 📈 大盘云图 📶 行情走势 🆚 投机情绪 🚀 今日热点

    动态移动止损、止盈代码

    香烟 LV3
    2019-09-04 · 1463 阅读
    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.             }
    40.    
    复制代码

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

    举报

     

    回答|共 3 个

    捉鱼的羊 LV5

    发表于 2019-9-4 13:34:31 | 显示全部楼层

    学习  看看

    啸星 LV1

    发表于 2019-9-4 13:36:52 | 显示全部楼层

    O(∩_∩)O哈哈~

    kouuok LV1

    发表于 2019-11-4 17:32:52 | 显示全部楼层

    学习再学习。谢谢了
    您需要登录后才可以回帖 登录 | 注册

    提醒: 禁止引战、谩骂、灌水内容

    微信二维码

    有问题联系客服