無料でロボットをダウンロードする方法を見る
Twitter上で私たちを見つけてください。
私たちのファンページに参加してください
興味深いスクリプト?
それではリンクにそれを投稿してください。-
他の人にそれを評価してもらいます
記事を気に入りましたか?MetaTrader 5ターミナルの中でそれを試してみてください。
スクリプト

KeyFinder 2.0 - MetaTrader 5のためのスクリプト

ビュー:
1063
評価:
(37)
パブリッシュ済み:
2016.02.25 09:53
アップデート済み:
2016.11.22 07:34
このコードに基づいたロボットまたはインジケーターが必要なら、フリーランスでご注文ください フリーランスに移動

内容

このスクリプトは、デマーク(DeMark)方式のピボットポイントを検索してチャート上に表示し、それらのディメンションを示します。

このスクリプトは実質的にKeyFinderと同じ機能を持っています。スクリプトや関連するすべてのオブジェクトをチャートから削除するボタン以外に視覚的な違いはありません。

図1KeyFinder 2.0スクリプトが適応された後のRTS指数先物契約チャート

図1KeyFinder 2.0スクリプトが適応された後のRTS指数先物契約チャート

スクリプトは、視覚的にも機能的に変更されていませんが、コードが大幅に変更されています。

CKeyFinderクラスがスクリプトのために作成されました。

図2CKeyFinderクラス

図2CKeyFinderクラス

以下がそのクラスのコードです。可能な限り詳細なコメントをつけてみたので、問題に直面することはないはずです。

//+------------------------------------------------------------------+
//|                                                    KeyFinder.mqh |
//|                                                   Trofimov Pavel |
//|                                               trofimovpp@mail.ru |
//+------------------------------------------------------------------+
#property copyright "Trofimov Pavel"
#property link      "trofimovpp@mail.ru"
//+------------------------------------------------------------------+
//| KeyFinder 2.0クラス                                            |
//+------------------------------------------------------------------+
class CKeyFinder
  {
private:
   // クラス変数
   int               MinDimension;  //ポイントの最小ディメンション
   int               MaxBars;       //処理するバーの数
protected:
   // 内部で使用されるクラスメソッド
   // 上部ポイントのディメンションの決定
   int               getHighDimension(MqlRates &tmpRates[],int tmp_i,int tmp_iCod);
   // 下部ポイントのディメンションの決定
   int               getLowDimension(MqlRates &tmpRates[],int tmp_i,int tmp_iCod);
public:
   // クラスコンストラクタ
                     CKeyFinder();
   // クラスデストラクタ
                    ~CKeyFinder();
   // ディメンション取得のプロパティメソッド
   int               GetMinDimension();
   // ディメンション設定のプロパティメソッド
   void              SetMinDimension(int temp_Val);
   // 処理するバーの数を取得するプロパティメソッド
   int               GetMaxBars();
   // 処理するバーの数を設定するプロパティメソッド
   void              SetMaxBars(int temp_Val);
   // Method for finding upper ピボットポイント
   void              FindUpKeyPoints(int temp_iCod,MqlRates &temp_rates[]);
   // 下部のピボットポイントを見つけるメソッド
   void              FindLowKeyPoints(int temp_iCod,MqlRates &temp_rates[]);
   // スクリプトオブジェクトからチャートをクリアするメソッド
   int               CleanChart();
  };
//+------------------------------------------------------------------+
//|                上部ポイントのディメンションの決定             |
//+------------------------------------------------------------------+
int CKeyFinder::getHighDimension(MqlRates &tmpRates[],int tmp_i,int tmp_iCod)// このメソッドはMqlRates型データの配列、配列内の処理されたバーの数、および配列の最大インデックスを受け取る
  {
   int k=1;
   while((tmpRates[tmp_i].high>tmpRates[tmp_i+k].high) && (tmpRates[tmp_i].high>tmpRates[tmp_i-k].high) && ((tmp_i+k)<(tmp_iCod)) && ((tmp_i-k)>0)) k++;
   if(((tmp_i+k)==tmp_iCod) || ((tmp_i-k)==0)) k=-1;
   return(k);
  };
//+------------------------------------------------------------------+
//|                下部ポイントのディメンションの決定             |
//+------------------------------------------------------------------+
int CKeyFinder::getLowDimension(MqlRates &tmpRates[],int tmp_i,int tmp_iCod)// このメソッドはMqlRates型データの配列、配列内の処理されたバーの数、および配列の最大インデックスを受け取る
  {
   int k=1;
   while((tmpRates[tmp_i].low<tmpRates[tmp_i+k].low) && (tmpRates[tmp_i].low<tmpRates[tmp_i-k].low) && ((tmp_i+k)<(tmp_iCod)) && ((tmp_i-k)>0)) k++;
   if(((tmp_i+k)==tmp_iCod) || ((tmp_i-k)==0)) k=-1;
   return(k);
  };
//+------------------------------------------------------------------+
//| GetMinDimensionメソッド                                           |
//+------------------------------------------------------------------+
int CKeyFinder::GetMinDimension(){return(MinDimension);};
//+------------------------------------------------------------------+
//| SetMinDimensionメソッド                                           |
//+------------------------------------------------------------------+
void CKeyFinder::SetMinDimension(int temp_Val)
  {
   if(temp_Val>1) MinDimension=temp_Val;
   else
     {
      MessageBox("The set dimension is too low."+"\n"+"The default dimension of 5 will be used","Warning!",MB_OK+MB_ICONWARNING);
      MinDimension=5;
     };
  };
//+------------------------------------------------------------------+
//| GetMaxBarsメソッド                                                |
//+------------------------------------------------------------------+
int CKeyFinder::GetMaxBars() {return(MaxBars);};
//+------------------------------------------------------------------+
//| SetMaxBarsメソッド                                                |
//+------------------------------------------------------------------+
void CKeyFinder::SetMaxBars(int temp_Val)
  {
// バーのセット数の履歴の可用性をチェック
   int SMaxBars=Bars(Symbol(),0);
   if(SMaxBars<temp_Val)
     {
      temp_Val=SMaxBars;// 使用可能なバーの最大数の設定
      MessageBox("The MaxBars parameter is too high."+"\n"+"Only "+IntegerToString(temp_Val)+" bars will be used for calculation.","Warning!",MB_OK+MB_ICONWARNING);
     };

// バーの数が低すぎないかどうかの確認
   if(temp_Val<(2*MinDimension))
     {
      MessageBox("The set number of bars is too low."+"\n"+"The default number of 300 will be used","Warning!",MB_OK+MB_ICONWARNING);
      temp_Val=300;
     };
   MaxBars=temp_Val;
  };
//+------------------------------------------------------------------+
//| FindKeyPointsメソッド - 上部キーポイントを見つける                  |
//+------------------------------------------------------------------+
void CKeyFinder::FindUpKeyPoints(int temp_iCod,MqlRates &temp_rates[])// このメソッドは最大配列要素のインデックスとMqlRates配列を受け取る
  {
   int HD=1;   //ポイントディメンションの初期化
   for(int i=temp_iCod-MinDimension; i>(MinDimension-1); i--)// 最後のバーからのループ - ゼロバーへのMinDimension + MinDimension
     {
      HD=getHighDimension(temp_rates,i,temp_iCod);//ポイントディメンションの取得
      if((HD>=MinDimension) || (HD==-1))
        {//MinDimension条件があった場合のマーク作成
         string Ob_Name="KF_Label"+IntegerToString(i);
         if(HD!=-1)
           {
            ObjectCreate(0,Ob_Name,OBJ_TEXT,0,temp_rates[i].time,temp_rates[i].high);
            ObjectSetInteger(0,Ob_Name,OBJPROP_ANCHOR,0,ANCHOR_LOWER);
            ObjectSetString(0,Ob_Name,OBJPROP_TEXT,0,IntegerToString(HD));
            ObjectSetInteger(0,Ob_Name,OBJPROP_COLOR,clrRed);
           }
         else
           { //ディメンションがわからなければ、ボールマークを使うk
            ObjectCreate(0,Ob_Name,OBJ_ARROW,0,temp_rates[i].time,temp_rates[i].high);
            ObjectSetInteger(0,Ob_Name,OBJPROP_ARROWCODE,0,159);
            ObjectSetInteger(0,Ob_Name,OBJPROP_ANCHOR,0,ANCHOR_BOTTOM);
            ObjectSetInteger(0,Ob_Name,OBJPROP_COLOR,clrRed);
           };
        };
     };
  };
//+------------------------------------------------------------------+
//| FindLowKeyPointsメソッド - 下部のキーポイントを見つける            |
//+------------------------------------------------------------------+   
void CKeyFinder::FindLowKeyPoints(int temp_iCod,MqlRates &temp_rates[])// The method receives an index of the maximum array element and the MqlRates array
  {
   int LD=1;//initializing points dimensions
   bool iCreate;
   for(int i=temp_iCod-MinDimension; i>(MinDimension-1); i--)// 最後のバーからのループ - ゼロバーへのMinDimension + MinDimension
     {
      LD=getLowDimension(temp_rates,i,temp_iCod);
      if((LD>=MinDimension) || (LD==-1))
        {
         string Ob_Name="KF_Label"+IntegerToString(i)+"_1";//バーを避ける。Low と High がキーポイントであり得る
         if(LD!=-1)
           {
            iCreate=ObjectCreate(0,Ob_Name,OBJ_TEXT,0,temp_rates[i].time,temp_rates[i].low);
            if(iCreate)
              {
               ObjectSetInteger(0,Ob_Name,OBJPROP_ANCHOR,0,ANCHOR_UPPER);
               ObjectSetString(0,Ob_Name,OBJPROP_TEXT,0,IntegerToString(LD));
               ObjectSetInteger(0,Ob_Name,OBJPROP_COLOR,clrGreen);
              }
            else Comment("Cannot create the object");
           }
         else
           {
            iCreate=ObjectCreate(0,Ob_Name,OBJ_ARROW,0,temp_rates[i].time,temp_rates[i].low);
            if(iCreate)
              {
               ObjectSetInteger(0,Ob_Name,OBJPROP_ARROWCODE,0,159);
               ObjectSetInteger(0,Ob_Name,OBJPROP_ANCHOR,0,ANCHOR_TOP);
               ObjectSetInteger(0,Ob_Name,OBJPROP_COLOR,clrGreen);
              }
            else Comment("Cannot create the object");
           };
        };
     };
  };
//+------------------------------------------------------------------+
//| CleanChartメソッド - チャートからのオブジェクトの削除              |
//+------------------------------------------------------------------+   
int CKeyFinder::CleanChart(void)
  {
   string Label="KF_Label";
   int obj_total=ObjectsTotal(0,0,-1),n=0;
   for(int obj=obj_total-1; obj>=0; obj--) //名前マスクを使ってスクリプトが作成したオブジェクトをチャートから削除する
     {
      string objname=ObjectName(0,obj,0,-1);
      if(StringFind(objname,Label)>=0) ObjectDelete(0,objname);
      n++;
     }
   return(n);
  }
//+------------------------------------------------------------------+
//| クラスコンストラクタ                                                |
//+------------------------------------------------------------------+
CKeyFinder::CKeyFinder(){};
//+------------------------------------------------------------------+
//| クラスデストラクタ                                                 |
//+------------------------------------------------------------------+
CKeyFinder::~CKeyFinder(){};
//+---------------------------------------------------------------------+

コードのほとんどは、クラスに移動されたので、メインスクリプトコードは非常にコンパクトです。

//+------------------------------------------------------------------+
//|                                                   KeyFinder2.mq5 |
//|                                                   Trofimov Pavel |
//|                                               trofimovpp@mail.ru |
//+------------------------------------------------------------------+
#property copyright "Trofimov Pavel"
#property link      "trofimovpp@mail.ru"
#property version   "2.00"
#property description "Warning!This algorithm uses loops for calculations!"
#property description "It is recommended so set not more than 1000 to process!"
#property script_show_inputs
//--- input parameters
input int      MinDimesion=5; //ポイントの最小ディメンション
input int      MaxBars=300;   //処理されるバーの数
#include       "KeyFinder.mqh"
#include       <ChartObjects\ChartObjectsTxtControls.mqh>
//+------------------------------------------------------------------+
//| スクリプト変数                                                 |
//+------------------------------------------------------------------+
CKeyFinder           m_keyfinder;      //СKeyFinderクラス変数の宣言
CChartObjectButton   m_button_close;   //CChartObjectButtonクラス変数の宣言
//+------------------------------------------------------------------+
//| スクリプトプログラム開始関数                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//-変数の初期化
   MqlRates  rates_array[];
   string Com="\n\n\n";
   int iCod=CopyRates(Symbol(),Period(),0,MaxBars,rates_array);// コピーできたMqlRates配列要素の数
   int sy=10;//ボタンの位置
   if(ChartGetInteger(0,CHART_SHOW_OHLC))
      sy+=16;
//-必要なパラメータの設定   
   m_keyfinder.SetMaxBars(MaxBars);
   m_keyfinder.SetMinDimension(MinDimesion);
   m_keyfinder.CleanChart();//二回目に使用する場合オブジェクトからチャートをクリアする
   iCod=iCod-1;//rates_array[]の最大要素のインデックス
   Com+="Working...Please, wait!";
//-ボタンの作成とプロパティの設定
   m_button_close.Create(0,"ButtonClose",0,10,sy,100,20);
   m_button_close.Description("Close Script");
   m_button_close.Color(Blue);
   m_button_close.FontSize(8);
   Comment(Com);
//-CKeyFinderクラスメソッドでのバーの処理
   if(iCod>0)
     {
      m_keyfinder.FindUpKeyPoints(iCod,rates_array);//上部キーポイントの検索
      Com+="\nUpper points have been processed.\n";
      Comment(Com);
      m_keyfinder.FindLowKeyPoints(iCod,rates_array);//下部キーポイントの検索
      Comment("\n\n\nProcessing is complete");
     }
   else Comment("\n\n\nNo bars to process!!!");
   m_button_close.State(false);
//-Looping the script until the button is pressed
   while(!(m_button_close.State()))
     {
      //--- チャートの再描写
      ChartRedraw();
      Sleep(250);
     };
//-ボタンを押してチャートをクリアする
   m_keyfinder.CleanChart();
   Comment("");
  }

最後に、いくつかの有用なリンクと説明を含みました。

  • MetaEditorから直接コードを読み込む方法
  • スクリプトをMetaTrader 4で使用するには、KeyFinder2.mq5ファイルの拡張子をmq4に変えてMetaEditorで再コンパイルする必要があります。クラスコード を含むKeyFinder.mqhアイルはメインスクリプトファイルと同じディレクトリに格納されるべきです(例えば MQL5\Scripts)。

みなさんのコメント、フィードバックやご提案を楽しみにしています。みなさんのトレーディングの成功を祈って。みなさんのトレーディングの成功を祈って!

MetaQuotes Ltdによってロシア語から翻訳されました。
元のコード: https://www.mql5.com/ru/code/12439

KeyLevels KeyLevels

00、20、50、80のラウンドナンバーで価格レベルを示すインディケータ。

KeyFinder KeyFinder

このスクリプトは、デマーク(DeMark)方式のピボットポイントを検索してチャート上に表示し、それらのディメンションを示します

Back to the Future Back to the Future

規制を用いたファンダメンタル分析

トレンドオシレータ トレンドオシレータ

Hodrick-Prescottフィルターを使用するトレンドオシレータ