网格制作者1.1

 
这是1.1版的 "网格制造者"......一个脚本或专家顾问,设置并维持一系列均匀间隔的买入或卖出订单
这个版本既可以是脚本,也可以是专家顾问,你可以改变更新频率,选择多头和/或空头,等等,请看参数解释。

我想我已经测试了大多数的变体,但不能保证它在所有情况下都能工作!如果你尝试后发现问题,请联系我们。如果你尝试后发现问题,请告诉我。

这可能是我发布的最后一个版本。我开发它是为了测试MT4。未来的版本将更加复杂,需要外部数据,如支撑位和阻力位,所以不适合发布。



//+------------------------------------------------------------------+
//|                                                     MakeGrid.mq4 |
//|                                            Copyright © 2005, hdb |
//|                                       http://www.dubois1.net/hdb |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, hdb"
#property link      "http://www.dubois1.net/hdb"
//#property version      "1.1beta"

extern string GridName = "Grid";       // identifies the grid. allows for several co-existing grids
extern double Lots = 0.1;              // 
extern double GridSize = 6;            // pips between orders - grid or mesh size
extern double GridSteps = 10;          // total number of orders to place
extern double UpdateInterval = 15;     // update orders every x minutes
extern bool   wantLongs = true;        //  do we want long positions
extern bool   wantShorts = true;       //  do we want short positions
extern bool   wantBreakout = true;     // do we want longs above price, shorts below price
extern bool   wantCounter = true;      // do we want longs below price, shorts above price
extern bool   limitEMA34 = false;      // do we want longs above ema only, shorts below ema only
extern double LastUpdate = 0;          // counter used to note time of last update
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//---- 
 #property show_inputs              // shows the parameters - thanks Slawa...    
//----
   return(0);
  }
//+------------------------------------------------------------------------+
//| test if there is an open position or order in the region of atRate     |
//|     will check for longs if checkLongs is true, else will check        |
//|     for shorts                                                         |
//+------------------------------------------------------------------------+

bool IsPosition(double atRate, double inRange, bool checkLongs )
  {
  
     int totalorders = OrdersTotal();
     for(int j=0;j<totalorders;j++)                                // scan all orders and positions...
      {
        OrderSelect(j, SELECT_BY_POS);
        if ( OrderSymbol()==Symbol() && OrderComment() == GridName )  // only look if mygrid and symbol...
         {  int type = OrderType();
            if (MathAbs( OrderOpenPrice() - atRate) < inRange) // dont look for exact price but price proximity (less than gridsize)
              { if ( ( checkLongs && ( type == OP_BUY || type == OP_BUYLIMIT  || type == OP_BUYSTOP ) )  || (!checkLongs && ( type == OP_SELL || type == OP_SELLLIMIT  || type == OP_SELLSTOP ) ) )
                 { return(true); }
              }
         }
      } 

   return(false);
  }
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//---- 
   int    i, j,k, ticket, entermode, totalorders;
   bool   doit;
   double point, startrate, traderate;
 
//----
  if (MathAbs(CurTime()-LastUpdate)> UpdateInterval*60)           // we update the first time it is called and every UpdateInterval minutes
   {
   LastUpdate = CurTime();
   Print("Updating");
   point = MarketInfo(Symbol(),MODE_POINT);
   startrate = ( Ask + point*GridSize/2 ) / point / GridSize;    // round to a number of ticks divisible by GridSize
   k = startrate ;
   k = k * GridSize ;
   startrate = k * point - GridSize*GridSteps/2*point ;          // calculate the lowest entry point
   
   double EMA34=iMA(NULL,0,34,0,MODE_EMA,PRICE_CLOSE,0);
   
   for( i=0;i<GridSteps;i++)
   {
     traderate = startrate + i*point*GridSize;
     if ( wantLongs && (!limitEMA34 || traderate > EMA34))
       {
         if (!IsPosition(traderate,point*GridSize,true) )           // test if i have no open orders close to my price: if so, put one on
          {
             if ( traderate > Ask ) 
              { entermode = OP_BUYSTOP; } 
              else 
              { entermode = OP_BUYLIMIT ; } 
             if ( (traderate > Ask ) && (wantBreakout) || ((traderate < Ask ) && (wantCounter)) ) 
              { ticket=OrderSend(Symbol(),entermode,Lots,traderate,0,0,traderate+point*GridSize,GridName,16384,0,Green); }
          }
       }

     if ( wantShorts && (!limitEMA34 || traderate < EMA34))
       {
         if (!IsPosition(traderate,point*GridSize,false) )           // test if i have no open orders close to my price: if so, put one on
          {
             if ( traderate > Bid ) 
              { entermode = OP_SELLLIMIT; } 
              else 
              { entermode = OP_SELLSTOP ; } 
              
              if ( (traderate < Bid ) && (wantBreakout) || ((traderate > Bid ) && (wantCounter)) ) 
                { ticket=OrderSend(Symbol(),entermode,Lots,traderate,0,0,traderate-point*GridSize,GridName,16384,0,Red); }
          }
       }

    }
   }
   return(0);
  }
//+------------------------------------------------------------------+
 
你好,hdb。

我在MoneyTec(Simspeed)、ET(ElectricSavant)和Oanda论坛(MarkVH和Sympatico)上长期关注这个想法,我一直在考虑如何开发一些专家来改进你发给论坛的第一个脚本,也许我们可以一起工作,更快地达到目的:)如果你有兴趣,请告诉我,我的电子邮件是artefactodigital@gmail.com。

最好的问候。
费尔南多.

这里是1.1版本的 "网格制造者"......一个脚本或专家顾问,设置并维持一系列均匀间隔的买入或卖出订单。<br / translate="no">这个版本是一个脚本或专家顾问,你可以改变更新频率,选择多头和/或空头,等等,见参数解释。

我想我已经测试了大多数变体,但不能保证它在所有情况下都能工作!如果你尝试后发现问题,请联系我们。如果你尝试后发现问题,请告诉我。

这可能是我发布的最后一个版本。我开发它是为了测试MT4。未来的版本将更加复杂,需要外部数据,如支撑位和阻力位,所以不适合发布。
 
好的,听起来不错...请看我的电子邮件...
 
顺便说一下,你可以自由地尝试它,使用它,改变它,但请不要卖掉它!我不保证它的有效工作状态,你用它做的任何交易都要承担风险。

我不保证它的有效工作状态,你用它做的任何交易都是你自己的风险。
我对由于这个脚本造成的直接或间接损失不承担任何责任。


如果你使用它,请偶尔发表反馈意见--结果、设置、错误、观察等等。

享受
 
好了,开始了......一次大的市场变动后,电网幸存下来了!!!。两周前我用5万块钱开了一个模拟账户
我在测试gridmaker时损失了1千美元,然后就在欧元暴跌之前,我把默认的GridMaker专家放在9个货币对上。
欧元/瑞士法郎、美元/日圆、英镑/日圆、欧元/英镑、美元/瑞士法郎、澳元/美元、英镑/美元、欧元/美元、欧元/日圆。

所有货币的网格间距为6点,TP为6点。我放置了0.1手的大小。我每隔6个点对每个货币对做多和做空。
每15分钟刷新一次(即网格每15分钟更新一次),除了欧元/美元和英镑/美元是5分钟。

余额增加了1万(20%),使用的保证金是1万3千(26%),自由保证金是2万6千(52%),未实现的损益是-1万9千。

欧元爆炸的净结果(到目前为止)是,我下降了-9千。我本来以为会比这更糟

网格正在以每天600至2000的速度增加余额!我期待着看到这一点。

我期待着看到下周的情况。

网格万岁!!"。
 
好吧,好吧,一个星期后,网格真的受到了打击!我的错,因为我没有做必要的地段大小/网格间距计算。我的错,因为我没有做必要的地段大小/网格间距的计算
以了解一个人可以用可用的资产承受多大的打击。

不管怎么说,余额增长得很好:每天增长700到1800 - 现在余额是65000(开始时是49000,所以现在是+16000)。
已用保证金现在是1.5万,可用保证金是2.1万--仍然有很多空间可以在需要时增加头寸。
未实现的损益为-2.9万,净亏损1.3万,比上周差4万。

积极的一面是,我改变了设置以避免反交易(CounterTrade标志为假),未实现的P&L似乎已经稳定下来。
它曾一度达到-36000。

我喜欢这个预先测试的原因是,它从一个大的打击开始--上周的欧元下跌--所以现在看看系统如何以及何时恢复将是很有趣的。
系统的恢复情况。我毫不怀疑它将会。

我只是迫不及待地想看到下周的结果!!。

ps.我有一个V1.2版本,可以改变TP和添加SL。如果你想要的话,请在这里发布。
 
我一直在玩这个东西,只是在所有的对子上以默认方式运行一切。
我不得不说,我对它的表现印象非常深刻。

只有一个很大的问题。

,只做空头。当价格下跌时,空头订单被激活。但很多时候,在价格决定逆转之前,你可能会在空头方面得到两个订单。

即止盈 与下一个空头启动的价格相同,并没有考虑到价差,即买入和卖出价格。

,所以为了帮助防止在价格逆转到多头之前有两个订单打开,TP需要在下一个空头订单被放置时同时发生。

我想,如果这是有可能的,我目前的缩减量可以减少一半。

我猜想你的最新版本会解决这个问题。

所以,如果你能把它贴出来,那就太好了......
 
嗨。

我很高兴你觉得这很有趣......我也是。

我不可能同时拥有TP=网格大小并消除在反转时有两个未结头寸的可能性。
这不是软件问题,只是与点差有关。

理论上完全消除这种情况的唯一可能性是每次都失去点差。
例如,你在1.2006(买入)时做空,TP在1.2000(卖出)时做空,如果你有4个点差,在1.1996(买入)时做空。
你只是失去了4/10的范围。

在新的版本中,你可以将网格大小和TP设置为不同的数字,所以你可以实现你的目标
在新版本中,你可以将网格大小和TP设置为不同的数字,所以你可以实现你所寻找的:如果你有一个4点的点差,你将网格设置为10,TP为6。

我不确定这是否会减少一半的dd--但它肯定会大大减少你的利润。

让我知道。

ps. v1.2在下一篇文章中
 
这里是gridmaker的V1.2版本。

,唯一的区别是。
1)如果你需要,我增加了一个可选的止损。0表示没有止损,任何正数都表示有止损。
,如果你在网格中使用止损,你应该让它变大。
2)你可以指定一个与网格大小不同的止损点。Darkstonexa,在之前的帖子中,希望消除双 "挂 "仓。
我最初的意图是尝试相对于网格大小更大的TP。

,把它保存到专家顾问文件夹(类似于C:\Program Files\MetaTrader 4\experts\),如果你想把它作为一个脚本(C:\Program Files\MetaTrader 4\experts\scripts\),可选择复制到脚本文件夹


如果你想的话,我有一个脚本可以删除开放的网格订单,如果你想改变设置的话,它是非常有用的。

注意:自上一版本以来,默认设置可能发生了变化,请确保在重新编译之前将您喜欢的设置放进去。

向管理员提问:也许我应该把这种东西放在专家顾问库中,这样做对吗?

//+------------------------------------------------------------------+
//|                                                     MakeGrid.mq4 |
//|                                            Copyright © 2005, hdb |
//|                                       http://www.dubois1.net/hdb |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, hdb"
#property link      "http://www.dubois1.net/hdb"
//#property version      "1.2beta"

extern string GridName = "Grid";       // identifies the grid. allows for several co-existing grids
extern double Lots = 0.1;              // 
extern double GridSize = 6;            // pips between orders - grid or mesh size
extern double GridSteps = 10;          // total number of orders to place
extern double TakeProfit = 6 ;         // number of ticks to take profit. normally is = grid size but u can override
extern double StopLoss = 0;            // if u want to add a stop loss. normal grids dont use stop losses
extern double UpdateInterval = 15;     // update orders every x minutes
extern bool   wantLongs = true;        //  do we want long positions
extern bool   wantShorts = true;       //  do we want short positions
extern bool   wantBreakout = true;     // do we want longs above price, shorts below price
extern bool   wantCounter = false;      // do we want longs below price, shorts above price
extern bool   limitEMA34 = false;      // do we want longs above ema only, shorts below ema only
extern double LastUpdate = 0;          // counter used to note time of last update
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//---- 
 #property show_inputs                  // shows the parameters - thanks Slawa...    
 if ( TakeProfit <= 0 )                 // 
   { TakeProfit = GridSize; }
//----
   return(0);
  }
//+------------------------------------------------------------------------+
//| tests if there is an open position or order in the region of atRate    |
//|     will check for longs if checkLongs is true, else will check        |
//|     for shorts                                                         |
//+------------------------------------------------------------------------+

bool IsPosition(double atRate, double inRange, bool checkLongs )
  {
  
     int totalorders = OrdersTotal();
     for(int j=0;j<totalorders;j++)                                // scan all orders and positions...
      {
        OrderSelect(j, SELECT_BY_POS);
        if ( OrderSymbol()==Symbol() && OrderComment() == GridName )  // only look if mygrid and symbol...
         {  int type = OrderType();
            if (MathAbs( OrderOpenPrice() - atRate) < inRange) // dont look for exact price but price proximity (less than gridsize)
              { if ( ( checkLongs && ( type == OP_BUY || type == OP_BUYLIMIT  || type == OP_BUYSTOP ) )  || (!checkLongs && ( type == OP_SELL || type == OP_SELLLIMIT  || type == OP_SELLSTOP ) ) )
                 { return(true); }
              }
         }
      } 

   return(false);
  }
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//---- 
   int    i, j,k, ticket, entermode, totalorders;
   bool   doit;
   double point, startrate, traderate;
 
//----
  if (MathAbs(CurTime()-LastUpdate)> UpdateInterval*60)           // we update the first time it is called and every UpdateInterval minutes
   {
   LastUpdate = CurTime();
   Print("Updating");
   point = MarketInfo(Symbol(),MODE_POINT);
   startrate = ( Ask + point*GridSize/2 ) / point / GridSize;    // round to a number of ticks divisible by GridSize
   k = startrate ;
   k = k * GridSize ;
   startrate = k * point - GridSize*GridSteps/2*point ;          // calculate the lowest entry point
   
   double EMA34=iMA(NULL,0,34,0,MODE_EMA,PRICE_CLOSE,0);
   
   for( i=0;i<GridSteps;i++)
   {
     traderate = startrate + i*point*GridSize;
     if ( wantLongs && (!limitEMA34 || traderate > EMA34))
       {
         if (!IsPosition(traderate,point*GridSize,true) )           // test if i have no open orders close to my price: if so, put one on
          {
             double myStopLoss = 0;
             if ( StopLoss > 0 )
               { myStopLoss = traderate-point*StopLoss ; }
               
             if ( traderate > Ask ) 
              { entermode = OP_BUYSTOP; } 
              else 
              { entermode = OP_BUYLIMIT ; } 
             if ( (traderate > Ask ) && (wantBreakout) || ((traderate < Ask ) && (wantCounter)) ) 
              { ticket=OrderSend(Symbol(),entermode,Lots,traderate,0,myStopLoss,traderate+point*TakeProfit,GridName,16384,0,Green); }
          }
       }

     if ( wantShorts && (!limitEMA34 || traderate < EMA34))
       {
         if (!IsPosition(traderate,point*GridSize,false) )           // test if i have no open orders close to my price: if so, put one on
          {
             myStopLoss = 0;
             if ( StopLoss > 0 )
               { myStopLoss = traderate+point*StopLoss ; }
             if ( traderate > Bid ) 
              { entermode = OP_SELLLIMIT; } 
              else 
              { entermode = OP_SELLSTOP ; } 
              
              if ( (traderate < Bid ) && (wantBreakout) || ((traderate > Bid ) && (wantCounter)) ) 
                { ticket=OrderSend(Symbol(),entermode,Lots,traderate,0,myStopLoss,traderate-point*TakeProfit,GridName,16384,0,Red); }
          }
       }

    }
   }
   return(0);
  }
//+------------------------------------------------------------------+
 
这很好。

只是目前有一个TP选项的问题的解决方案。

我可能高估了缩减量......但希望它能阻止很多我在一个区间的末端看到2个订单的情况
每一个损失2000美元以上的情况将成为过去 :)

现在,最后一件可能有用的事情是在限价订单上设置过期选项。
目前你设置的是它们不会过期。
所以你必须手动删除。

目前,我有一堆大约3天的订单,而且不可能很快被击中。

好吧,我想说的是,工作很好... :)
 
这里有一个脚本,可以删除特定货币对 的所有未结订单。代码有点讨厌,但似乎是有效的。

//+------------------------------------------------------------------+
//|                                                   RemoveGrid.mq4 |
//|                                            Copyright © 2005, hdb |
//|                                       http://www.dubois1.net/hdb |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, hdb"
#property link      "http://www.dubois1.net/hdb"

extern string GridName = "Grid";

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {

 #property show_inputs              // shows the parameters - thanks Slawa... 

//---- 
  int total = OrdersTotal();
  int i ;
  
      for(i=total-1; i>=0;i--)
 
      {
        OrderSelect(i, SELECT_BY_POS);
        int type   = OrderType();

        if ( OrderSymbol()==Symbol() && OrderComment() == GridName )
        {
          bool result = false;
    
          switch(type)
          {
             case OP_BUY       : result = true ;
      
            case OP_SELL      : result = true ;

            //Close pending orders
            case OP_BUYLIMIT  : result = OrderDelete( OrderTicket() ); 
            case OP_BUYSTOP   : result = OrderDelete( OrderTicket() ); 
            case OP_SELLLIMIT : result = OrderDelete( OrderTicket() ); 
            case OP_SELLSTOP  : result = OrderDelete( OrderTicket() ); 
          }
    
          if(result == false)
          {
     //       Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );
     //       Sleep(3000);
          }  
        }
      }
 
//----
   return(0);
  }
//+------------------------------------------------------------------+