Multi Time Frame ( MTF ) indicator

 

Hi. I have created an MFT indicator that for each candlestick in the current time frame, sums the volume of the bearish and bullish candles in the M1 time frame separately and shows it in the diagram. But my problem is that the graph is only shown in a small interval and does not calculate the rest of the values. Can you help me solve the problem?

#property strict
#property indicator_separate_window
#property indicator_buffers 2

#property indicator_label1 "VBuyers"
#property indicator_label2 "VSellers"

enum ShowMode //Diagram Show Mode
{
OneSide=1,      //OneSideMode
TwoSideMode=2  //TwoSideMode
};
input ShowMode DiagramMode=TwoSideMode;
input color SellerLineColor=clrRed;   //Seller Line Color
input color BuyerLineColor=clrLime;    //Buyer Line Color

double VBuyersbuffer[],VSellersbuffer[];

int CurrentTimeFrame,CurrentTFBarCounter,M1BarCounter;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   SetIndexBuffer(0,VBuyersbuffer);
   SetIndexBuffer(1,VSellersbuffer);
   SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,4,BuyerLineColor);
   SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,2,SellerLineColor);
   //IndicatorSetInteger(INDICATOR_LEVELCOLOR,0,BuyerLineColor);
   //IndicatorSetInteger(INDICATOR_LEVELCOLOR,1,SellerLineColor);
   IndicatorDigits(0);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| 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[])
  {
   double TotalVSeller,TotalVBuyer;
   datetime TimeM1[],TimeCurrentTF[];
   double OpenM1[],CloseM1[],HighM1[],LowM1[];
   int VolumeM1[],VolumeCurrentTF[],MaxVolume,v;
//calculate seller buyers volume

   CurrentTimeFrame=ChartPeriod(0);                  //Find current chart period
   ArrayCopySeries(TimeM1,MODE_TIME,NULL,PERIOD_M1);
   ArrayCopySeries(TimeCurrentTF,MODE_TIME,NULL,PERIOD_CURRENT);
   ArrayCopySeries(OpenM1,MODE_OPEN,NULL,PERIOD_M1);
   ArrayCopySeries(CloseM1,MODE_CLOSE,NULL,PERIOD_M1);
   ArrayCopySeries(HighM1,MODE_HIGH,NULL,PERIOD_M1);
   ArrayCopySeries(LowM1,MODE_LOW,NULL,PERIOD_M1);

// calculate M1 volumes and save to array VolumeM1[]
//==============================================================================================================
   ArrayResize(VolumeM1,ArraySize(HighM1));
   for(int k=0; k<ArraySize(VolumeM1); k++)
     {
      v=(int)iVolume(_Symbol,PERIOD_M1,k);
      VolumeM1[k]=v;
     }

   int SellerVolumeM1[],BuyerVolumeM1[];
   ArrayResize(SellerVolumeM1,ArraySize(VolumeM1));
   ArrayResize(BuyerVolumeM1,ArraySize(VolumeM1));
   for(int k=0; k<ArraySize(VolumeM1); k++)
     {
      SellerVolumeM1[k]=0;
      BuyerVolumeM1[k]=0;
      if(OpenM1[k]>CloseM1[k])
         SellerVolumeM1[k]=VolumeM1[k];
      if(OpenM1[k]<CloseM1[k])
         BuyerVolumeM1[k]=VolumeM1[k];
     }
   ArrayResize(TimeCurrentTF,Bars);
   ArrayResize(VolumeCurrentTF,Bars);
   for(int i=0; i<Bars-prev_calculated; i++)
     {
      TimeCurrentTF[i]=Time[i];
      VolumeCurrentTF[i]=(int) Volume[i];
     }
   MaxVolume=ArrayMaximum(VolumeCurrentTF,NULL,0);


//==============================================================================================================

//--- the main loop of calculations,
   int SellerVolumeTotal[],BuyerVolumeTotal[];
   ArrayResize(SellerVolumeTotal,ArraySize(TimeCurrentTF));
   ArrayResize(BuyerVolumeTotal,ArraySize(TimeCurrentTF));

//Multi Time Frame Calculator

   TotalVBuyer=0;
   TotalVSeller=0;
   int i=0;
   int limit=Bars-prev_calculated,M1Counter=0;
   for(int i=0, k=0; i<ArraySize(TimeM1); i++)   //i=M1BarCounter   k=CurrentBarCounter
     {
      if(OpenM1[i]<=CloseM1[i])
        {
         TotalVBuyer=TotalVBuyer+(int) iVolume(_Symbol,PERIOD_M1,i);
        }
      if(OpenM1[i]>CloseM1[i])
        {
         TotalVSeller=TotalVSeller+(int) iVolume(_Symbol,PERIOD_M1,i);
        }

      if(iTime(_Symbol,PERIOD_CURRENT,k)==iTime(_Symbol,PERIOD_M1,i))
        {
         VBuyersbuffer[k]=TotalVBuyer;
         if(DiagramMode==1)
         {
           VSellersbuffer[k]=TotalVSeller;
         }else //ShowMode 
         {
         VSellersbuffer[k]=-TotalVSeller;
         }
         TotalVBuyer=0;
         TotalVSeller=0;
         k++;
         continue;
        }
      string WindowName = "Seller-Buyer Power Ver 1.02";
      IndicatorShortName(WindowName);
     }
   return(rates_total);
  }
Files:
 
In this indicator, for each current time frame candlestick, the volume of total bearish and bullish candlesticks of its constituent candlesticks in M1 timeframe should be added separately.
Documentation on MQL5: Date and Time / TimeCurrent
Documentation on MQL5: Date and Time / TimeCurrent
  • www.mql5.com
TimeCurrent - Date and Time - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

Was a solution to this ever given?

Thanks.
 

finally i know that it is a mt4 or mt5 property. they can can just save  limited candle data. ( i think it was 1440 candle at each timeframe) and if you want more of them you must open the chart every day. by this action information of them saved to your PC and you can use them.

 
Mahdi Moghadampour #:

finally i know that it is a mt4 or mt5 property. they can can just save  limited candle data.
( i think it was 1440 candle at each timeframe) and
if you want more of them you must open the chart every day. by this action information of them saved to your PC and you can use them.

Hello,

You may solve it by this way:

Tools -> Option -> Charts.

Note.

As long as your broker provides more complete data,
> then your charts will have more complete data.

There are some countries that limit the completeness of data in chart history.
An example is India. The broker only provides historical data for the past 3 months.

Regards.

 

   Hi!!!! There is an indicator similar to your indicator.          Waddah_Attar_BUY_SELL_Vol_xtf,1   может он тебе поможет .

I liked your indicator. But I didn't understand how you control MTF mode. I'm going to use your indicator in my system.

Reason: