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

 

Found a strange glitch when drawing on the MT5 chart: arrows instead of low candles are placed in arbitrary places, as if shifted to the chart




#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window

#property strict

#property indicator_buffers 1 
#property indicator_plots   1
 
#property indicator_label1  "Arrows" 
#property indicator_type1   DRAW_ARROW 
#property indicator_color1  clrGreen 
#property indicator_width1  1

double Buf_0[];

int OnInit()
  {

   SetIndexBuffer(0,Buf_0,INDICATOR_DATA);
   PlotIndexSetInteger(0,PLOT_ARROW,233);
   
   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[])
  {
   
   for (int i=0; i<rates_total; i++)
      {
   
      Buf_0[i]=iLow(_Symbol, _Period,i);
      }
   return(rates_total);
  }

 
psyman:

Found a strange glitch when drawing on the MT5 chart: arrows instead of low candles are placed in arbitrary places, as if shifted to the chart




1. The indicator ALREADY has a low array. It must be applied.

2. There is no need to run the visualization at maximum speed.

3. The code is terribly glitchy - because on every tick there is a pass through ALL BARs.

 
Vladimir Karputov:

1. The indicator ALREADY has a low array. Apply it.

2. There is no need to run the visualisation at maximum speed.

3. The code is terribly glitchy - because on every tick there is a pass through ALL BARs.

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[])
  {
   ArrayInitialize(Buf_0,EMPTY_VALUE);

   for (int i=0; i<rates_total; i++)
      {
   
      Buf_0[i]=iLow(_Symbol, _Period,i);
      }
   return(rates_total);
  }
 
Vladimir Karputov:

1. The indicator ALREADY has a low array. Apply it.

2. There is no need to run the visualisation at maximum speed.

3. The code is terribly glitchy - because on every tick there is a pass through ALL the bars.

I didn't post the code here, but wrote the simplest one to simplify the parse.

Tell me more about what's wrong, about maximum speed is not clear.

 
Vitaly Muzichenko:

Vitaly, initialization doesn't work for some reason. I tried writingPlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0); it doesn't work either :(

 
psyman:

I didn't post the code here, but wrote the simplest one to simplify the parse.

Tell me more about what's wrong, the maximum speed is unclear.

Start correcting it one step at a time. For example, fix it first:

The indicator already has a low array. You need to apply it.

 
Buf_0[i]=iLow(_Symbol, _Period,i);

iLow works as series true, Buf_0 is false, low[] is also false. I.e. the 0th element in your case gets rates_total-1 (mirrored)

You need to flip one of them, for example:

Buf_0[i]=iLow(_Symbol, _Period,rates_total-1-i);
 
psyman:

Found a strange glitch when drawing on the MT5 chart: arrows instead of low candles are placed in arbitrary places, as if shifted to the chart



Knowing the riddle about apples at Pinocchio's will definitely help with this problem. I do not remember it in detail, we will wait for someone to retell it without errors.

 
Igor Zakharov:

iLow works as series true, Buf_0 is false, low[] is also false. I.e. the 0th element in your case gets rates_total-1 (mirrored)

You need to flip one of them, for example:

This is an indicator! There are already arrays in OnCalculate.

                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[]

Why should you cram iXXXX functions into an indicator?

 
Vladimir Karputov:

This is an indicator! OnCalculate ALREADY has arrays

Why would you put iXXXXXX functions into an indicator?

How should I know? The questioner used iLow(), it means he needs it. Maybe it is easier to perceive, maybe he plans to address another symbol or timeframe through an input variable (I don't remember, is there a copyrates in fours?)

Added: the question on the five was asked in the quaternary thread. I overlooked it, I repent. But, the answer is still the same.