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

 
 
Olá WHRoeder, consegui compilar o indicador e anexei aqui a imagem do gráfico. A linha indicadora em vermelho forma uma linha reta no topo e caiu no Bar0. Anexei aqui os últimos códigos, gentilmente recomendo onde melhorar o código para que o indicador trace os valores de criss-crossing M1. Um grande obrigado de antemão.
#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

 
double Buf_0[];             // 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_DOT,1);// 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(NULL, PERIOD_D1, Time[iCht]);
      double   openD1 = iOpen(NULL, PERIOD_D1, iD1);
      int      iM1Beg = iBarShift(NULL, PERIOD_M1, Time[iCht]),
               iM1End = -1;
      if(iCht > 0) iM1End = iBarShift(NULL, PERIOD_M1, Time[iCht-1]);
      for(Buf_0[i] = 0; iM1Beg > iM1End; iM1Beg--){
         double hM1 = iHigh(NULL, PERIOD_M1, iM1Beg),
                lM1 =  iLow(NULL, 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);                          // Exit the special funct. start()
  }
//--------------------------------------------------------------------
 
 
Zaldy: uma linha reta no topo e largada no Bar0.
Você tem a história da M1?
 
WHRoeder:
Você tem a história da M1?


Sim, eu tenho.
 
#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

 
double Buf_0[];             // 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_DOT,1);// 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(NULL, PERIOD_D1, Time[iCht]);
      double   openD1 = iOpen(NULL, PERIOD_D1, iD1);
      int      iM1Beg = iBarShift(NULL, PERIOD_M1, Time[iCht]),
               iM1End = -1;
      if(iCht > 0) iM1End = iBarShift(NULL, PERIOD_M1, Time[iCht-1]);
      for(Buf_0[i] = 0; iM1Beg > iM1End; iM1Beg--){
         double hM1 = iHigh(NULL, PERIOD_M1, iM1Beg),
                lM1 =  iLow(NULL, 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);                          // Exit the special funct. start()
  }
//--------------------------------------------------------------------
 

A linha de código em destaque só dará o turno correto se o índio estiver anexado ao gráfico diário.

Como eu já disse em meu posto anterior

"Portanto, você precisa do valor de data/hora para aabertura da vela D1. Você pode fazer isso? "

 
GumRai:

A linha de código em destaque só dará o turno correto se o índio estiver anexado ao gráfico diário.

Como eu já disse em meu posto anterior

"Portanto, você precisa do valor de data/hora para a abertura da vela D1. Você pode fazer isso? "


Oi GumRai, eu tentei muitas vezes, mas não consegui compilá-lo, está além do meu entendimento. O melhor é que se alguém puder me mostrar como vou aprender com isso, notei que aprendo rapidamente se houver exemplos. Neste momento o indicador está contando as barras M1 dentro da Barra1 que cruzam o preço Open[1]. Entretanto, a contagem pára a partir daí e não avança para completar o gráfico. Tentei ligar o indicador a um EA, mas nem mesmo o EA pode enviar o sinal quando voltava a testar. Por favor, mostre alguns códigos que irão completar este indicador para sempre. Obrigado.
 
Buf_0[iCht] = EMPTY;
 
Zaldy:

Oi GumRai, eu tentei muitas vezes, mas não consegui compilá-lo, está além do meu entendimento. O melhor é que se alguém puder me mostrar como vou aprender com isso, notei que aprendo rapidamente se houver exemplos. Neste momento o indicador está contando as barras M1 dentro da Barra1 que cruzam o preço Open[1]. Entretanto, a contagem pára a partir daí e não avança para completar o gráfico. Tentei ligar o indicador a um EA, mas nem mesmo o EA pode enviar o sinal quando voltava a testar. Por favor, mostre alguns códigos que irão completar este indicador para sempre. Obrigado.


Não compilado ou testado, mas pode ajudá-lo

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


Consegui inserir Buf_0[iCht] = VAZIO; no código WHRoeder e de alguma forma o indicador funcionou. Por favor, verifique a imagem e os últimos códigos compilados. No entanto, quando o liguei ao meu EA, ele continuou carregando-o e descarregando-o como se fosse um bêbado vomitando leite. Os outros indicadores ligados ao mesmo EA funcionaram bem. Esta é a mensagem que recebi:

2014.02.25 17:17:08.806 2014.01.02 07:48 Indicador personalizado MamaMaryII EURPLN,Daily: removido

2014.02.25 17:17:08.799 2014.01.02 07:48 Indicador personalizado MamaMaryII EURPLN,Daily: carregado com sucesso

2014.02.25 17:17:08.794 2014.01.02 07:48 Indicador personalizado MamaMaryII EURPLN,Daily: removido

2014.02.25 17:17:08.787 2014.01.02 07:48 Indicador personalizado MamaMaryII EURPLN,Daily: carregado com sucesso

2014.02.25 17:17:08.783 2014.01.02 07:48 Indicador personalizado MamaMaryII EURPLN,Daily: removido

2014.02.25 17:17:08.774 2014.01.02 07:48 Indicador personalizado MamaMaryII EURPLN,Daily: carregado com sucesso

2014.02.25 17:17:08.768 2014.01.02 07:48 Indicador personalizado MamaMaryII EURPLN,Daily: removido

Por favor, me avise o que deu errado. Obrigado. Indicador personalizado anexado em um gráfico
 
#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(NULL, PERIOD_D1, Time[iCht]);
      double   openD1 = iOpen(NULL, PERIOD_D1, iD1);
      int      iM1Beg = iBarShift(NULL, PERIOD_M1, Time[iCht]),
               iM1End = -1;
      if(iCht > 0) iM1End = iBarShift(NULL, PERIOD_M1, Time[iCht-1]);
   Buf_0[iCht] = EMPTY;  //  <<<<<<<<<<<< This is the magic code that gjol inserted and it worked.    
      for(Buf_0[i] = 0; iM1Beg > iM1End; iM1Beg--){
         double hM1 = iHigh(NULL, PERIOD_M1, iM1Beg),
                lM1 =  iLow(NULL, PERIOD_M1, iM1Beg);
// count Bars of M1 Period that crisscross Open price of D1 Period 
        if( hM1 >= openD1 && openD1 >= lM1) Buf_0[iCht]++; 
       // Buf_1[iCht]= Multiplier*Buf_0[iCht];
     }
  }   
//--------------------------------------------------------------------
   return(0);// 
  }
//--------------------------------------------------------------------
Razão: