Download MetaTrader 5

get the total number of indicator buffers used

To add comments, please log in or register
parham.trader
374
parham.trader  

Hi friends,

I'd like to know how can I get the total number of indicator buffers I've used in my indicator.

thanking in advance,

honest_knave
Moderator
2326
honest_knave  

This isn't a facetious reply... surely you know how many buffers you've used by looking at the code? 

#property  indicator_buffers x
IndicatorBuffers(x);
parham.trader
374
parham.trader  
honest_knave:

This isn't a facetious reply... surely you know how many buffers you've used by looking at the code? 


for sure we can understand from preprocessor and the function you said in your response but I think you may agree with me that in programming it is not a certain procedure to follow ! 

I'm looking for a more convenient solution to the issue.

fxsaber
7651
fxsaber  
Print(indicator_buffers);
whroeder1
15917
whroeder1  
parham.trader: I'm looking for a more convenient solution to the issue.
  1. Just remember it
    #define    VISIBLE_BUFFERS   x
    #property  indicator_buffers VISIBLE_BUFFERS   
    :
    int OnInit(){
       #define TOTAL_BUFFERS (VISIBLE_BUFFERS+y)
       IndicatorBuffers(TOTAL_BUFFERS);
       :
    }
    void OnTick(){
       Print(TOTAL_BUFFERS);
       
  2. The real question is what are you going to do with it? You can't index buffers.



fxsaber:
Print(indicator_buffers);
Nice try, but that only returns the property value not the total buffers, and it' not documented.
parham.trader
374
parham.trader  
whroeder1:
  1. The real question is what are you going to do with it? You can't index buffers.

What do you mean by "You can't index buffers"?! I used a "for" loop like what I'm showing below and it worked properly.

   for(i=1;i<=15;i++)
     {
      SetIndexStyle(i,DRAW_NONE);
     }
whroeder1
15917
whroeder1  
Yes, only in init. You could just as easily use this:
//--- indicator buffers mapping
   int   c=0;
   SetIndexBuffer(c,mama);                                           ++c;
   SetIndexBuffer(c,fama);                                           ++c;
   SetIndexBuffer(c,sl);                                             ++c;
   SetIndexBuffer(c,entry);                                          ++c;
   SetIndexBuffer(c,detrender);        SetIndexEmptyValue(c,0.0);    ++c;
:
   IndicatorBuffers(c);
//---
And not worry about it.
Or do it like everyone else
//--- indicator buffers mapping
   IndicatorBuffers(9);
   SetIndexBuffer(0,mama);                                     
   SetIndexBuffer(1,fama);                                     
   SetIndexBuffer(2,sl);                                       
   SetIndexBuffer(3,entry);                                    
   SetIndexBuffer(4,detrender);        SetIndexEmptyValue(4,0.0);
:
//---
Your way just saved you from cut and paste 15 lines. Big deal.
fxsaber
7651
fxsaber  
https://www.mql5.com/en/blogs/post/680572
MQL's OOP notes: Arrayed indicator buffers based on operators overloading
MQL's OOP notes: Arrayed indicator buffers based on operators overloading
  • 2016.09.16
  • Stanislav Korotky
  • www.mql5.com
From very first moment as I started learning MetaTrader many years ago I was wondering why there are no multidimentional buffers in indicators. Indeed, when you code an indicator with multiple buffers...
parham.trader
374
parham.trader  
whroeder1:
Yes, only in init. You could just as easily use this:
And not worry about it.
Or do it like everyone else
Your way just saved you from cut and paste 15 lines. Big deal.


Thank you so much for the solution! 

Finally you showed me the easiest way to get the total number of used indicator buffers

whroeder1
15917
whroeder1  
parham.trader: Finally you showed me the easiest way to get the total number of used indicator buffers
Unfortunately it doesn't work. You have to call IndicatorBuffers(n) before you can do the rest. Back to the Original solution
#define   VISIBLE_BUFFERS     3
#property indicator_buffers VISIBLE_BUFFERS
#property indicator_color1  Red  
#property indicator_label1  "MAMA"
double   mama[];

#property indicator_color2  White
double fama[]; 
:
#property indicator_color3  Blue
double sl[]
:
double   price[],          range[];
#define EXTRA_BUFFERS   2
:
{
   IndicatorBuffers(VISIBLE_BUFFERS + EXTRA_BUFFERS);          int   c=0;
   SetIndexBuffer(c,mama);                                           ++c;
   SetIndexBuffer(c,fama);                                           ++c;
   SetIndexBuffer(c,sl);                                             ++c;
   SetIndexBuffer(c,price);                                          ++c;
   SetIndexBuffer(c,range);            SetIndexEmptyValue(c,0.0);    ++c;
   :
To add comments, please log in or register