Help modify indicator from Plotting Daily Lines to Plotting Hourly Lines

 
#property indicator_chart_window
#property indicator_buffers 3 // Increase buffers to 3
#property indicator_plots   3 // Increase plots to 3
#property indicator_label1  "Daily open line"
#property indicator_label2  "Above Open line"
#property indicator_label3  "Below Open line"
#property indicator_type1   DRAW_ARROW
#property indicator_type2   DRAW_LINE
#property indicator_type3   DRAW_LINE
#property indicator_style1  STYLE_DOT
#property indicator_style2  STYLE_SOLID
#property indicator_style3  STYLE_SOLID
#property indicator_color1  clrGold
#property indicator_color2  clrRed
#property indicator_color3  clrBlue

input int TimeShift = 0; // Time shift (in hours)
double openLine[];
double aboveOpen[];
double belowOpen[];

int OnInit() { 
    SetIndexBuffer(0, openLine, INDICATOR_DATA); 
    SetIndexBuffer(1, aboveOpen, INDICATOR_CALCULATIONS);
    SetIndexBuffer(2, belowOpen, INDICATOR_CALCULATIONS);
    return(INIT_SUCCEEDED); 
}

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 (Bars(_Symbol, _Period) < rates_total) 
        return(-1);

    for (int i = (int)MathMax(prev_calculated - 1, 0); i < rates_total && !IsStopped(); i++)
    {
        string stime = TimeToString(time[i] + TimeShift * 3600, TIME_DATE);
        openLine[i] = (i > 0) ? (TimeToString(time[i - 1] + TimeShift * 3600, TIME_DATE) == stime) ? openLine[i - 1] : open[i] : open[i];
        
        aboveOpen[i] = openLine[i] + 100 * Point(); // Line 100 points above the daily open
        belowOpen[i] = openLine[i] - 100 * Point(); // Line 100 points below the daily open
    }
    return (rates_total);
}
 
Your topic has been moved to the section: Technical Indicators
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 
        string stime = TimeToString(time[i] + TimeShift * 3600, TIME_DATE);
  1. Arrays must be manually sized. They have no direction. You must move elements if you want a stack/as-series (set non-series, enlarge the array, set as-series).

  2. Buffers are automatically size, are as-series, and elements are moved for you, new elements are set to EMPTY_VALUE (or your designated. They can also draw on the chart automatically.

  3. In MT4, buffers and MT4 predefined arrays are all ordered AsSeries. There is a difference between the arrays passed to OnCalculate (e.g. low[]) and the MT4 predefined variables (e.g. Low[].) The passed arrays have no default direction, just like MT5.

    To determine the indexing direction of time[], open[], high[], low[], close[], tick_volume[], volume[] and spread[], call ArrayGetAsSeries(). In order not to depend on default values, you should unconditionally call the ArraySetAsSeries() function for those arrays, which are expected to work with.
              Event Handling Functions - Functions - Language Basics - MQL4 Reference

  4. In MT5, you must set the direction.

    To define the indexing direction in the time[], open[], high[], low[], close[], tick_volume[], volume[] and spread[] arrays, call the ArrayGetAsSeries() function. In order not to depend on defaults, call the ArraySetAsSeries() function for the arrays to work with.
              Event Handling / OnCalculate - Reference on algorithmic/automated trading language for MetaTrader 5
Reason: