D1期間の始値と交差するM1期間の棒をカウントする指標。 - ページ 3

 
Zaldy:


そのコードは値を与えるかもしれませんが、正しい値を与えるものではありません。

私の以前の投稿をご覧ください。

 
GumRai:


そのコードは値を与えるかもしれませんが、正しい値を与えるものではありません。

私の以前の投稿をご覧ください。

こんにちは、Gumraiさん、あなたのコードとここに添付したQjolマジックコードをコンパイルしてみました。qjolのコードなしでは、プロットの形は数字の7のようですが、qjolのコードを追加すると、より良い動作になります。画像にあるように、値は-1まで下がりました。このプロットは前の画像と同じ形をしていますが、値が違います。これを改善する方法を教えてください。ありがとうございます。
 
#property indicator_separate_window    // Indicator is drawn in the main window
#property indicator_buffers 1       // Number of buffers
#property  indicator_color1 Red     // Color of the 1st line
//#property indicator_color2 Yellow      // Color of the 2nd line
 
//extern int Multiplier=2; 
double Buf_0[];// Buf_1[];             // Declaring indicator arrays
//THIS INDICATOR IS TO COUNT NUMBER OF M1 BARS WHICH HIGH[I] IS HIGHER AND LOW[I] IS LOWER THAN OPEN[1440].
//--------------------------------------------------------------------
int init()                          // Special function init()
  {
//--------------------------------------------------------------------
   SetIndexBuffer(0,Buf_0);         // Assigning an array to a buffer
   SetIndexStyle (0,DRAW_LINE,STYLE_SOLID,2);// Line style
//--------------------------------------------------------------------
//   SetIndexBuffer(1,Buf_1);         // Assigning an array to a buffer
//   SetIndexStyle (1,DRAW_LINE,STYLE_SOLID,2);// Line style
//--------------------------------------------------------------------
   return(0);                          // Exit the special funct.init()
  }
//--------------------------------------------------------------------
int start()                         // Special function start()
  {
  
  
     int  i=0, iCht, Counted_bars; 
      
   
//--------------------------------------------------------------------
  Counted_bars=IndicatorCounted(); // Number of counted bars
   for(iCht = Bars - 1 - Counted_bars; iCht >= 0; iCht--){ // Chart bars
      int      iD1    = iBarShift(Symbol(), PERIOD_D1, Time[iCht]); 
    Buf_0[iCht] = EMPTY;  //  <<<<<<<<<<<< This is the magic code that gjol inserted and it worked.      
      //----find the datetime of iD1. ie the Time[]
      datetime daystarttime = iTime(Symbol(),PERIOD_D1,iD1);
      
      double   openD1 = iOpen(Symbol(), PERIOD_D1, iD1);
      
      //----find BarShift of daystarttime on current chart and take the nearest following bar if it doesn't exist
      int iM1Beg = iBarShift(Symbol(),PERIOD_M1,daystarttime,true);
      if(iM1Beg<0)
         iM1Beg = iBarShift(Symbol(),PERIOD_M1,daystarttime,false)+1;
      
      //----find BarShift for end of day on current chart and take the nearest following bar if it doesn't exist
      if(iD1>0)
         {
         datetime nextday = iTime(Symbol(),PERIOD_D1,iD1-1);
         int iM1End = iBarShift(Symbol(),PERIOD_M1,nextday-1,true);
         if(iM1End<0)
         
            iM1End = iBarShift(Symbol(),PERIOD_M1,nextday,false);
      
               
       
         for(Buf_0[i] = 0; iM1Beg > iM1End; iM1Beg--){
                double hM1 = iHigh(Symbol(), PERIOD_M1, iM1Beg),
                lM1 =  iLow(Symbol(), PERIOD_M1, iM1Beg);
// count Bars of M1 Period that crisscross Open price of D1 Period 
         if( hM1 >= openD1 && openD1 >= lM1) Buf_0[iCht]++;
         } 
         }
         }
//--------------------------------------------------------------------
   return(0);// 
  }
//--------------------------------------------------------------------
 
GumRai:


そのコードは値を与えるかもしれませんが、正しい値を与えるものではありません。

以前の投稿をご覧ください。


GumRaiさん、こんにちは。

どのようにしたら改善されるのか、アドバイスをお願いします。ありがとうございます。

 
Zaldy:


GumRaiさん、こんにちは。

どのように改善したらよいか、アドバイスをお願いします。ありがとうございます。


私の提案はすでに実装されているようですね。

バッファ[0]が計算されていないため、indi行は0になります。この値を0から始めて日が経つにつれて増加させるのか、それともbuffer[0] == buffer[1]とした方が見た目がすっきりするのか、判断する必要がありますね。

 
WHRoederさん、qjolさん、GumRaiさん、私のインジケータのコーディングに多大なご協力をありがとうございました。
 
GumRai:


私の提案はすでに実装されているようですね。

バッファ[0]が計算されていないため、インジラインはゼロになります。この値を0から始めて日が経つにつれて増加させるか、あるいはbuffer[0] == buffer[1]にするか決めなければなりませんが、その方がすっきりするでしょう。


GumRaiさん、こんにちは!0から始まって日が進むにつれて増えていくようなコーディングはどうすればいいでしょうか?助けてください。ありがとうございます。
 
Zaldy:

こんにちは、GumRai、どのように私は0から始まり、一日の進行に応じて増加するようにコード化することができますか?助けてください。ありがとうございます。


あなたのコードにいくつか変更を加えてみました。



int start()                         // Special function start()
  {
  
  
  int  i, iCht, Counted_bars, limit, iD1, iM1Beg, iM1End, counter ; 
  datetime daystarttime, nextday ;   
  double hM1, lM1, openD1 ; 
//--------------------------------------------------------------------
  Counted_bars=IndicatorCounted(); // Number of counted bars
  limit = Bars - 1 - Counted_bars;
  if(limit > Bars-100)   
      limit = Bars-100;
  for(iCht = limit; iCht >= 0; iCht--){ // Chart bars
      iD1 = iBarShift(Symbol(), PERIOD_D1, Time[iCht]); //---Barshift on daily chart
      daystarttime = iTime(Symbol(),PERIOD_D1,iD1); //--Find datetime value for start of the day      
      openD1 = iOpen(Symbol(), PERIOD_D1, iD1);
      
      //----find BarShift of daystarttime on current chart and take the nearest following bar if it doesn't exist
      iM1Beg = iBarShift(Symbol(),PERIOD_M1,daystarttime,true);
      if(iM1Beg<0)
         iM1Beg = iBarShift(Symbol(),PERIOD_M1,daystarttime,false)+1;
      
      //----find BarShift for end of day on current chart and take the nearest following bar if it doesn't exist
      if(iD1>0)  //-- Change to iD1>=0 to show running total for the current day
         {
         nextday = iTime(Symbol(),PERIOD_D1,iD1-1);
         iM1End = iBarShift(Symbol(),PERIOD_M1,nextday-1,true);
         if(iM1End<0)         
            iM1End = iBarShift(Symbol(),PERIOD_M1,nextday,false);
       
         counter = 0;
         for(i= iM1Beg; i >= iM1End; i--){
            hM1 = iHigh(Symbol(), PERIOD_M1, i);
            lM1 =  iLow(Symbol(), PERIOD_M1, i);
            // count Bars of M1 Period that crisscross Open price of D1 Period 
            if( hM1 >= openD1 && openD1 >= lM1)
               counter++ ;
         }
         Buf_0[iCht] = counter; 
         }
         }
//--------------------------------------------------------------------
   return(0);// 
  }
//--------------------------------------------------------------------
//+------------------------------------------------------------------+

これは、あなたが望むものを行う必要があります

このままでは、今日の値が表示されません。

ハイライトされたテキストのように変更すると、0から始まり、日が 進むにつれて増加する今日の値が含まれるようになるはずです。

 

なぜ、この区画は不完全なのか。2014年1月以前は記入されていません。問題点をご教示ください。このチャートはWHRoederのコードを使っていますが、GumRaiが提案したものでも同じように廃れたプロットが得られます。

 
なぜなら、それ以前のM1データがないからです。