Download MetaTrader 5

Direction of plotting a Graph?

To add comments, please log in or register


im a lil bit confused. In which direction the plot is working? From right to left or left to right? I thought in MT4 it was from right(today) to left(history). It looks like that plotting a graph in MT4 is from history to today, but for me i need it in another direction. Is it possible to mirror the drawing? And wasnt it in MT4 that iClose(0) means the actual bar and iClose(bars) was the first in the history? To understand my problem a bit better i paste the source code of my EMA calculation here. The problem here is that the EMA plot are mirrored in the wrong direction. If you go to month view you will see that at the beginning of the EMA graph in the history the line is exactly the close value. And in the actual bar from today the EMA line is far away. But it should be in the other way.

//|                                                      mt5_EMA.mq5 |
//|                        Copyright 2010, MetaQuotes Software Corp. |
//|                                     |
#property copyright "Copyright 2010, MetaQuotes Software Corp."
#property link      ""
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots 1

//---- plot Line
#property indicator_label1 "Line"
#property indicator_type1 DRAW_LINE
#property indicator_color1 YellowGreen
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1

//--- input parameters

//--- indicator buffers
double GD=20;              //Moving Average
double SF;                 //Smoothing Factor
double cEMA[];             //EMA
double i;
//| Custom indicator initialization function                         |
int OnInit()
//--- indicator buffers mapping
//| 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[])
   int bars=Bars(Symbol(),PERIOD_CURRENT);      //bars for the displayed timeframe
   i=0;                                         //Counter
   SF=(2/(GD+1));                               //Smoothing Factor
   Print ("Closekurs 0:",close[0]);
   Print ("Closekurs Bars:",close[bars-1]);

     for(int i=0;i<=bars-1;i++)
      if (i==0)                                 //if first bar in history and so no history-yesterday course is availabe
      if (i>0)                                  //if history+1 day

//--- return value of prev_calculated for next call

Automated Trading and Strategy Testing
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
Rashid Umarov
Rashid Umarov  
Try to insert code properly. - User Memo
  • 2010.02.25
  • MetaQuotes Software Corp.
You have just registered and most likely you have questions such as, "How do I insert a picture to my a message?" "How do I format my MQL5 source code?" "Where are my personal messages kept?" You may have many other questions. In this article, we have prepared some hands-on tips that will help you get accustomed in and take full advantage of its available features.
Try to insert code properly.


The basic answer to your question is that you need to use ArraySetAsSeries(), but this will cause other issues with your code, such as the need to loop in reverse order and the indexes should be i+1, not i-1.  You also need to use prev_calculated to avoid recalculating the entire indicator set with each tick.

 I suggest you look in the help documentation and articles.


To add comments, please log in or register