Download MetaTrader 5
To add comments, please log in or register
What is a social trading? Read the article to find that out!
imamushroom 2015.10.01 13:12 


I'm using the code from this article to calculate when a new bar opens but it's not displaying the historical data for the indicator. I modified the TimeCurrent() to iTime(_Symbol,_Period,shift) to try to handle this but it's not working.

Could you tell me what I'm doing wrong please?


#property indicator_separate_window

#property indicator_buffers 1

#property indicator_color1 RoyalBlue

#include <Lib_CisNewBar.mqh>

CisNewBar current_chart;

//---- input parameters

extern int    Length=18;      // Bollinger Bands Period

extern int    Deviation=2;    // Deviation was 2

extern double MoneyRisk=1.00; // Offset Factor

extern int    Signal=1;       // Display signals mode: 1-Signals & Stops; 0-only Stops; 2-only Signals;

extern int    Line=1;         // Display line mode: 0-no,1-yes  

extern int    Nbars=1000;

//---- indicator buffers

double TrendBuffer[];

extern bool SoundON=true;

bool TurnedUp = false;

bool TurnedDown = false;


//| Custom indicator initialization function                         |


  int init()


   string short_name;

//---- indicator line





   short_name="Example ("+Length+","+Deviation+")";


   SetIndexLabel(0,"Trend Value");






void deinit()



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[])


   int    shift;


   for (shift=Nbars;shift>=0;shift--)




   for (shift=Nbars-Length-1;shift>=0;shift--)


      int period_seconds=PeriodSeconds(_Period);                    

      datetime new_time=iTime(_Symbol,_Period,shift)/period_seconds*period_seconds; 



         Print("time[shift] = "+TimeToString(time[shift]));

         if( Close[shift] > Close[shift+1] )


              else if(Close[shift] < Close[shift+1] ) 








The "New Bar" Event Handler
The "New Bar" Event Handler
  • 2010.10.11
  • Konstantin Gruzdev
MQL5 programming language is capable of solving problems on a brand new level. Even those tasks, that already have such solutions, thanks to object oriented programming can rise to a higher level. In this article we take a specially simple example of checking new bar on a chart, that was transformed into rather powerful and versatile tool. What tool? Find out in this article.
To add comments, please log in or register