计算M1时期与D1时期开盘价交叉的条形图的指标 - 页 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。

请告知我们如何才能最好地改善这一点。谢谢。


看上去你已经实现了我的建议。

第1行落到了0,因为代码中没有计算缓冲区[0]。你必须决定你是否希望这个值从0开始,并随着时间的推移而增加,或者也许只是让buffer[0]==buffer[1],这将使它看起来更整洁。

 
感谢WHRoeder、qjol和GumRai对我的指标编码的巨大帮助。
 
GumRai:


看上去你已经实现了我的建议。

第1行落到了0,因为代码中没有计算buffer[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数据