Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1490

 
Alexey Viktorov:
Where is it written that there can't be a history sub-loading along with the new bar?

Where is it written that the history should be tracked?
While it is being loaded, the indicator calculations can be disregarded - because there is no complete history (bars can appear anywhere).
Hence, the conclusion - only after all of the bars have been built can there be a new bar.
Otherwise all the bars are "old".

 
m-r LSV:

Didn't help :(

show the code.

 
Taras Slobodyanik:

you need to see what you've built.

Taras!!! The man is asking about MQL5!!! And MT5 is indexed from left to right... It turns out that you should not count 1 bar, but rates_total-2

 
Taras Slobodyanik:

Where is it written that you have to monitor the history loading?
While it is being loaded, the indicator calculations can be disregarded - because there is no complete history.
Hence the conclusion - only after all the bars have been built can there be a new bar.
Otherwise all of the bars are "old".

Please advise how to do it with history.
The thing is, it is planned, to check something on the history of course.
I have some observations and would like to use buffers for arrows.

But that will come later.

 
Taras Slobodyanik:

show the code.

//+------------------------------------------------------------------+
//|                                                    test.mq5 |
//|                                  Copyright 2021, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window

#property indicator_buffers 2
#property indicator_plots   2

#property indicator_label1  "Signal UP"
#property indicator_type1   DRAW_ARROW
#property indicator_color1  clrLime
#property indicator_style1  STYLE_SOLID
#property indicator_width1  2

#property indicator_label2  "Signal DN"
#property indicator_type2   DRAW_ARROW
#property indicator_color2  clrRed
#property indicator_style2  STYLE_SOLID
#property indicator_width2  2

double up[];
double dn[];

datetime fin=0, last=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
    IndicatorSetString(INDICATOR_SHORTNAME, "Prototype");
    
   SetIndexBuffer(0,up,INDICATOR_DATA);
   PlotIndexSetInteger(0,PLOT_ARROW,233);
    
   SetIndexBuffer(1,dn,INDICATOR_DATA);
   PlotIndexSetInteger(1,PLOT_ARROW,234);
   
   
  
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
   {
   fin=iTime(Symbol(), PERIOD_M1 ,0);
   if(last==fin) return(rates_total);
   last=fin;
   
   if(rates_total - prev_calculated == 1)
      {
      //Print("Новый бар");
      if(open[1] > close[1])
           {
           Print("Dn");
           }
      else if(open[1] < close[1])
           {
           Print("Up");
           }
      }

return(rates_total);
}
 
Alexey Viktorov:

Taras!!! The man is asking about MQL5!!! In MT5, indexing is from left to right... It turns out that rates_total-2, and not 1 bar must be counted.

No, no, prev_calculated and rates_total do not depend on it.

 
Taras Slobodyanik:

no-no, prev_calculated and rates_total do not depend on this

What is the relationship of prev_calculated and rates_total to the fact that you propose to read the opening and closing of the first bar on the left?

 
Alexey Viktorov:

What is the relation of prev_calculated and rates_total to the fact that you propose to read the opening and closing of the first bar on the left?

i am not suggesting to read the closing bar on the left, this is not my code)

mine only

if(rates_total - prev_calculated == 1)
 
m-r LSV:

Didn't help :(

Yes, you either need to change the direction of the arrays or take the rates_total-2 index instead of 1

{
   
   ArraySetAsSeries(open,true);
   ArraySetAsSeries(high,true);
   ArraySetAsSeries(low,true);
   ArraySetAsSeries(close,true);
   ArraySetAsSeries(time,true);
   
   if(rates_total - prev_calculated > 1)
      {
      Print("Загрузка истории");
      return(rates_total);
      }
   
   if(rates_total - prev_calculated == 1)
      {
      //Print("Новый бар");
      if(open[1] > close[1])
           {
           Print("Dn");
           }
      else if(open[1] < close[1])
           {
           Print("Up");
           }
      }

return(rates_total);
}


 
Taras Slobodyanik:

I'm not suggesting reading the bar close on the left, that's not my code)

It's just mine.

It's unseemly to lie so blatantly. You delete your post and blame your illiteracy on someone else. Liar.

Reason: