Author: Copyright © 2020, Vladimir Karputov

This script is a specialized technical analysis tool designed for the MetaTrader 5 platform. Its primary purpose is to identify and visually mark specific price points—specifically "Open Prices"—from a higher or different timeframe onto your current trading chart.

Core Functionality

The tool acts as a visual bridge between multiple timeframes. While most traders look at a single chart (e.g., a 15-minute chart), this script allows you to see where the price opened on a larger interval (such as the 1-hour or 4-hour chart) directly on your active workspace.

How the Logic Works

To ensure a smooth and accurate user experience, the script follows a specific logical flow:

  • Validation and Safety: When you first load the tool, it performs a "sanity check." If you try to set a timeframe that is smaller than the one you are currently viewing (for example, trying to view 1-minute data on a 1-hour chart), the script will issue an alert and prevent execution. This ensures the visual data remains meaningful and organized.
  • Smart Data Synchronization: The script intelligently scans historical price data. It identifies the exact moment a new bar (candle) is born for your chosen timeframe. Instead of cluttering your screen with constant updates, it focuses on these specific "birth" moments to ensure accuracy.
  • Dynamic Timeframe Mapping:
    • If you are viewing the same timeframe as your input, the script simply pulls the standard open price.
    • If you are viewing a different timeframe, the script performs a "shift" calculation. It calculates the mathematical distance between your current view and the target timeframe to find the corresponding historical data point.
  • Visual Output: Once the correct price is located, the script places a specific visual marker (an arrow) on your chart. This marker is labeled with the currency symbol and the timeframe to make it immediately clear what price level you are looking at.

Key User Benefits

  • Contextual Awareness: It provides a "bird's eye view," allowing you to see significant support or resistance levels created by larger market movements without constantly switching between different tabs.
  • Clean Visualization: By using specific markers rather than just drawing lines, the tool keeps your chart clean and professional.
  • Automation: It removes the need for manual calculation; the script handles all the complex math required to sync different time periods perfectly.
Price Data Components
Series array that contains open prices of each bar
Miscellaneous
It issuies visual alerts to the screen
7 Views
0 Downloads
0 Favorites
Open Level
ÿþ//+------------------------------------------------------------------+

//|                                                   Open Level.mq5 |

//|                              Copyright © 2020, Vladimir Karputov |

//|                     https://www.mql5.com/ru/market/product/43516 |

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

#property copyright "Copyright © 2020, Vladimir Karputov"

#property link      "https://www.mql5.com/ru/market/product/43516"

#property version   "1.003"

#property indicator_chart_window

#property indicator_buffers 1

#property indicator_plots   1

//--- plot Open

#property indicator_label1  "Open"

#property indicator_type1   DRAW_ARROW

#property indicator_color1  clrFuchsia

#property indicator_style1  STYLE_SOLID

#property indicator_width1  1

//--- input parameters

input ENUM_TIMEFRAMES   Inp_period  = PERIOD_H1;   // Timeframe

//--- indicator buffer

double   OpenBuffer[];

//---

bool     m_global_error             = false;

datetime m_prev_bars                = 0;           // "0" -> D'1970.01.01 00:00';

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

   if(Inp_period<Period())

     {

      string err_text=(TerminalInfoString(TERMINAL_LANGUAGE)=="Russian")?

                      "E>4=>9 ?0@0<5B@ \"Timeframe\" =5 <>65B 1KBL ,( B5:CI53> B09<D@59<0!":

                      "Input parameter \"Timeframe\" cannot be LESS than the current timeframe!";

      Alert(__FILE__," ",__FUNCTION__,", ERROR: ",err_text);

      m_global_error=true;

      return(INIT_SUCCEEDED);

     }

   double price_open=iOpen(Symbol(),Inp_period,0);

//--- indicator buffers mapping

   SetIndexBuffer(0,OpenBuffer,INDICATOR_DATA);

//--- setting a code from the Wingdings charset as the property of PLOT_ARROW

   PlotIndexSetInteger(0,PLOT_ARROW,159);

//--- Set the display of the symbol

   PlotIndexSetString(0,PLOT_LABEL,Symbol()+","+StringSubstr(EnumToString(Inp_period),7)+" Open");

//---

   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(m_global_error)

      return(0);

//--- main loop

   int limit=prev_calculated-1;

   if(prev_calculated==0)

      limit=0;

   for(int i=limit; i<rates_total; i++)

     {

      //--- we work only at the time of the birth of new bar

      if(time[i]==m_prev_bars)

         continue;

      m_prev_bars=time[i];

      if(Inp_period==Period())

        {

         OpenBuffer[i]=open[i];

        }

      else

        {

         int bars_shift=iBarShift(Symbol(),Inp_period,time[i],false);

         if(bars_shift<0)

           {

            return(0);

            m_prev_bars=0;

           }

         double price_open=iOpen(Symbol(),Inp_period,bars_shift);

         if(price_open==0.0)

           {

            return(0);

            m_prev_bars=0;

           }

         OpenBuffer[i]=price_open;

        }

     }

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

   return(rates_total);

  }

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

Comments