Why am I getting values of bar from Jan 1, 1970?

 

Hi guys!


I'm a newbie to coding. Just getting started. This is the second program I now code. 


Here is my current issue with the below coding:

1/ Why does the system give me the high of the candle from 1970.01.01 and this twice (see print statements in terminal)

2/ Why my high_price_array[] seems to be of a size of 4 (see print statements) despite having a declared size of only 3 (line 22)?


What's going on here? 

Thx for your input/help. 


-------------------------------------------------------------------------------------------



#property indicator_separate_window

#property indicator_buffers 2

#property indicator_color1 Green

#property indicator_color2 Black

#property indicator_width1 2

#property indicator_width2 2





//---------------------------------------------------------------------------------------------|

//                                      GLOBAL VARIABLES                                               |

//---------------------------------------------------------------------------------------------|





extern   int   Bar_History       =  10;





double         high_price_array[3], low_price_array[3];

datetime       price_array_time[3];



double         Buf_High[], Buf_Low[]; 





//---------------------------------------------------------------------------------------------|

//                                     SPECIAL FUNCTIONS                                               |

//---------------------------------------------------------------------------------------------|



int init() {



   ArrayInitialize(high_price_array, 0);

   ArrayInitialize(low_price_array, 0);



   SetIndexBuffer(0, Buf_High);

   SetIndexStyle(0, DRAW_HISTOGRAM, 2, Green); 

   SetIndexBuffer(1, Buf_Low);

   SetIndexStyle(1, DRAW_HISTOGRAM, 2, Black); 

   

   IndicatorShortName("Break In Micromarket Structure");

   SetIndexLabel(0, "High");

   SetIndexLabel(1, "Low");



   return(INIT_SUCCEEDED);

   

}



//---------------------------------------------------------------------------------------------|

//                                        START FUNCTION                                                |

//---------------------------------------------------------------------------------------------|



int start() {



   int   counted_bars = IndicatorCounted();

   int   i = Bars - counted_bars - 1;

   int   look_back_candle  =  3; 

   int   highest_high_index = 0;





   if (i > Bar_History - 1) 

      i = Bar_History - 1;

      

   while(i >= 0) {

      

      datetime time = iTime(NULL, 0, i);



      Print("=== Candle Zero === ", TimeToStr(time, TIME_DATE), "  ", TimeToStr(time, TIME_MINUTES), " === Candle Index: ", i);

      

      for (int j = 1 ; j <= look_back_candle ; j++) {

         high_price_array[j] = iHigh(NULL, 0, i+j);

         low_price_array[j] = iLow(NULL, 0, i+j);

         price_array_time[j] = iTime(NULL, 0, i+j);

      }



      for (int k = 0 ; k <= look_back_candle ; k++) {

         Print("Array index ", k, "  ", TimeToStr(price_array_time[k], TIME_DATE), "  ", TimeToStr(price_array_time[k], TIME_MINUTES),

               " - High = ", high_price_array[k]);

      }

      

      highest_high_index = ArrayMaximum(high_price_array, WHOLE_ARRAY, 0);

      Print("Highest High Index = ", highest_high_index);

      

      i--;

   }

   

   return (0);

}   

   

//----------------------------------------------------------------------------------------------|

//                                 USER DEFINED FUNCTIONS                                           |

//----------------------------------------------------------------------------------------------|
Files:
Swings.mq4  4 kb
 
Edward_512:

Hi guys!


I'm a newbie to coding. Just getting started. This is the second program I now code. 


Here is my current issue with the below coding:

1/ Why does the system give me the high of the candle from 1970.01.01 and this twice (see print statements in terminal)

2/ Why my high_price_array[] seems to be of a size of 4 (see print statements) despite having a declared size of only 3 (line 22)?


What's going on here? 

Thx for your input/help. 


It seems you have declared high and low price array static with only three bars but because ArraySetAsSeries is not equal true you don't get the most recent three bars but the oldest three. From 1970.
But in indicators you mostly work with Series = false, then you need rates_total as index of the latest bar.
What was your intention?