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

汉化版网格EA



汉化版网格EA汉化作者注释如下:
//单纯以是否有单为下单的唯一条件,无策略
//循环内容特殊 待解
//特点在于1。控制小数位来精确化价格后作为下单价格,定义小数位参数时是否应先赋值(或取货币对的市场规定值)  2。按格幅到长度循环处理
//只有开仓语句,以赢利目标自行出仓,问题:如果成交后一直未止赢,如何处理

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

//[EA1]网格特别写法(译)
//单纯以是否有单为下单的唯一条件,无策略
//循环内容特殊 待解
//特点在于1。控制小数位来精确化价格后作为下单价格,定义小数位参数时是否应先赋值(或取货币对的市场规定值)  2。按格幅到长度循环处理
//只有开仓语句,以赢利目标自行出仓,问题:如果成交后一直未止赢,如何处理
//+------------------------------------------------------------------+
//|                                                       网格EA.mq4 |
//|                                     Copyright 2014, QQ:125808047 |
//+------------------------------------------------------------------+
#property copyright "www.125808047.com"
#property link      "http://www.125808047.com/"


#include <stdlib.mqh>                                                                                                // 

extern double 网格步幅= 25;                                                                                          // 格幅
extern double 网格长度= 60;                                                                                         // 网格总长度

double 关键价,                                                                                                       // 以下定义参数变量:网格关键价,,,,,,
       倍数,                                                                                                         // 倍数
       i,                                                                                                            // 下单价格
       手数= 0.01,                                                                                                   // 手数
       市场止损线,                                                                                                   // 市场止损线
       止赢,                                                                                                         // 赢利目标
       止损;                                                                                                         // 止损
int 魔术号,                                                                                                          // 定义一些整型变量:魔术号,,,,(自定义?)小数位,
    j,                                                                                                               // 循环递增值
    买单数,                                                                                                          // 买单统计
    卖单数,                                                                                                          // 卖单统计
    小数位,                                                                                                          // 小数位              
    单编号;                                                                                                          // 发单编号              
string Text="Grid";                                                                                                  // 文本字符串(未用)

// +-------------------------初始化------------------------------+     

int init()                                                                      // (为何参数赋值内容写在初始化部分)
    {
    if (小数位==4)  小数位=2;                                                                                        // 如果小数位等于4位,则改为2位
      else  小数位=0;                                                                                                // 否则小数位为0  
                     
    魔术号 =20100513;                                                                                                // 魔术号
    网格步幅 =网格步幅*Point;                                                                                        // 网格步幅*市场点
    网格长度 =网格长度*Point;                                                                                        // 网格长度*市场点
    市场止损线 =MarketInfo(Symbol(),MODE_STOPLEVEL)*Point;                                                           // 市场规定的止损价*市场点
    return(0);                                                                                                       // 
   }

void deinit() {
  Comment("www.125808047.com");
}

// +------------------------------------------------------------------+

int start() 
   {
    倍数 =NormalizeDouble((Bid -NormalizeDouble(Bid,小数位))/网格步幅, 0);          // (Print 检查这地方出值为0 )    // ★★ 倍数:(注意正负值)
    关键价 =NormalizeDouble(Bid,小数位) +网格步幅*倍数;                               // 待再理解                      // ★★ 轴心价:叫买价+格幅乘以倍数

    //下网格布网      
    for(i=关键价;  i>=关键价-网格长度;  i=i-网格步幅)                                                                // 将i赋为轴心,如果大于轴心-格长度,做如下循环,递减值为i-格幅    
       {                                                                                                             // 
        买单数 =0;                                                                                                   // 买计数初赋为 0    
        卖单数 =0;                                                                                                   // 卖计数初赋为 0
        for(j=0; j<OrdersTotal(); j++)                                                                               // 按单总数递增循环    
           {                                                                                                         // 
            if(OrderSelect(j,SELECT_BY_POS)==false) return(0);                                                       // 按顺序选择订单失败 返回    
                                                                                                                     // 
            if(OrderMagicNumber()==魔术号 && NormalizeDouble(OrderOpenPrice(),小数位)==NormalizeDouble(i,小数位) )   // 魔术号一致 且 开仓价精确化值=i值
              {                                                                                                      //
               if(OrderType()==OP_BUY  || OrderType()==OP_BUYLIMIT ) 买单数++;                                       // 如果单类型为已成交买单或限价挂单, 则将多单数加1    
               if(OrderType()==OP_SELL || OrderType()==OP_SELLSTOP ) 卖单数++;                                       // 如果单类型为已成交买单或限价挂单, 则将空单数加1    
              }    
           }    
           
        if(买单数==0)                                                                                                // 买统计等于0时    
           {                                                                                                         // 
            止赢 =i+网格步幅;                                                                                        // 止赢为i+格幅
            止损 =0;                                                                                                 // 止损不设
            if(Ask-i>=市场止损线)                                                                                    // 叫卖价-i如果大于等于市场规定止损线    
              {                                                                                                      // 
              单编号 =OrderSend(Symbol(),
                                OP_BUYLIMIT, //限价买
                                手数,
                                i,
                                0,
                                止损,
                                止赢,
                                "网格- BuyLimit",
                                魔术号,
                                0,
                                Red);                     // 发送限价买订单    价格为i
              if (单编号>0) Alert(Symbol()," ",单编号,"网格-BuyLimit=",i," 开仓成功");                               // 如果成功,报警通知    
                else Alert( Symbol(),"网格- BuyLimit=",i," 开仓未成:",ErrorDescription(GetLastError()));             // 否则也报警通知    
              Sleep(10000);                                                                                          // 休息10秒
              }                                                                                                      // 
           if(Ask==i)                                                                                                // 如果叫卖价等于i
              {                                                                                                      // 
               单编号=OrderSend(Symbol(),
                                OP_BUY,      //直接买
                                手数,
                                i,
                                0,
                                止损,
                                止赢,
                                "网格- Buy",
                                魔术号,
                                0,
                                Magenta);                               // 发送现价买订单    
               if (单编号>0) Alert(Symbol()," ",单编号,"网格-Buy=",i," 开仓成功");                                   // 如果成功 报警
               else Alert( Symbol(),"网格- Buy=",i," 开仓未成:",ErrorDescription(GetLastError()));                   // 否则也报警
               Sleep(10000);                                                                                         // 休息10秒
             }
          }
          
       if(卖单数==0)                                                                                                 // 如果卖统计等于0
          {                                                                                                          //     
           止赢=i-网格步幅;                                                                                          // 止赢为 i-格幅
           止损=0;                                                                                                   // 止损为0
           if(Bid-i>=市场止损线)                                                                                     // 叫买价-i    >=市场规定止损线
             {                                                                                                       // 
              单编号=OrderSend(Symbol(),
                               OP_SELLSTOP,   //突破价卖
                               手数,
                               i,
                               0,
                               止损,
                               止赢,
                               "网格- SellStop",
                               魔术号,
                               0,
                               Blue);                      // 
              if (单编号>0) Alert(Symbol()," ",单编号,"网格-   SellStop=",i," 开仓成功");                            // 
              else Alert( Symbol(),"网格- SellStop=",i," 开仓未成:",ErrorDescription(GetLastError()));               // 
              Sleep(10000);                                                                                          // 
             }                                                                                                       // 
           if(Bid==i)                                                                                                // 
             {                                                                                                       // 
              单编号=OrderSend(Symbol(),
                               OP_SELL,     //直接卖
                               手数,
                               i,
                               0,
                               止损,
                               止赢,
                               "网格- Sell",
                               魔术号,
                               0,
                               Cyan);                              // 
              if (单编号>0) Alert(Symbol()," ",单编号,"网格-BuyLimit=",i," 开仓成功");                               // 
              else Alert( Symbol(),"网格- BuyLimit=",i," 开仓未成:",ErrorDescription(GetLastError()));               // 
              Sleep(10000);                                                                                          // 
             } 
          } 
      }    

   //上网格布网
   for(i=关键价+网格步幅;  i<=关键价+网格长度;  i=i+网格步幅)                                                        // 初轴心价+格幅, 如果小于轴心价+格幅长度,按轴心价再加一次格幅 运算如下部分
      {                                                                                                              // 
       买单数  =0;                                                                                                   // 将买统计赋为0
       卖单数 =0;                                                                                                    // 将卖统计赋为0
       for(j=0; j<OrdersTotal(); j++)                                                                                // 循环查找订单数
          {                                                                                                          // 选择失败则返回
           if(OrderSelect(j,SELECT_BY_POS)==false) return(0);                                                        // 如果魔术号相符 且按点精确后开仓价等于按点精确化的轴心加格幅
           if(OrderMagicNumber()==魔术号 && NormalizeDouble(OrderOpenPrice(),小数位)==NormalizeDouble(i,小数位) )    // 
             {                                                                                                       // 如果订单类型为买或突破买,则将买统计加1
              if(OrderType()==OP_BUY  || OrderType()==OP_BUYSTOP)    买单数++;                                       // 如果订单类型为卖或突破卖,则将卖统计加1
              if(OrderType()==OP_SELL || OrderType()==OP_SELLLIMIT)  卖单数++;                                       // 
             }
          }
          
       if(买单数==0)                                                                                                 // 如果买统计为0
          {                                                                                                          // 
           止赢=i+网格步幅;                                                                                          // 
           止损=0;                                                                                                   // 
           if(i-Ask>=市场止损线)                                                                                     // 如果i-叫卖价>=市场规定的止损线
             {
             单编号=OrderSend(Symbol(),                                                                              // 发送订单 
                              OP_BUYSTOP,          //突破买                                                          // 类:
                              手数,                                                                                  // 手:
                              i,                                                                                     // 价:
                              0,                                                                                     // 滑:
                              止损,                                                                                  // 损:
                              止赢,                                                                                  // 赢:
                              "网格+  BuyStop",                                                                      // 评:
                              魔术号,                                                                                // 码:
                              0,                                                                                     // 效:
                              Red);                                                                                    // 色:
              if (单编号>0) Alert(Symbol()," ",单编号,"网格+ BuyStop=",i," 开仓成功");                               // 如果发送成功,则报警通知
              else Alert( Symbol(),"网格+  BuyStop=",i," 开仓未成:",ErrorDescription(GetLastError()));               // 否则也报警说明原因
              Sleep(10000);                                                                                          // 休息10秒
             }                                                                                                       // 
             
           if(i==Ask)                                                                                                // 如果i=叫卖价
             {                                                                                                       // 
             单编号 =OrderSend(Symbol(),                                                                             // 
                               OP_BUY,              //直接买                                                         // 
                               手数,                                                                                 // 
                               i,                                                                                    // 
                               0,                                                                                    // 
                               止损,                                                                                 //                                                            // 
                               止赢,                                                                                 // 
                               "网格+  Buy",                                                                         // 
                               魔术号,                                                                               // 
                               0,                                                                                    // 
                               Magenta);                                                                                   // 
             if(单编号>0) Alert(Symbol(),"  ",单编号,"网格+Buy=",i," 开仓成功");                                     // 
             else Alert( Symbol(),"网格+  Buy=",i," 开仓未成:",ErrorDescription(GetLastError()));                    // 
             Sleep(10000);                                                                                           // 
            }
         }    
         
     if(卖单数==0)                                                                                                   // 当卖统计等于0
         {                                                                                                           // 则将止赢目标定为 
          止赢=i-网格步幅;                                                                                           // 将止损赋为0
          止损=0;                                                                                                    // 
          if(i-Bid>=市场止损线)                                                                                      // 如果下单的价格大于市场夫定的止损价
            {                                                                                                        // 
            单编号 =OrderSend(Symbol(),                                                                              // 发送限价卖订单
                              OP_SELLLIMIT,   //限价卖
                              手数,
                              i,
                              0,
                              止损,
                              止赢,
                              "网格+  SellLimit",
                              魔术号,
                              0,
                              Blue); 
            if (单编号>0) Alert(Symbol()," ",单编号,"网格+    SellLimit=",i," 开仓成功");                            // 
            else Alert( Symbol(),"网格+  SellLimit=",i," 开仓未成:",ErrorDescription(GetLastError()));               // 
            Sleep(10000);                                                                                            // 休息10秒
            }                                                                                                        // 
          if(i==Bid)                                                                                                 // 如果下单价格等于叫买价
            {                                                                                                        // 
            单编号 =OrderSend(Symbol(),                                                                              // 下现价卖出单
                              OP_SELL,     //直接卖
                              手数,
                              i,
                              0,
                              止损,
                              止赢,
                              "网格+ Sell",
                              魔术号,
                              0,
                              Cyan); 
            if(单编号>0) Alert(Symbol(),"  ",单编号,"网格+    Sell=",i," 开仓成功");                                 // 
            else Alert( Symbol(),"网格+  Sell=",i," 开仓未成:",ErrorDescription(GetLastError()));                    // 
            Sleep(10000);                                                                                            // 休息10秒
            }
         }
    }
      
//--主循环结束
   return(0);                                                                                                        // 
 }  
//--------------------------------------------------------------------+

如您喜欢此文章请点下面分享按钮↴峰汇在线 » 汉化版网格EA
上一篇:
下一篇:
分享到:更多 ()