Indicatore per contare le barre del periodo M1 che incrociano il prezzo aperto del periodo D1 - pagina 3

 
Zaldy:


Quel codice può dare dei valori, ma non dà valori corretti.

Si prega di vedere i miei post precedenti

 
GumRai:


Quel codice può dare dei valori, ma non dà valori corretti.

Si prega di vedere i miei post precedenti

Ciao Gumrai, ho compilato il tuo codice più il codice magico Qjol che ho allegato qui. Senza il codice qjol la forma del grafico è come un numero 7 ma aggiungendo il codice qjol si comporta meglio. Il valore come puoi vedere nell'immagine è sceso a -1. La trama ha la stessa forma dell'immagine precedente ma un valore diverso. Per favore consigliate come migliorare questo. Grazie.
 
#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:


Quel codice può dare valori, ma non dà valori corretti.

Si prega di vedere i miei post precedenti


Ciao GumRai,

Si prega di consigliare il modo migliore per migliorare questo. Grazie.

 
Zaldy:


Ciao GumRai,

Si prega di consigliare il modo migliore per migliorare questo. Grazie.


Sembra che tu abbia già implementato i miei suggerimenti.

La linea indiana cade a zero perché il buffer[0] non è calcolato nel codice. Devi decidere se vuoi che questo valore parta da 0 e aumenti man mano che il giorno va avanti o forse solo fare in modo che buffer[0] == buffer[1], il che lo farebbe sembrare più ordinato.

 
Grazie a WHRoeder, qjol e GumRai per il grande aiuto nella codifica del mio indicatore.
 
GumRai:


Sembra che tu abbia già implementato i miei suggerimenti.

La linea indiana cade a zero perché il buffer[0] non è calcolato nel codice. Dovete decidere se volete che questo valore inizi a 0 e aumenti man mano che il giorno va avanti o forse semplicemente fare in modo che buffer[0] == buffer[1], il che lo farebbe sembrare più ordinato.


Ciao GumRai, Come posso codificare per iniziare da 0 e aumentare man mano che il giorno avanza? Per favore aiuta. Grazie.
 
Zaldy:

Ciao GumRai, come posso codificare per iniziare da 0 e aumentare man mano che il giorno avanza? Per favore aiuta. Grazie.


Ho fatto alcune modifiche al tuo codice



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

Questo dovrebbe fare quello che vuoi

Così com'è non darà un valore per oggi

Se fai la modifica come nel testo evidenziato, dovrebbe includere un valore per oggi che partirà da 0 e aumenterà con l'avanzare del giorno

 

Perché la trama è incompleta qui. Non si sta riempiendo prima di gennaio 2014. Si prega di consigliare il problema. Questo grafico è stato fatto usando il codice WHRoeder ma anche quello proposto da GumRai dà la stessa trama interrotta.

 
perché non hai dati M1 prima di quella data