グリッドメーカー 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) and Oanda forums (MarkVH and Sympatico) で長い間このアイデアに従ってきました。私は、あなたがフォーラムに送った最初のスクリプトを改善するためにいくつかの専門家を開発する方法について考えてきました、おそらく我々は、より速く何かを得るために一緒に仕事ができます)あなたが興味を持っている場合は、私に知らせてください私の電子メールは、artefactodigital@gmail.com。

最高のよろしく。
フェルナンド。

グリッドメーカーのバージョン1.1です...スクリプトまたはエキスパートアドバイザーで、等間隔に並んだ売買注文を設定・維持します。<br / translate="no"> このバージョンは、スクリプトやエキスパートアドバイザーのいずれかであり、更新頻度を変更することができ、ロングとショートを選択するなど、説明のためにパラメータを参照してください。

私はほとんどのバリエーションをテストしていると思うが、それはすべてのケースで動作することを保証するものではありません!あなたがそれを試してみて、問題を見つけた場合、それはあなたのためのものではありません。もし、試してみて問題があれば、私に教えてください。

これはおそらく私が投稿する最後のバージョンです。MT4をテストするために開発しました。今後のバージョンはもっと複雑になり、サポートやレジスタンスのレベルなどの外部データが必要になるので、それを掲載するのは適切ではないでしょう。
 
よし、いい感じだ。
 
ところで、あなたはそれを試して、使用して、それを変更するのは自由ですが、それを販売しないようにしてください。

私はこのスクリプトの有効な動作状態を保証するものではありません。
このスクリプトによる直接または間接的な損失について、私は一切の責任を負いません。


このスクリプトを使用した場合、結果、設定、バグ、観察など、時折フィードバックを投稿してください。

お楽しみに
 
市場の大きな動きの後、グリッドは生き残りました!2週間前に5万円でデモ口座を 作りました。
グリッドメーカーをテストして1kを失い、ユーロ急落の直前にデフォルトのグリッドメーカー・エキスパートを9通貨ペアに設定しました。
eur/chf, usd/jpy, gbp/jpy, eur/gbp, usd/chf, aud/usd, gbp/usd, eur/usd, eur/jpy の9つの通貨ペアです。

グリッド間隔は全通貨で6ティック、TPは6ティックです。ロットサイズは0.1ロットで置きました。各通貨ペアで6ティックごとにロングANDショートを行いました。
リフレッシュはEUR/USDとGBP/USDが5分である以外は15分ごと(つまりグリッドが15分ごとにリゲインされる)だった。

残高は10k(20%)増、使用した証拠金は13k(26%)、フリーマージンは26k(52%)、含み損は-19kです。

ユーロバンの正味の結果は、(今のところ)-9kのダウンです。私はこれよりずっと悪いと予想していたのですが

グリッドは、1日あたり600から2000の割合で残高を増やしています。

来週はどうなっているか楽しみです。

グリッド万歳!
 
さてさて、1週間後、グリッドは本当に打撃を受けてしまいました。必要なロットサイズとグリッド間隔の計算をしなかったのが悪いのですが
を計算していなかったことが原因です。

とにかく、残高はかなり順調に推移しています:1日あたり700から1800の増加 - 残高は現在65k(49kで開始したので、これは+16kです)。
使用した証拠金は15k、利用可能な証拠金は21k - 必要に応じてポジションを追加する余地はまだたくさんあります。
含み損は-29kで、純損益は13kとなり、先週より4k悪化しました。

プラス面は、カウンタートレードを避けるように設定を変更したこと(CounterTrade flag false)で、含み損は安定したようです。
一時は-36kでした。

このフォワードテストについて私が気に入っているのは、先週のユーロの下落という大きな打撃から始まったことです。
いつどのように回復するかが見ものです。私は、そうなることを確信しています。

来週、結果が出るのが楽しみです。

ps.私は、TPを変更し、SLを追加する可能性のあるv1.2を持っています。もし欲しいならここに投稿してください。
 
私は、この製品でかなり遊んでいます。すべてのペアで、すべてをデフォルトで実行しています。
その性能に非常に感銘を受けたと言わざるを得ません。





つまり、テイクプロフィットは 次に開始されるショートと同じ価格であり、スプレッド、つまり買値と売値は考慮されません。 したがって、価格がロングサイドに反転する前に2つの注文を開くことを防ぐために、次のショート注文が置かれると同時にTPが発生する必要があります。このようなことが可能であれば、私のドローダウンは半分になるのではないかと思っています。 この問題は、あなたの最新のバージョンで解決できるのではないでしょうか。もし、それを投稿していただけるなら、とてもうれしいです。
 
こんにちは。

あなたがそれを楽しいと感じるのはうれしいです。

TP=グリッドサイズと同時に、反転時に2つのオープンポジションを持つ可能性を排除する方法はないのです。
これはソフトウェアの問題ではなく、単純にスプレッドに関係することです。

理論的にこれを完全に排除する唯一の可能性は、その都度スプレッドを失うことです。
例えば、1.2006 (bid) でショートし、1.2000 (ask) で TP、1.1996 (bid) でショートすると、4ティックのスプレッドがある場合。
この場合、単純にレンジの4/10を失うことになります。

新しいバージョンでは、グリッドサイズとTPを異なる数値に設定することができますので、あなたが探しているものを実装することができます。
新しいバージョンでは、グリッドサイズとTPを異なる数値に設定することができるので、あなたが探しているものを実装することができます。

ddが半分になるかどうかはわかりませんが、利益が大幅に減ることは間違いないでしょう。

教えてください。

ps. 次の投稿でv1.2が公開されます。
 
グリッドメーカーのv1.2です。
1) ストップロスが必要な場合は、オプションで追加しました。
もしグリッドでストップロスを 使うなら、大きくする必要があります。
2) グリッドのサイズと異なるTPを指定することができます。


save it to the expert advisor folder ( like C:\Program FilesMetaTrader 4experts ) and an optional copy to the scripts folder
if you want as a script (C:\Program FilesMetaTrader 4experts pipes)このスクリプトは、エキスパートアドバイザーフォルダに保存します。

グリッドの注文を削除するスクリプトもあります。

注意: 前バージョンからデフォルトの設定が変更されている可能性があります。

QUESTION to an administrator: このようなものはエキスパートアドバイザーライブラリに置くべきかもしれません。これは正しいですか?

//+------------------------------------------------------------------+
//|                                                     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);
  }
//+------------------------------------------------------------------+
理由: