ArraySetAsSeries does not work !!

 

Here I have written some codes to show that  ArraySetAsSeries   function does not have any effect in Arrays!!

any boddy can help me?

why this function has no effect in my metatrader???

result

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
//---- plot Label1
#property indicator_label1  "Label1"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- indicator buffers
double         Label1Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {

   if(!ArrayIsSeries(Label1Buffer))
      Print("Label1Buffer[] is not timeseries");
   //if(ArrayIsDynamic(Label1Buffer))
   //   Print("Label1Buffer is dynamic");
      
   SetIndexBuffer(0,Label1Buffer,INDICATOR_DATA);

   if(ArrayIsSeries(Label1Buffer))
      Print("Label1Buffer[] is timeseries aftert set as buffer");
else
      Print("Label1Buffer[] is NOT timeseries after set as indicator buffer!!!");


   ArraySetAsSeries(Label1Buffer,true);

   if(ArrayIsSeries(Label1Buffer))
      Print("Label1Buffer[] is timeseries after set series");
      else
      Print("Label1Buffer[] is NOT timeseries after set as series!!!");
      

//--- indicator buffers mapping
//---
  }
//+------------------------------------------------------------------+
//| 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[])
  {


//--- ArrayGetAsSeries

   if(ArrayIsSeries(open))
      Print("open[] is timeseries");
   else
      Print("open[] is not timeseries!!!");


   ArraySetAsSeries(open,false);
   if(ArrayIsSeries(open))
      Print("open[] is timeseries after set false");
   else
      Print("open[] is not timeseries  after set false");

//--- return value of prev_calculated for next call
   return(rates_total);
  }
 

Use ArrayGetAsSeries Not ArrayIsSeries:

#property indicator_chart_window 
#property indicator_buffers 1 
#property indicator_plots   1 
//---- plot Label1 
#property indicator_label1  "Label1" 
#property indicator_type1   DRAW_LINE 
#property indicator_color1  clrRed 
#property indicator_style1  STYLE_SOLID 
#property indicator_width1  1 
//--- indicator buffers 
double         Label1Buffer[]; 
//+------------------------------------------------------------------+ 
//| Custom indicator initialization function                         | 
//+------------------------------------------------------------------+ 
void OnInit() 
  { 
//--- indicator buffers mapping 
//--- 
  } 
//+------------------------------------------------------------------+ 
//| 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[]) 
  { 
//--- 
   ArraySetAsSeries(open, true);

   if(ArrayGetAsSeries(open)) 
      Print("open[] is timeseries"); 
   else 
      Print("open[] is not timeseries!!!"); 

   ArraySetAsSeries(open, false);
   
   if(ArrayGetAsSeries(open)) 
      Print("open[] is timeseries"); 
   else 
      Print("open[] is not timeseries!!!"); 


//--- return value of prev_calculated for next call 
   return(rates_total); 
  }
 

ArrayIsSeries: The function checks whether an array is a timeseries.

ArrayGetAsSeries: It checks direction of an array index.


 
Yashar Seyyedin #:

ArrayIsSeries: The function checks whether an array is a timeseries.

ArrayGetAsSeries: It checks direction of an array index.


thank you 

yes it works with ArrayGetAsSeries.

would you please look at my previous topic on ::  https://www.mql5.com/en/forum/465601#comment_53087642

I can not read my custom indicators buffers in my experts in back test !!

despit of my expert advisor that only alert base on last value of indicators  or despide of plotting corectly on the chart.

problem with iCustom
problem with iCustom
  • 2024.04.14
  • Mehrdad Sarrafi
  • www.mql5.com
hi here I have a custom indicator , But when I use it in my expert 's backtest, I only receve maximum one signal...
 
Don't use those functions on buffers in OnInit. The buffers have not yet been created.
Reason: