有您的持续关注
我们会做得更好

MT4持仓保姆EA



顾名思义,该EA是针对MT4持仓开发的,可以给订单添加止损盈利及中途移动止损和部分平仓。来自网络的程序,用法请用模拟盘熟悉参数设置。

本网收集整理智能交易EA仅为MQL4编程爱好者提供语法及相关编程技巧的学习研究之用,智能交易存在极高的风险测试请用模拟盘,请勿用于实盘。MT4持仓保姆EA源码如下:

//+------------------------------------------------------------------+
//|                                                  MT4持仓保姆.mq4 |
//|                                     Copyright 2014, QQ:125808047 |
//+------------------------------------------------------------------+
#property copyright "www.125808047.com"
#property link      "http://www.125808047.com/"

extern string 自动止损参数 = "默认打开";
extern bool AutoStoploss = TRUE;
extern double stoploss = 27.0;
extern string 自动止盈参数 = "默认打开";
extern bool AutoTakeProfit = TRUE;
extern double takeprofit = 12.0;
extern string 盈利后移动止损 = "默认打开";
extern bool AutoTrailingStop = TRUE;
extern double TrailingStop = 5.0;
extern string 分次离场参数 = "按比例分步撤退";
extern bool Gradually = FALSE;
extern int GraduallyNum = 2;
extern double drift = 1.0;
double g_order_lots_160;

int start() {
   double order_stoploss_4;
   double order_takeprofit_12;
   double order_open_price_20;
   for (int pos_0 = 0; pos_0 < OrdersTotal(); pos_0++) {
      if (OrderSelect(pos_0, SELECT_BY_POS, MODE_TRADES)) {
         if (OrderSymbol() == Symbol()) {
            order_stoploss_4 = OrderStopLoss();
            order_takeprofit_12 = OrderTakeProfit();
            order_open_price_20 = OrderOpenPrice();
            if (g_order_lots_160 == 0.0) g_order_lots_160 = OrderLots();
            if (OrderType() == OP_BUY) {
               if (Gradually) CraduallyBuy();
               if (AutoStoploss && AutoTakeProfit && order_stoploss_4 == 0.0 && order_takeprofit_12 == 0.0) bool cg = OrderModify(OrderTicket(), OrderOpenPrice(), Ask - Point * stoploss, Ask + Point * takeprofit, 0, Green);
               else {
                  if (AutoStoploss && order_stoploss_4 == 0.0) cg = OrderModify(OrderTicket(), OrderOpenPrice(), Ask - Point * stoploss, OrderTakeProfit(), 0, Green);
                  if (AutoTakeProfit && order_takeprofit_12 == 0.0) cg = OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), Ask + Point * takeprofit, 0, Green);
               }
               if (AutoTrailingStop && Bid - order_open_price_20 > Point * TrailingStop)
                  if (Bid - order_stoploss_4 > TrailingStop * Point) cg = OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, Green);
            }
            if (OrderType() != OP_SELL) continue;
            if (Gradually) CraduallySell();
            if (AutoStoploss && AutoTakeProfit && order_stoploss_4 == 0.0 && order_takeprofit_12 == 0.0) cg = OrderModify(OrderTicket(), OrderOpenPrice(), Bid + Point * stoploss, Bid - Point * takeprofit, 0, Green);
            else {
               if (AutoStoploss && order_stoploss_4 == 0.0) cg = OrderModify(OrderTicket(), OrderOpenPrice(), Bid + Point * stoploss, OrderTakeProfit(), 0, Green);
               if (AutoTakeProfit && order_takeprofit_12 == 0.0) cg = OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), Bid - Point * takeprofit, 0, Green);
            }
            if (!(AutoTrailingStop && order_open_price_20 - Ask > Point * TrailingStop)) continue;
            if (order_stoploss_4 - Ask <= TrailingStop * Point) continue;
            cg = OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * TrailingStop, OrderTakeProfit(), 0, Green);
            continue;
         }
         g_order_lots_160 = 0;
      }
   }
   return (0);
}

void CraduallyBuy() {
   double order_open_price_0 = OrderOpenPrice();
   double order_lots_8 = OrderLots();
   for (int li_16 = 1; li_16 <= GraduallyNum; li_16++) {
      if (NormalizeDouble((Bid - order_open_price_0) / Point, 0) == NormalizeDouble(takeprofit / GraduallyNum * li_16, 0))
         if (order_lots_8 == NormalizeDouble(g_order_lots_160 * (1 / GraduallyNum + 1 - li_16 / GraduallyNum), 2)) bool cg = OrderClose(OrderTicket(), NormalizeDouble(g_order_lots_160 / GraduallyNum, 2), Bid, 3, CLR_NONE);
      if (NormalizeDouble((Bid - order_open_price_0) / Point, 0) == NormalizeDouble(takeprofit * ((GraduallyNum - 1) / GraduallyNum), 0)) cg = OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), Ask + Point * takeprofit * drift, 0, Green);
   }
}

void CraduallySell() {
   double order_open_price_0 = OrderOpenPrice();
   double order_lots_8 = OrderLots();
   for (int li_16 = 1; li_16 <= GraduallyNum; li_16++) {
      if (NormalizeDouble((order_open_price_0 - Ask) / Point, 0) == NormalizeDouble(takeprofit / GraduallyNum * li_16, 0))
         if (order_lots_8 == NormalizeDouble(g_order_lots_160 * (1 / GraduallyNum + 1 - li_16 / GraduallyNum), 2)) bool cg = OrderClose(OrderTicket(), NormalizeDouble(g_order_lots_160 / GraduallyNum, 2), Ask, 3, CLR_NONE);
      if (NormalizeDouble((order_open_price_0 - Ask) / Point, 0) == NormalizeDouble(takeprofit * ((GraduallyNum - 1) / GraduallyNum), 0)) cg = OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), Bid - Point * takeprofit * drift, 0, Green);
   }
}

如您喜欢此文章请点下面分享按钮↴峰汇在线 » MT4持仓保姆EA
上一篇:
下一篇:
分享到:更多 ()