My code doesn't show on chart? Please help

 

Hi,

I recently returned to using some of my old MT4 charts and modifying an old indicator. The original works perfectly well, however, when I modified the timeframe to make it calculate and draw lines for 4H candles, it doesn't work. 

There is no error message when the indicator was compiled, but it simply doesn't show up on charts. Please could any coding masters help me check it out?

(I can't seem to attach the indicator here, so I copied the code in the message. Sorry for any inconvenience! And thanks in advance!!!)

Edit -- Mounir Cheikh, I followed your suggestion, and it now works. Thank you so very much. You are a star!

And to the other two posters: sorry for having posted a long block of code in the wrong format. Now I have removed it. Thanks again for your time and suggestions. I may need to ask more coding questions in the future. 


            
 
Alex:

Hi,

I recently returned to using some of my old MT4 charts and modifying an old indicator. The original works perfectly well, however, when I modified the timeframe to make it calculate and draw lines for 4H candles, it doesn't work. 

There is no error message when the indicator was compiled, but it simply doesn't show up on charts. Please could any coding masters help me check it out?

(I can't seem to attach the indicator here, so I copied the code in the message. Sorry for any inconvenience! And thanks in advance!!!)


#define R3_NAME "Daily R3"

#define R2_NAME "Daily R2"

#define R1_NAME "Daily R1"

#define PIVOT_NAME "Daily PP"

#define S1_NAME "Daily S1"

#define S2_NAME "Daily S2"

#define S3_NAME "Daily S3"


//#define FONT "Tahoma"


#define R3_COL Crimson

#define R2_COL Crimson

#define R1_COL Crimson

#define PIVOT_COL Gray

#define S1_COL Green

#define S2_COL Green

#define S3_COL Green


#property indicator_chart_window

#property indicator_buffers 7

#property indicator_color1 R3_COL

#property indicator_color3 R1_COL

#property indicator_color4 PIVOT_COL

#property indicator_color5 S1_COL

#property indicator_color7 S3_COL


// Input(s)

extern string Note1 = "H4 =1";

extern int TimeFrame = 1;

extern int H4Period = 3;

extern string Note2 = "Other Settings";

extern double SR1 = 0.5;

extern double SR3 = 0.618;

extern int Limit = 2500;

extern int ShiftHrs = 0;   // Pivot day shift

                           // positive value moves pivot day earlier


// Buffers for levels

double Res3[], Res2[], Res1[], Pivot[], Sup1[], Sup2[], Sup3[];


double PastHigh[5000], PastLow[5000], PastClose[5000], Range[5000];



//--------------------------------------------------------------------

// Initialization

//--------------------------------------------------------------------

int init()

{

   // Attach indicator arrays to buffers

   SetIndexBuffer( 0, Res3);

   SetIndexBuffer( 1, Res2);

   SetIndexBuffer( 2, Res1);

   SetIndexBuffer( 3, Pivot);

   SetIndexBuffer( 4, Sup1);

   SetIndexBuffer( 5, Sup2);

   SetIndexBuffer( 6, Sup3);


   // Set styles

   SetIndexStyle( 0, DRAW_LINE);

   SetIndexStyle( 1, DRAW_LINE);

   SetIndexStyle( 2, DRAW_LINE);

   SetIndexStyle( 3, DRAW_LINE);

   SetIndexStyle( 4, DRAW_LINE);

   SetIndexStyle( 5, DRAW_LINE);

   SetIndexStyle( 6, DRAW_LINE);


   // Set empty values

   SetIndexEmptyValue( 0, EMPTY_VALUE );

   SetIndexEmptyValue( 1, EMPTY_VALUE );

   SetIndexEmptyValue( 2, EMPTY_VALUE );

   SetIndexEmptyValue( 3, EMPTY_VALUE );

   SetIndexEmptyValue( 4, EMPTY_VALUE );

   SetIndexEmptyValue( 5, EMPTY_VALUE );

   SetIndexEmptyValue( 6, EMPTY_VALUE );


   // Set labels

   SetIndexLabel( 0, R3_NAME );

   SetIndexLabel( 1, R2_NAME );

   SetIndexLabel( 2, R1_NAME );

   SetIndexLabel( 3, PIVOT_NAME );

   SetIndexLabel( 4, S1_NAME );

   SetIndexLabel( 5, S2_NAME );

   SetIndexLabel( 6, S3_NAME );


   

   return(0);

}


//--------------------------------------------------------------------

//| De-initialization                                                |

//--------------------------------------------------------------------

int deinit()

{

   // Remove texts

   /*ObjectDelete( R3_NAME );

   ObjectDelete( R2_NAME );

   ObjectDelete( R1_NAME );

   ObjectDelete( PIVOT_NAME );

   ObjectDelete( S1_NAME );

   ObjectDelete( S2_NAME );

   ObjectDelete( S3_NAME );*/


   return(0);

}


//--------------------------------------------------------------------

//| Main iteration                                                   |

//--------------------------------------------------------------------

int start()

{

   

   int counted_bars=IndicatorCounted();


   int limit, i;

//---- indicator calculation

if (counted_bars==0)


   if(counted_bars<0) return(-1);


   limit=(Bars-counted_bars)-1;



for (i=limit; i>=0;i--)

   

  

   double CandleNum[5000];


   

   {

      

      // If the pivot day changes...

      if( TimeFrame == 1 )

      {

         // Determine High & Low for the previous Period

         CandleNum[i] = iBarShift( NULL, PERIOD_H4, Time[i], false);

         PastHigh[i] = iHigh(NULL, PERIOD_H4, iHighest( NULL, PERIOD_H4, MODE_HIGH, H4Period, CandleNum[i]+1 ) ); // Pivot Day high

         PastLow[i] = iLow(NULL, PERIOD_H4, iLowest( NULL, PERIOD_H4, MODE_LOW, H4Period, CandleNum[i]+1 ) );     // Pivot Day low

         PastClose[i] = iClose( NULL, PERIOD_H4, CandleNum[i]+1 ); 

         Comment("");

         // Pivot calculations

         Pivot[i] = ( PastHigh[i] + PastLow[i] + PastClose[i] ) / 3;    // Pivot point

         Range[i] = PastHigh[i] - PastLow[i];

         Res1[i] = Pivot[i] + SR1*Range[i];//2 * Pivot[i] - PastLow[i];                     // R1

         

         Res3[i] = Pivot[i] + SR3*Range[i];//Res1[i] + Range[i];                            // R3

         Sup1[i] = Pivot[i] - SR1*Range[i];//2 * Pivot[i] - PastHigh[i];                    // S1

                             // S2

         Sup3[i] = Pivot[i] - SR3*Range[i];//Sup1[i] - Range[i];                            // S3

         

         if(Res1[i]!=Res1[i+1]) Res1[i+1] = EMPTY_VALUE;

         if(Res2[i]!=Res2[i+1]) Res2[i+1] = EMPTY_VALUE;

         if(Res3[i]!=Res3[i+1]) Res3[i+1] = EMPTY_VALUE;

         if(Sup1[i]!=Sup1[i+1]) Sup1[i+1] = EMPTY_VALUE;

         if(Sup2[i]!=Sup2[i+1]) Sup2[i+1] = EMPTY_VALUE;

         if(Sup3[i]!=Sup3[i+1]) Sup3[i+1] = EMPTY_VALUE;

      }

      

      


   }


   return(0);

}


//--------------------------------------------------------------------

press Alt+S and paste the code in the window that appears.  

 
  1. When you post code please use the CODE button (Alt-S)! (For large amounts of code, attach it.) Please edit your post.
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  2. You have no loop
    for (i=limit; i>=0;i--)
       double CandleNum[5000];

 

Hi,

I think that:

double CandleNum[5000]

need to be before:

for (i=limit; i>=0;i--)
Reason: