why arrow does not draw in indicator?

 
Just begin to learn mql5, the following is a simple test, the data is there, why arrow just doesn't draw? 
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
#property indicator_type1   DRAW_ARROW
#property indicator_color1  clrWhite
#property indicator_width1  1

double       extSARBuffer[];

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
   IndicatorSetInteger(INDICATOR_DIGITS,2);
   PlotIndexSetInteger(0,PLOT_ARROW,159);
   SetIndexBuffer(0,extSARBuffer,INDICATOR_DATA);
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
   IndicatorSetString(INDICATOR_SHORTNAME," ");

   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[])
  {

   ArraySetAsSeries(high,true);

   extSARBuffer[1]=high[1];
   Comment(extSARBuffer[1]);

   return(rates_total);
  }
 

Code: always display 'Arrow' on the very RIGHT bar.

//+------------------------------------------------------------------+
//|                                                   High Arrow.mq5 |
//|                              Copyright © 2021, Vladimir Karputov |
//|                      https://www.mql5.com/en/users/barabashkakvn |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2021, Vladimir Karputov"
#property link      "https://www.mql5.com/en/users/barabashkakvn"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot High
#property indicator_label1  "High"
#property indicator_type1   DRAW_ARROW
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- input parameters
input int      Input1=9;
//--- indicator buffers
double         HighBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,HighBuffer,INDICATOR_DATA);
//--- setting a code from the Wingdings charset as the property of PLOT_ARROW
   PlotIndexSetInteger(0,PLOT_ARROW,159);
//---
   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[])
  {
//---
   int limit=prev_calculated-1;
   if(prev_calculated==0)
      limit=0;
   for(int i=limit; i<rates_total; i++)
     {
      if(i==rates_total-1)
         HighBuffer[i]=high[i];
      else
         HighBuffer[i]=0.0;
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

Result:

High Arrow

Files:
 
Vladimir Karputov #:

Code: always display 'Arrow' on the very RIGHT bar.

Result:


Thanks you for your help.

I was wrong, I thought ArraySetAsSeries() will also reverse the array order, into like MT4.

 
joshatt #:

Thanks you for your help.

I was wrong, I thought ArraySetAsSeries() will also reverse the array order, into like MT4.

It does reverse the order, what was missing is an ArraySetAsSereis for extSARBuffer (preferably in OnInit for that case), so your code was drawing the arrow at the 2nd candle on the left end at the high of the 2nd candle on the right end

 
Manuel Alejandro Cercos Perez #:

It does reverse the order, what was missing is an ArraySetAsSereis for extSARBuffer (preferably in OnInit for that case), so your code was drawing the arrow at the 2nd candle on the left end at the high of the 2nd candle on the right end

That explained everything. Thanks a lot, appreciate it.

Reason: