Accessing different buffers for same custom indicator

 

I'm working with an external indicator and access to different buffers is needed.

For example, a Bollinger-Bands-like indicator has three buffers ( one for the central line, two for the external ones ).

How to access those data? It seems it is not possible just using iCustom and CopyBuffer.

Thank you

 
Marco Strazzeri:

I'm working with an external indicator and access to different buffers is needed.

For example, a Bollinger-Bands-like indicator has three buffers ( one for the central line, two for the external ones ).

How to access those data? It seems it is not possible just using iCustom and CopyBuffer.

Thank you

In copybuffer choose the buffer

 
First use iCustom, then CopyBuffer. Exactly in that order. 
 

That's fine, thank you.

It seems what i've implemented has something wrong, since i have tried to get data from two different indicators and i'm not getting correct values.

Here is the compilable code. What i'm trying to do here is just to get the current values of the two indicators inside the OnInit function. Those indicators have many buffers: i'm trying to get all the current values of them but i'm getting wrong values, some of them are nonsense. Also, the atr indicator doesn't have 13 buffers but the code still gives me "reasonable", but wrong, values.


input int magic_number=4000;
input double lotto=0.01;
input int murray_period=64;
input int murray_stepback=0;
input int murrey_lvl_res=0;
input int murrey_lvl_sup=0;
input int murrey_tolleranza_ticks=100;
input int atr_period=18;
input double atr_mult_factor1=1.6;
input double atr_mult_factor2=3.2;
input double atr_mult_factor3=4.8;
input int atr_smoothing=0;
input int atr_smoothing_depth=100;
input int atr_smoothing_param=15;
input int atr_price_constant=0;
input int atr_horiz_shift=0;
input int atr_vert_shift=0;
input int atr_channel_lvl=1;
input int stop_loss_ticks=100;
input int take_profit_ticks=100;






CPositionInfo cpi;
COrderInfo coi;
CTrade cTrade;

int atr_handle,murrey_handle;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{

   cTrade.SetExpertMagicNumber(magic_number);
   atr_handle=iCustom(NULL,0,"murrey_math_mt5",murray_period,murray_stepback);
   murrey_handle=iCustom(NULL,0,"atr_channels",atr_period,atr_mult_factor1,atr_mult_factor2,atr_mult_factor3,atr_smoothing,atr_smoothing_depth,atr_smoothing_param,atr_price_constant,atr_horiz_shift,atr_vert_shift);
   
   Print("murrey handle: "+murrey_handle+" atr handle: "+atr_handle);
   for(int i=0;i<13;i++)
      Print("murrey "+i+": "+murreyAt(i));
      
   for(int i=0;i<13;i++)
      Print("atr "+i+": "+atrAt(i));  
       
   return(INIT_SUCCEEDED);
}

double murreyAt(int index)
{
   double vals[];
   CopyBuffer(murrey_handle,index,iTime(Symbol(),Period(),0),1,vals);
   return vals[0];
}

double atrAt(int index)
{
   double vals[];
   CopyBuffer(atr_handle,index,0,1,vals);
   return vals[0]; 
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

  }
//+------------------------------------------------------------------+
 
Get the handles in OnInit. Get the values in OnTick, not in OnInit.
 
William Roeder:
Get the handles in OnInit. Get the values in OnTick, not in OnInit.

Thanks, i moved this inside the OnTick


for(int i=0;i<13;i++)
      Print("atr "+i+": "+atrAt(i)); 


but i get wrong values too

 

There should be something wrong with the current implementation.


Isn't it supposed to get different values of one buffer for the last 10 candles?

This code returns the same values for all the printings, not possible for a ATR channels indicator which changes every candle


double atrAt(int index)
{
   double vals[];
   CopyBuffer(atr_handle,index,0,10,vals);
   for(int i=0;i<10;i++)
      Print("vals "+i+": "+vals[i]);
   return vals[0]; 
}
 
Marco Strazzeri:

There should be something wrong with the current implementation.


Isn't it supposed to get different values of one buffer for the last 10 candles?

This code returns the same values for all the printings, not possible for a ATR channels indicator which changes every candle


Second parameter of CopyBuffer() is the buffer number. You are using the "index" in a wrong way
 
Mladen Rakic:
Second parameter of CopyBuffer() is the buffer number. You are using the "index" in a wrong way

Thanks for your time Miaden;

actually i wanted to get values from the buffer number (index), starting from the current candle, getting the last 10 values. Can you confirm the code actually doesn't correspond to this description?

 
Marco Strazzeri:

Thanks for your time Miaden;

actually i wanted to get values from the buffer number (index), starting from the current candle, getting the last 10 values. Can you confirm the code actually doesn't correspond to this description?

No idea how that indicator (the "murrey_math_mt5") works, but if that looks like some of the widely spread murray math indicator, it is using objects, not buffers.
 
Mladen Rakic:
No idea how that indicator (the "murrey_math_mt5") works, but if that looks like some of the widely spread murray math indicator, it is using objects, not buffers.

Hmm i have wide experience in MT4, like on MT4 i can see in the navigator window the various buffers of both indicators. Plus this, the problem is seen in both indicators, murrey and atr channel

Reason: