Download MetaTrader 5

Direction of plotting a Graph?

To add comments, please log in or register
LaHood
7
LaHood  

Hi,


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. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2010, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#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
   SetIndexBuffer(0,cEMA,INDICATOR_DATA);
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| 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
         {
         cEMA[i]=close[i];
         }
      if (i>0)                                  //if history+1 day
         {
         cEMA[i]=cEMA[i-1]+(SF*(close[i]-cEMA[i-1]));
         }
    
     PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,0);
     }

//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

Automated Trading and Strategy Testing
  • www.mql5.com
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
Admin
12661
Rashid Umarov  
Try to insert code properly.
MQL5.community - User Memo
  • 2010.02.25
  • MetaQuotes Software Corp.
  • www.mql5.com
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 MQL5.community and take full advantage of its available features.
Paul
784
Paul  
Rosh:
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