Indicador para contar barras de M1 Período que cruza Preço aberto do Período D1 - página 3

 
Zaldy:


Esse código pode dar valores, mas não dá valores corretos.

Por favor, veja meus cargos anteriores

 
GumRai:


Esse código pode dar valores, mas não dá valores corretos.

Por favor, veja meus cargos anteriores

Oi Gumrai, eu compilei seu código mais o código mágico Qjol que anexei aqui. Sem o código qjol o formato da trama é como um número 7, mas acrescentando o código qjol ele se comporta melhor. O valor como você pode ver na imagem caiu para -1. A trama tem a mesma forma que a imagem anterior aqui, mas valor diferente. Por favor, informe como melhorar isto. Obrigado.
 
#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:


Esse código pode dar valores, mas não dá valores corretos.

Por favor, veja meus cargos anteriores


Olá GumRai,

Por favor, informe como podemos melhorar isso da melhor maneira possível. Obrigado.

 
Zaldy:


Olá GumRai,

Por favor, informe como podemos melhorar isso da melhor maneira possível. Obrigado.


Parece que você já implementou minhas sugestões.

A linha indi cai para zero porque o buffer[0] não é calculado no código. Você tem que decidir se quer que este valor comece em 0 e aumente conforme o dia passa ou talvez apenas faça buffer[0] == buffer[1], o que o faria parecer mais arrumado.

 
Obrigado WHRoeder, qjol e GumRai pela grande ajuda na codificação do meu indicador.
 
GumRai:


Parece que você já implementou minhas sugestões.

A linha indi cai para zero porque o buffer[0] não é calculado no código. Você tem que decidir se quer que este valor comece em 0 e aumente à medida que o dia passa ou talvez apenas faça buffer[0] == buffer[1], o que o faria parecer mais arrumado.


Olá GumRai, como posso codificar para começar em 0 e aumentar à medida que o dia avança? Por favor, ajude-me. Obrigado.
 
Zaldy:

Olá GumRai, como posso codificar para começar em 0 e aumentar à medida que o dia avança? Por favor, ajude-me. Obrigado.


Eu fiz algumas mudanças em seu código



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

Isto deve fazer o que você quer

Como é, não dará um valor para hoje

Se você fizer a mudança como no texto destacado, ela deverá então incluir um valor para hoje que começará em 0 e aumentará conforme o progresso do dia

 

Por que a trama está incompleta aqui. Ele não está sendo preenchido antes de janeiro de 2014. Por favor, informe o problema. Este gráfico foi feito usando o código WHRoeder, mas mesmo o proposto por GumRai também dá a mesma trama descontinuada.

 
porque você não tem dados M1 antes dessa data
Razão: