Function returning number of Bars for a specified TF

 

Hello!

 Is there any function that returns the number of bars on a chart for a specified TimeFrame? I mean, I dont need the Bars variable which returns the number of bars on a current chart. I need to pass 1440 for example and obtain the number of bars for a D1 chart.

 

Thanks a lot 

 
mkheidzedavid:

Hello!

 Is there any function that returns the number of bars on a chart for a specified TimeFrame? I mean, I dont need the Bars variable which returns the number of bars on a current chart. I need to pass 1440 for example and obtain the number of bars for a D1 chart.

Why ?  there may be a better way to do  what you need than using iBars()
 
Thanks. That's what I needed.
 
RaptorUK:
Why ?  there may be a better way to do  what you need than using iBars()



And one more question please. Is there a function that returns the amount left on the deposit?
 
mkheidzedavid:


And one more question please. Is there a function that returns the amount left on the deposit?
Perhaps you could answer my question first ?
 
mkheidzedavid: And one more question please. Is there a function that returns the amount left on the deposit?
Perhaps you should RTFM. learn to code it, instead of asking such simple questions that prove you haven't. AccountBalance - MQL4 Documentation
 
RaptorUK:
Perhaps you could answer my question first ?


Because I have written an indicator that calculates some values based on the TimeFrame one unit less than the current TF. For example, if Im on a D1 chart, it calculates the results for H4. So perhaps I need to pass Period_H4 in iBars()
 
mkheidzedavid:

Because I have written an indicator that calculates some values based on the TimeFrame one unit less than the current TF. For example, if Im on a D1 chart, it calculates the results for H4. So perhaps I need to pass Period_H4 in iBars()
That doesn't explain why you need the number of Bars for a different timeframe . ..  but never mind.
 
RaptorUK:
That doesn't explain why you need the number of Bars for a different timeframe . ..  but never mind.

I have such an indicator here which should be computed for 1 unit less TF than current chart TF.

 

//+------------------------------------------------------------------+
//|                                                        GMACD.mq4 |
//|                                    Copyright 2012, Guriev Invest |
//|                                   http://www.gurievinvest.org.ua |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, Guriev Invest"
#property link      "http://www.gurievinvest.org.ua"

#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Red
#property indicator_color4 Green
#property indicator_style2 STYLE_DOT
#property indicator_width3 3
#property indicator_width4 3

//=====Ïàðàìåòðû èíäèêàòîðà=====
extern int FastMA    = 24;
extern int SlowMA    = 72;
extern int SignalMA  = 24;

//=====Áóôåðû èíäèêàòîðà=====
double MacdBufferRed[];
double MacdBufferGreen[];
double SignalBuffer[];
double LineBuffer[];
//+------------------------------------------------------------------+
//| Èíèöèàëèçàöèÿ                                                    |
//+------------------------------------------------------------------+
int init()
  {
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_HISTOGRAM);
   SetIndexStyle(3,DRAW_HISTOGRAM);
   SetIndexDrawBegin(0,SlowMA);
   SetIndexDrawBegin(1,SlowMA+SignalMA);
   SetIndexDrawBegin(2,SlowMA+SignalMA);
   SetIndexDrawBegin(3,SlowMA+SignalMA);
   IndicatorDigits(Digits+1);
   
   SetIndexBuffer(0,LineBuffer);
   SetIndexBuffer(1,SignalBuffer);
   SetIndexBuffer(2,MacdBufferRed);
   SetIndexBuffer(3,MacdBufferGreen);
   
   IndicatorShortName("MACD("+FastMA+","+SlowMA+","+SignalMA+")");
   SetIndexLabel(0,"Line");
   SetIndexLabel(1,"Signal");
   SetIndexLabel(2,"MACD");
   SetIndexLabel(3,"MACD");
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   double volFirst   = 0;
   double volSecond  = 0;
   int counted_bars=IndicatorCounted();
   //=====Ïîñëåäíèé áàð áóäåò ïåðåñ÷èòàí
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   //=====Ïîäñ÷åò ïåðâîé ñðåäíåé
   for(int i=0; i<limit; i++)
      LineBuffer[i]=iMA(NULL,0,FastMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowMA,0,MODE_EMA,PRICE_CLOSE,i);
   
   
   for(i=0; i<limit; i++)
   {
      MacdBufferRed[i]  = 0.0;
      MacdBufferGreen[i]= 0.0;
            
      SignalBuffer[i]   = iMAOnArray(LineBuffer,Bars,SignalMA,0,MODE_SMA,i);
      volFirst          = LineBuffer[i]-SignalBuffer[i];
      volSecond         = LineBuffer[i-1]-SignalBuffer[i-1];
      if(volFirst>volSecond) MacdBufferRed[i] = volFirst;
      else MacdBufferGreen[i] = volFirst;
   }  
   
   return (0);
  }
//+------------------------------------------------------------------+
 
mkheidzedavid: I have such an indicator here which should be computed for 1 unit less TF than current chart TF.
What does the indicator code have to do with your getting the values via iCustom? What is the second argument to iCustom?
 
Man I have created a third indicator which requires the values from this indicator and extracts them via 4 of the buffers of GMACD indicator shown above. This indicator uses the function Bars inside which gives wrong result because if Im on a D1 chart I need GMACD to be calculated from H4 TF and now it works on "CURRENT" chart so returns the number of bars via Bars variable for D1 (while I need H4). 
Reason: