新しいタイムフレームのチャートに変更すると、インジケータが消えてしまう。

 

こんにちは。

私はあるインジケータ(最初の部分)から始めています。時間枠を変えても問題なく動作します。

次に、2番目の部分を追加します。Close[i]-Close[i+1]が過去100バーの差の中央値より小さい場合、すべてのバッファに値0を割り当てます。

このインジケータは1つのチャートでは正常に動作しますが、タイムフレームを変更すると、このインジケータは消えてしまいます。そのため、このインジケータをチャートに再接続する必要があります。

この問題はArrayが原因だと思うのですが、どうすれば解決できるのかわかりません。

どなたかこのエラーについて教えていただけませんか?

本当にありがとうございました。

SCFX

//+------------------------------------------------------------------+
//|                                                          hf1.mq4 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                              httakeprofit://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "httakeprofit://www.mql5.com"
#property version   "1.00"
#property strict

//--- indicator settings
//#property indicator_chart_window
#property indicator_separate_window
#property indicator_buffers 5
#property indicator_width1 2  
#property indicator_width2 2 
#property indicator_width3 1 
#property indicator_width4 1 
#property indicator_width5 1 

#property indicator_color1 Yellow
#property indicator_color2 Red
#property indicator_color3 Red
#property indicator_color4 Orange
#property indicator_color5 Orange

//--- input parameter
input int kperiod=30;
input int dperiod=9;
input int slow=9;
input int sample_roc_quartile=100;

//--- buffers
double buy[];
double sell[];
double stoploss[];
double takeprofit1[];
double takeprofit2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void) //*/*/*/*/*/
  {
//--- indicator buffers mapping
//--- 1 additional buffer used for counting.
   //IndicatorBuffers(6);
   IndicatorDigits(Digits);
//--- indicator line
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexBuffer(0,buy);
   SetIndexArrow(0,241);
   
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexBuffer(1,sell);
   SetIndexArrow(1,242);

   SetIndexStyle(2,DRAW_ARROW);
   SetIndexBuffer(2,stoploss);

   SetIndexStyle(3,DRAW_ARROW);
   SetIndexBuffer(3,takeprofit2); 
         
   SetIndexStyle(4,DRAW_ARROW);
   SetIndexBuffer(4,takeprofit1);  
   
  
//--- name for DataWindow and indicator subwindow label

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
      int limit=rates_total-prev_calculated;
      
      double roc_s[];
      ArrayResize(roc_s,sample_roc_quartile+1);

//---

//------------------------------------------ 

for(int i=0; i<limit; i++)
{  

//FIRST PSART 

   if(iStochastic(NULL,0,kperiod,dperiod,slow,0,0,0,i)>iStochastic(NULL,0,kperiod,dperiod,slow,0,0,1,i)   &&   iStochastic(NULL,0,kperiod,dperiod,slow,0,0,0,i+1)<iStochastic(NULL,0,kperiod,dperiod,slow,0,0,1,i+1))   
      {  buy[i]=Close[i]; 
         stoploss[i]=Low[i]-0.005; 
         takeprofit1[i]=Close[i]+0.005;
         takeprofit2[i]=Close[i]+0.01;
         }
      
   if(iStochastic(NULL,0,kperiod,dperiod,slow,0,0,0,i)<iStochastic(NULL,0,kperiod,dperiod,slow,0,0,1,i)   &&   iStochastic(NULL,0,kperiod,dperiod,slow,0,0,0,i+1)>iStochastic(NULL,0,kperiod,dperiod,slow,0,0,1,i+1))   
      {  sell[i]=Close[i]; 
         stoploss[i]=High[i]; 
         takeprofit1[i]=Close[i]-0.0050;
         takeprofit2[i]=Close[i]-0.01;
         }   
         
//SECOND PART         
   for(int j=0;j<=sample_roc_quartile;j++)
   {
      roc_s[j]=Close[i+j]-Close[i+j+1];
      ArraySort(roc_s);
      
      if(   (Close[i]-Close[i+1])<roc_s[50]  )
         {  buy[i]=0; 
            stoploss[i]=0; 
            takeprofit1[i]=0;
            takeprofit2[i]=0;
         }
    }     
}
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 

配列の範囲 外エラーでインジケータが削除されている可能性あり

int limit=rates_total-prev_calculated;

for(int i=0; i<limit; i++)
iStochastic(NULL,0,kperiod,dperiod,slow,0,0,0,i+1)<iStochastic(NULL,0,kperiod,dperiod,slow,0,0,1,i+1))

ログにグローバル初期化失敗のメッセージが表示されている可能性があります。
ログを確認してください。

 

ご指摘ありがとうございます。

ログを確認 しましたが、エラーや警告の表示はありません。

(i+1)は単独で(あるいはSecond部分を削除するだけでも)このインジケータは問題なく動作するので、トラブルの原因になるとは思えません。

SCFX

 

エラーがあります あなたのコードをコンパイルし、それをテストしました。

2014.05.22 22:39:43.936 カスタム指標 テスト指標3 XAUUSD,M1: 削除されました。
2014.05.22 22:39:43.905 テスト指標3 XAUUSD,M1:グローバル初期化に失敗
2014.05.22 22:39:43.905 テスト指標3 XAUUSD,M5: uninit reason 3 //----------------------- チャートを変更する
2014.05.22 22:39:17.323 「テスト指標3.mq4」の配列が範囲外 です (117,32)
2014.05.22 22:39:15.591 テスト指標3 XAUUSD,M5: 初期化されました。
2014.05.22 22:39:09.570 カスタムインジケータ テストインジケータ3 XAUUSD,M5: ロード成功

 
scfx:

ご指摘ありがとうございます。

ログを確認しましたが、エラーや警告の表示はありません。

(i+1)は単独で(あるいはSecond部分を削除するだけでも)このインジケータは問題なく動作するので、トラブルの原因になるとは思えません。

SCFX


それはおそらくこれです

roc_s[j]=Close[i+j]-Close[i+j+1];

あなたは、存在しないバーの終値を 取得しようとしている

 

最初にインジケータを起動したときに : prev_calculated == 0 という行を追加する必要があります。

みたいな感じで。

 int limit = -100;
   if( prev_calculated == 0 ) limit = 3000;// will calculate 3000 Bars
    else                      limit = rates_total-prev_calculated;
      

私のPCではエラーは出ませんでした ;-)

 

ffoorrさん、こんにちは。

あなたの解決策は本当に素晴らしいです。

実を言うと、私は昨晩それを修正するために誰かを雇いました。しかし、そのコードは非効率的で、以下のようにfor(i)をもう一つ追加しています。

prev_calculated==0の意味を説明していただけるとありがたいです。

//+------------------------------------------------------------------+
//|                                                          hf1.mq4 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                              httakeprofit://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "httakeprofit://www.mql5.com"
#property version   "1.00"
#property strict

//--- indicator settings
//#property indicator_chart_window
#property indicator_separate_window
#property indicator_buffers 5
#property indicator_width1 2  
#property indicator_width2 2 
#property indicator_width3 1 
#property indicator_width4 1 
#property indicator_width5 1 

#property indicator_color1 Yellow
#property indicator_color2 Red
#property indicator_color3 Red
#property indicator_color4 Orange
#property indicator_color5 Orange

//--- input parameter
input int kperiod=30;
input int dperiod=9;
input int slow=9;
input int sample_roc_quartile=100;

//--- buffers
double buy[];
double sell[];
double stoploss[];
double takeprofit1[];
double takeprofit2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void) //*/*/*/*/*/
  {
//--- indicator buffers mapping
//--- 1 additional buffer used for counting.
   //IndicatorBuffers(6);
   IndicatorDigits(Digits);
//--- indicator line
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexBuffer(0,buy);
   SetIndexArrow(0,241);
   
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexBuffer(1,sell);
   SetIndexArrow(1,242);

   SetIndexStyle(2,DRAW_ARROW);
   SetIndexBuffer(2,stoploss);

   SetIndexStyle(3,DRAW_ARROW);
   SetIndexBuffer(3,takeprofit2); 
         
   SetIndexStyle(4,DRAW_ARROW);
   SetIndexBuffer(4,takeprofit1);  
   
  
//--- name for DataWindow and indicator subwindow label

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
      int limit=rates_total-prev_calculated;
          if(limit<=0)limit =2;
     
      double roc_s[];
      ArrayResize(roc_s,sample_roc_quartile+1);

//---

//------------------------------------------ 

for(int i=1; i<limit; i++)
{  

//FIRST PSART 

   if(iStochastic(NULL,0,kperiod,dperiod,slow,0,0,0,i)>iStochastic(NULL,0,kperiod,dperiod,slow,0,0,1,i)   
   &&   iStochastic(NULL,0,kperiod,dperiod,slow,0,0,0,i+1)<iStochastic(NULL,0,kperiod,dperiod,slow,0,0,1,i+1))   
      {  buy[i]=Close[i]; 
         stoploss[i]=Low[i]-0.005; 
         takeprofit1[i]=Close[i]+0.005;
         takeprofit2[i]=Close[i]+0.01;
         }
      
   if(iStochastic(NULL,0,kperiod,dperiod,slow,0,0,0,i)<iStochastic(NULL,0,kperiod,dperiod,slow,0,0,1,i)   
   &&   iStochastic(NULL,0,kperiod,dperiod,slow,0,0,0,i+1)>iStochastic(NULL,0,kperiod,dperiod,slow,0,0,1,i+1))   
      {  sell[i]=Close[i]; 
         stoploss[i]=High[i]; 
         takeprofit1[i]=Close[i]-0.0050;
         takeprofit2[i]=Close[i]-0.01;
         }   
} 

    
//SECOND PART   

//--------------------------------------- HERE IS THE WHAT HE DID
int mid = (sample_roc_quartile +1)/2;
  
for(int i=1; i<limit&&(i+1)<rates_total; i++)
{    

//---------------------------------------------


  for(int j=0;j<=sample_roc_quartile&&(i+j+1)<rates_total;j++)
   {
      roc_s[j]=Close[i+j]-Close[i+j+1];
      ArraySort(roc_s);
   }   
      
      if( (Close[i]-Close[i+1])<roc_s[mid]  )
         {  buy[i]=0; 
            stoploss[i]=0; 
            takeprofit1[i]=0;
            takeprofit2[i]=0;
         }
    
 }    

//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 

皆さん、こんにちは・・・。


IBFX MACD traditional indicatorと他のテンプレートをMT4にインストールするのに問題があります。

以前のバージョンでは、「expert」フォルダの中にある「indicator」フォルダにファイルをコピー&ペーストするだけでよかったのですが、現在のバージョンでは、「MQL4」フォルダだけがあり、「expert」と「indicator」の2つのフォルダから構成されています。

現在のものは「MQL4」フォルダのみで、「expert」フォルダと「indicator」フォルダが別々に構成されています。

両方のフォルダにペーストし、プラットフォームを再起動しようとしましたが、うまくいきません。

ということです。

また、2本のEMAラインを持つ伝統的なMACDインディケータを 取得するための他の方法があれば教えてください。

ありがとうございます。

Douglas
 
DOUGLAS BENGさん、他の人のトピックに自分の質問を載せるのはやめた方がいいですよ、他の人のトピックとは関係ないんですから。自分のトピックを立ち上げてください。
 
douglas_heng: IBFXのMACDトラディショナルインジケーターなどのテンプレートをMT4にインストールするのに苦労しています。
Don'tDon't multiple (6) posts.他の人の投稿をハイジャックしないでください。
 
scfx:

ffoorrさん、こんにちは。

あなたの解決策は本当に素晴らしいです。

実を言うと、私は昨晩それを修正するために誰かを雇いました。しかし、そのコードは非効率的で、以下のようにfor(i)をもう一つ追加しています。

prev_calculated==0の意味を説明していただけるとありがたいです。


まあscfxさん、あなたのインジケータの2番目の部分が理解できないので、わからないのですが。

インジケータを初めて起動するとき(チャートに置くとき)、prev_calculatedは構造上ゼロに等しいので、インジケータが計算を開始する起点を固定することができます。

if( prev_calculated == 0) limit = 100;

もしくは

if( prev_calculated < 50) limit = 500:

または、次のようにします。

if( prev_calculated < 500) limit = 3000: (すべて同じ、チャートの始まりは使われない)

int limit = -100;
   if( prev_calculated == 0 ) limit = 3000;// will calculate 3000 Bars
    else                      limit = rates_total-prev_calculated;

at the first lauch of the indicator limit = 3000;

for(int i=1; i<3000; i++) // draw 3000 bars 

at the second lauch limit = 0; // ( because rates_total-prev_calculated = 0)  ;
for(int i=1; i<0; i++)    //   draw the last bars only, faster

とても良いアイデアです。

理由: