Author: 2015, Anton Gorin
Price Data Components
Series array that contains close prices for each bar
0 Views
0 Downloads
0 Favorites
Live_lines
//+------------------------------------------------------------------+
//|                                                   Live lines.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "2015, Anton Gorin"
#property link      "https://www.mql5.com/ru/users/owis2/publications"
#property version   "1.0"
#property strict
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Price
#property indicator_label1  "Price"
#property indicator_type1   DRAW_SECTION
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- indicator buffers
double         PriceBuffer[];
datetime       LastTime;
int            Step;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,PriceBuffer);
   string Name;
   switch(_Period)
     {
      case PERIOD_M1:   Step=5;  Name="M5";   break;
      case PERIOD_M5:   Step=3;  Name="M15";  break;
      case PERIOD_M15:  Step=2;  Name="M30";  break;
      case PERIOD_M30:  Step=2;  Name="H1";   break;
      case PERIOD_H1:   Step=4;  Name="H4";   break;
      case PERIOD_H4:   Step=6;  Name="D1";   break;
      case PERIOD_D1:   Step=5;  Name="W";    break;
      case PERIOD_W1:   Step=4;  Name="MN";   break;
      case PERIOD_MN1:  Step=3;  Name="MN3";  break;
     }
   SetIndexEmptyValue(0,0.0);
   IndicatorShortName("Live lines ("+Name+")");
//---
   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[])
  {
//---
   if(iTime(_Symbol,PERIOD_M1,0)==LastTime) return rates_total;
   LastTime=iTime(_Symbol,PERIOD_M1,0);
   int Total=WindowFirstVisibleBar()+Step;
   if(Total>=Bars) Total=Bars-1;
   for(int i=0;i<=Total;i+=Step)
      PriceBuffer[i]=iClose(_Symbol,PERIOD_M1,i*_Period);
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

Comments