get the total number of indicator buffers used

 

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,

 

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);
 
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.

 
Print(indicator_buffers);
 
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.
 
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);
     }
 
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.
 
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...
 
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

 
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;
   :
Reason: