MQL5 Custom Indicator : Keeping Set of line between two period seperators

 
//+------------------------------------------------------------------+
//|                                                    BOYVOL100.mq5 |
//|                                                  Masa Nethononda |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Masa Nethononda"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window

#include <ACDVOL100.mqh>

#property indicator_chart_window
#property indicator_buffers 8
#property indicator_plots   8
//--- plot OpenRangeHigh
#property indicator_label1  "OpenRangeHigh"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrDodgerBlue
#property indicator_style1  STYLE_SOLID
#property indicator_width1  2
//--- plot OpenRangeLow
#property indicator_label2  "OpenRangeLow"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrDodgerBlue
#property indicator_style2  STYLE_SOLID
#property indicator_width2  2
//--- plot PivotRangeHigh
#property indicator_label3  "PivotRangeHigh"
#property indicator_type3   DRAW_LINE
#property indicator_color3  clrOrangeRed
#property indicator_style3  STYLE_SOLID
#property indicator_width3  2
//--- plot PivotRangeLow
#property indicator_label4  "PivotRangeLow"
#property indicator_type4   DRAW_LINE
#property indicator_color4  clrOrangeRed
#property indicator_style4  STYLE_SOLID
#property indicator_width4  2
//--- plot AUpValue
#property indicator_label5  "AUpValue"
#property indicator_type5   DRAW_LINE
#property indicator_color5  clrGold
#property indicator_style5  STYLE_SOLID
#property indicator_width5  2
//--- plot ADownValue
#property indicator_label6  "ADownValue"
#property indicator_type6   DRAW_LINE
#property indicator_color6  clrGold
#property indicator_style6  STYLE_SOLID
#property indicator_width6  2
//--- plot CUpValue
#property indicator_label7  "CUpValue"
#property indicator_type7   DRAW_LINE
#property indicator_color7  clrDeepPink
#property indicator_style7  STYLE_SOLID
#property indicator_width7  2
//--- plot CDownValue
#property indicator_label8  "CDownValue"
#property indicator_type8   DRAW_LINE
#property indicator_color8  clrDeepPink
#property indicator_style8  STYLE_SOLID
#property indicator_width8  2

//--- indicator buffers
double         OpenRangeHighBuffer[];
double         OpenRangeLowBuffer[];
double         PivotRangeHighBuffer[];
double         PivotRangeLowBuffer[];
double         AUpValueBuffer[];
double         ADownValueBuffer[];
double         CUpValueBuffer[];
double         CDownValueBuffer[];


string OpenRangeHigh = "OpenRangeHigh";
string OpenRangeLow = "OpenRangeLow";
string AUpValue = "AUpValue";
string ADownValue = "ADownValue";
string CUpValue = "CUpValue";
string CDownValue = "CDownValue";
string PivotRangeHigh = "PivotRangeHigh";
string PivotRangeLow = "PivotRangeLow";

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   int IndicatorPlotBegins = 2;
   int IndicatorPlotShift = 22;
   
   SetIndexBuffer(0,OpenRangeHighBuffer,INDICATOR_DATA);
   PlotIndexSetInteger(0,PLOT_SHIFT,IndicatorPlotShift);
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,IndicatorPlotBegins);
   SetIndexBuffer(1,OpenRangeLowBuffer,INDICATOR_DATA);
   PlotIndexSetInteger(1,PLOT_SHIFT,IndicatorPlotShift);
   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,IndicatorPlotBegins);
   SetIndexBuffer(2,PivotRangeHighBuffer,INDICATOR_DATA);
   PlotIndexSetInteger(2,PLOT_SHIFT,IndicatorPlotShift);
   PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,IndicatorPlotBegins);
   SetIndexBuffer(3,PivotRangeLowBuffer,INDICATOR_DATA);
   PlotIndexSetInteger(3,PLOT_SHIFT,IndicatorPlotShift);
   PlotIndexSetInteger(3,PLOT_DRAW_BEGIN,IndicatorPlotBegins);
   SetIndexBuffer(4,AUpValueBuffer,INDICATOR_DATA);
   PlotIndexSetInteger(4,PLOT_SHIFT,IndicatorPlotShift);
   PlotIndexSetInteger(4,PLOT_DRAW_BEGIN,IndicatorPlotBegins);
   SetIndexBuffer(5,ADownValueBuffer,INDICATOR_DATA);
   PlotIndexSetInteger(5,PLOT_SHIFT,IndicatorPlotShift);
   PlotIndexSetInteger(5,PLOT_DRAW_BEGIN,IndicatorPlotBegins);
   SetIndexBuffer(6,CUpValueBuffer,INDICATOR_DATA);
   PlotIndexSetInteger(6,PLOT_SHIFT,IndicatorPlotShift);
   PlotIndexSetInteger(6,PLOT_DRAW_BEGIN,IndicatorPlotBegins);
   SetIndexBuffer(7,CDownValueBuffer,INDICATOR_DATA);
   PlotIndexSetInteger(7,PLOT_SHIFT,IndicatorPlotShift);
   PlotIndexSetInteger(7,PLOT_DRAW_BEGIN,IndicatorPlotBegins);
   
   




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


//---
     
   int Total = 0;
   int LookBack = 0;
   if(prev_calculated == 0)
     {
      Total=rates_total-LookBack;
     }
      else
        {
         Total = rates_total-prev_calculated;
        }
   

   for(int i = 0; i<Total; i++)
     {

      OpenRangeHighBuffer[i] = OpenRangeHighH1;
      ObjectSetInteger(NULL,OpenRangeHigh,OBJPROP_TIMEFRAMES,OBJ_PERIOD_M1|OBJ_PERIOD_M15|OBJ_PERIOD_M30|OBJ_PERIOD_H1);

      OpenRangeLowBuffer[i]=OpenRangeLowH1;
      ObjectSetInteger(NULL,OpenRangeLow,OBJPROP_TIMEFRAMES,OBJ_PERIOD_M1|OBJ_PERIOD_M15|OBJ_PERIOD_M30|OBJ_PERIOD_H1);

      PivotRangeHighBuffer[i]= PivotRangeHighH1();
      ObjectSetInteger(NULL,PivotRangeHigh,OBJPROP_TIMEFRAMES,OBJ_PERIOD_M1|OBJ_PERIOD_M15|OBJ_PERIOD_M30|OBJ_PERIOD_H1);

      PivotRangeLowBuffer[i]= PivotRangeLowH1();
      ObjectSetInteger(NULL,PivotRangeLow,OBJPROP_TIMEFRAMES,OBJ_PERIOD_M1|OBJ_PERIOD_M15|OBJ_PERIOD_M30|OBJ_PERIOD_H1);

      AUpValueBuffer[i] = AUpValueH1;
      ObjectSetInteger(NULL,AUpValue,OBJPROP_TIMEFRAMES,OBJ_PERIOD_M1|OBJ_PERIOD_M15|OBJ_PERIOD_M30|OBJ_PERIOD_H1);

      ADownValueBuffer[i]= ADownValueH1;
      ObjectSetInteger(NULL,ADownValue,OBJPROP_TIMEFRAMES,OBJ_PERIOD_M1|OBJ_PERIOD_M15|OBJ_PERIOD_M30|OBJ_PERIOD_H1);

      CUpValueBuffer[i]=CUpValueH1;
      ObjectSetInteger(NULL,CUpValue,OBJPROP_TIMEFRAMES,OBJ_PERIOD_M1|OBJ_PERIOD_M15|OBJ_PERIOD_M30|OBJ_PERIOD_H1);

      CDownValueBuffer[i] = CDownValueH1;
      ObjectSetInteger(NULL,CDownValue,OBJPROP_TIMEFRAMES,OBJ_PERIOD_M1|OBJ_PERIOD_M15|OBJ_PERIOD_M30|OBJ_PERIOD_H1);

     }

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


//+------------------------------------------------------------------+

Good Day MQL5 Forum and Programmers.

Please assist I am a beginner in the MT5 programming platform and I have tirelessly trying to write a code that will instruct the sets of indicator line to be inbetween two period seperators.

Please assist I have been trying to go through the OnCalculate function for quite some time.

Please find attached Snips of the code and indicator.

Thank you for your assistance in advance.

Files:
 
Masa Eudy Nethononda:

Good Day MQL5 Forum and Programmers.

Please assist I am a beginner in the MT5 programming platform and I have tirelessly trying to write a code that will instruct the sets of indicator line to be inbetween two period seperators.

Please assist I have been trying to go through the OnCalculate function for quite some time.

Please find attached Snips of the code and indicator.

Thank you for your assistance in advance.

1.  Please insert the code correctly: when editing a message, use the button   Codeto insert the code.

2. Nothing is clear from your drawing.

 
Vladimir Karputov:

1.  Please insert the code correctly: when editing a message, use the button   to insert the code.

2. Nothing is clear from your drawing.

Thank you I have attached the code.


I want the set of colored line to be in between the two period seperators only not for the lines to go all the way to the left.

for example datetime to be in between 2020.04.06 00:00 to 2020.04.07 00:00 only

 
Masa Eudy Nethononda :

Thank you I have attached the code.


I want the set of colored line to be in between the two period seperators only not for the lines to go all the way to the left.

for example datetime to be in between 2020.04.06 00:00 to 2020.04.07 00:00 only

In this case, you need to determine the date of the period.

If this is the first launch (prev_calculated == 0)

 //--- 
   int limit=prev_calculated- 1 ;
   if (prev_calculated== 0 )
      limit= 0 ;

you put 0.0 in the indicator buffer, before the start of the period date.

 
Vladimir Karputov:

In this case, you need to determine the date of the period.

If this is the first launch (prev_calculated == 0)

you put 0.0 in the indicator buffer, before the start of the period date.

its still showing the same thing.

the datetime is already included in the indicator data 

 Please see attached..on MT4 is like as shown in the picture attached. I need to achieve the same result on MT5
Files:
mt4_1.JPG  17 kb
 
Masa Eudy Nethononda :

its still showing the same thing.

the datetime is already included in the indicator data 

Start with the simplest: draw the icon ONLY on the current bar (by the way, I always create file templates using the MQL Wizard)

//+------------------------------------------------------------------+
//|                                                     Last Bar.mq5 |
//|                                  Copyright 2021, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot High
#property indicator_label1  "High"
#property indicator_type1   DRAW_ARROW
#property indicator_color1  clrDeepSkyBlue
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- input parameters
input int      Input1=9;
//--- indicator buffers
double   HighBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,HighBuffer,INDICATOR_DATA);
//--- setting a code from the Wingdings charset as the property of PLOT_ARROW
   PlotIndexSetInteger(0,PLOT_ARROW,159);
//--- set as an empty value 0
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.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[])
  {
//---
   int limit=prev_calculated-1;
   if(prev_calculated==0)
     {
      HighBuffer[0]=0.0;
      limit=1;
     }
   for(int i=limit; i<rates_total; i++)
     {
      if(i<rates_total-1)
         HighBuffer[i]=0.0;
      else
         HighBuffer[i]=high[i];
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+


Result:

Last bar

Files:
Last_Bar.mq5  3 kb
Reason: