Why do "prices" in OnCalculate() show different values?

 
As you can see in the code, I put the high prices into an array and printed it. But there are differences between the output prices and the prices I see in the parity. This applies not only to "high", but also to others.

I can't understand why?


#property copyright "Copyright 2022, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window

#property indicator_buffers 1
/*
#property indicator_plots 1

#property indicator_label1  "Up"
#property indicator_type1   DRAW_ARROW
#property indicator_color1  clrBlue
*/
double Up[];
input int Limit;

int OnInit()
  {
   SetIndexBuffer(0, Up, INDICATOR_DATA);

   return(INIT_SUCCEEDED);
  }

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
  
   for(int i = 0; i < Limit; i++)
     {
         Up[i] = high[i];
         Print(i,".ELEMENT: ",Up[i]);            
     }
   
   return(rates_total);
}
 
guga19:
As you can see in the code, I put the high prices into an array and printed it. But there are differences between the output prices and the prices I see in the parity. This applies not only to "high", but also to others.

I can't understand why?


Use ArraySetAsSeries(high,true)

Or

for(int i = rates_total-1 ; i < rates_total-1-Limit; --i)
 

Thanks.

İt worked.

I thought the 0th element of the array started from the right of the graph.

 
guga19 #: I thought the 0th element of the array started from the right of the graph.

Perhaps you should read the manual. Event Handling Functions - Functions - Language Basics - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
   How To Ask Questions The Smart Way. (2004)
      How To Interpret Answers.
         RTFM and STFW: How To Tell You've Seriously Screwed Up.

To determine the indexing direction of time[], open[], high[], low[], close[], tick_volume[], volume[] and spread[], call ArrayGetAsSeries(). In order not to depend on default values, you should unconditionally call the ArraySetAsSeries() function for those arrays, which are expected to work with.
 
William Roeder #:

Perhaps you should read the manual. Event Handling Functions - Functions - Language Basics - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
   How To Ask Questions The Smart Way. (2004)
      How To Interpret Answers.
         RTFM and STFW: How To Tell You've Seriously Screwed Up.

Yes I have read. For some reason, I remembered the information that indexing starts from the right, since it says "defult values" in the article.

I've been messing around with MQL for the past 3 days for my needs. I guess I'm looking for convenience here, as in C# and Python.

But anyway, thanks for your interest.
Reason: