Indicador para contar las barras del periodo M1 que se cruzan con el precio de apertura del periodo D1 - página 2

 
 
Hola WHRoeder, he conseguido compilar el indicador y adjunto aquí la imagen del gráfico. La línea del indicador en rojo forma una línea recta en la parte superior y cayó en Bar0. Adjunto aquí los últimos códigos amablemente aconsejar donde mejorar el código para que el indicador traza los valores de M1 entrecruzados. Muchas gracias de antemano.
#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: una línea recta en la parte superior y cayó en Bar0.
¿Tienes el historial de M1?
 
WHRoeder:
¿Tiene antecedentes de M1?


Sí, lo tengo.
 
#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()
  }
//--------------------------------------------------------------------
 

La línea de código resaltada sólo dará el desplazamiento correcto si el indi está unido al gráfico diario.

Como ya dije en mi post anterior

"Así que necesitas el valor de la fecha para la apertura de la vela D1. ¿Puede hacer esto? "

 
GumRai:

La línea de código resaltada sólo dará el desplazamiento correcto si el indi está unido al gráfico diario.

Como ya dije en mi post anterior

"Así que necesitas el valor de la fecha para la apertura de la vela D1. ¿Puede hacer esto? "


Hola GumRai, lo he intentado muchas veces pero ni siquiera he podido compilarlo, está más allá de mi entendimiento. Lo mejor es que si alguien puede mostrarme cómo entonces aprenderé de ello, he notado que aprendo rápidamente si hay ejemplos. Ahora mismo el indicador cuenta las barras M1 dentro de la Barra1 que se cruzan con el precio Open[1]. Sin embargo el conteo se detiene a partir de ahí y no avanza hasta completar el gráfico. Intenté vincular el indicador a un EA, pero incluso el EA no puede enviar la señal cuando se hace la prueba. Por favor, muestren algunos códigos que completen este indicador para bien. Gracias.
 
Buf_0[iCht] = EMPTY;
 
Zaldy:

Hola GumRai, lo he intentado muchas veces pero ni siquiera he podido compilarlo, está más allá de mi entendimiento. Lo mejor es que si alguien puede mostrarme cómo entonces aprenderé de ello, he notado que aprendo rápidamente si hay ejemplos. Ahora mismo el indicador cuenta las barras M1 dentro de la Barra1 que se cruzan con el precio Open[1]. Sin embargo el conteo se detiene a partir de ahí y no avanza hasta completar el gráfico. Intenté vincular el indicador a un EA, pero incluso el EA no puede enviar la señal cuando se hace la prueba. Por favor, muestren algunos códigos que completen este indicador para bien. Gracias.


No está compilado ni probado, pero puede ayudarte

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:


Me las arreglé para insertar Buf_0[iCht] = EMPTY; en el código WHRoeder y de alguna manera el indicador trabajó. Sin embargo, cuando lo vinculé a mi EA, seguía cargando y descargando como si un borracho vomitara leche. Los otros indicadores vinculados al mismo EA funcionaban bien. Este es el mensaje que recibí:

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

2014.02.25 17:17:08.799 2014.01.02 07:48 Indicador personalizado MamaMaryII EURPLN,Daily: cargado con éxito

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

2014.02.25 17:17:08.787 2014.01.02 07:48 Indicador personalizado MamaMaryII EURPLN,Daily: cargado con éxito

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

2014.02.25 17:17:08.774 2014.01.02 07:48 Indicador personalizado MamaMaryII EURPLN,Daily: cargado con éxito

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

Por favor, dígame qué es lo que ha fallado. Gracias. Indicador personalizado adjunto en un 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);// 
  }
//--------------------------------------------------------------------