HiLo2DayBefore

Download script
HiLo2DayBefore

This script is a technical analysis tool designed to provide traders with visual benchmarks on their trading charts by automatically identifying and plotting key historical price levels. Its primary purpose is to help users identify significant support and resistance areas based on previous market behavior.

How the Logic Works

The script operates by looking back at historical daily data to extract four specific pieces of information from the preceding days:

  • Yesterday’s Range: It identifies the highest price reached and the lowest price reached during the previous trading day.
  • Two Days Ago Range: It identifies the highest and lowest prices from the day before yesterday.
  • Pivot Point Calculation: It calculates a "Standard Pivot" level, which is determined by taking the average of yesterday’s high, low, and closing prices.

Visual Representation on Your Chart

Once the script gathers this data, it automatically draws the following elements directly onto your screen:

  1. High & Low Boundaries: The tool draws horizontal lines for the highs and lows of both "yesterday" and the "day before yesterday." These are color-coded to distinguish between the two timeframes.
  2. Labels: Each line is accompanied by a text label (e.g., "Low yesterday," "Pivot level") so that you can immediately identify what price point you are looking at without having to check the data manually.
  3. Dynamic Pivot Line: A specific line is dedicated to the calculated Pivot Point, providing a central "equilibrium" level for the current trading session.

Key Features

  • Automated Updates: The script continuously refreshes these levels as new daily candles form, ensuring your benchmarks are always current.
  • Clean Interface: When you remove the indicator from your chart, it is designed to automatically clear all drawn lines and labels, leaving your workspace clean.
  • Visual Clarity: By using different colors and line styles (such as dotted vs. solid lines), the tool allows you to quickly differentiate between the current day's significant levels and older historical data.

Essentially, this script serves as a "memory" for your chart, highlighting where the market has reacted in the past so you can better anticipate potential price movements in the present.

Price Data Components
Series array that contains close prices for each barSeries array that contains the highest prices of each barSeries array that contains the lowest prices of each bar
17 Views
0 Downloads
0 Favorites
HiLo2DayBefore
//+------------------------------------------------------------------+
//|                                               HiLo2DayBefore.mq4 |
//+------------------------------------------------------------------+

#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
//YLow, low of yesterday.
//YHigh, high of yesterday.
//B4YLow, low of before yestersay.
//B4YHigh, high of before yesterday.
//PP, pivot point.
   ObjectDelete("YLow");
   ObjectDelete("B4YLow");
   ObjectDelete("YHigh");
   ObjectDelete("B4YHigh");
   ObjectDelete("PIVOT");
   Comment(" ");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   
//----
double yesterday_close,yesterday_high,yesterday_low,before_yesterday_close,before_yesterday_high,before_yesterday_low;

    yesterday_close = iClose(NULL,PERIOD_D1,1);
    yesterday_high = iHigh(NULL,PERIOD_D1,1);
    yesterday_low = iLow(NULL,PERIOD_D1,1);
    before_yesterday_close = iClose(NULL,PERIOD_D1,2);
    before_yesterday_high = iHigh(NULL,PERIOD_D1,2);
    before_yesterday_low = iLow(NULL,PERIOD_D1,2);

//---- Calculate Pivots

//Comment("\nYesterday quotations :\nH ",yesterday_high,"\nL ",yesterday_low, "\nC ",yesterday_close,"\n\nBefore yesterday quotations :\nH ",before_yesterday_high,"\nL ",before_yesterday_low, "\nC ",before_yesterday_close);
double pivot = (yesterday_high + yesterday_low + yesterday_close)/3;// Standard Pivot

drawLine(yesterday_low,"YLow", Plum,0);
drawLabel("Low yesterday",yesterday_low,Plum);
drawLine(before_yesterday_low,"B4YLow", Plum,0);
drawLabel("Low before yesterday",before_yesterday_low,Plum);

drawLine(pivot,"PIVOT",Aqua,1);
drawLabel("Pivot level",pivot,Aqua);

drawLine(yesterday_high,"YHigh",CornflowerBlue,0);
drawLabel("High yesterday",yesterday_high,CornflowerBlue);
drawLine(before_yesterday_high,"B4YHigh",CornflowerBlue,0);
drawLabel("High before yesterday",before_yesterday_high,CornflowerBlue);


//----
   return(0);
  }
//+------------------------------------------------------------------+
void drawLabel(string name,double lvl,color Color)
{
    if(ObjectFind(name) != 0)
    {
        ObjectCreate(name, OBJ_TEXT, 0, Time[10], lvl);
        ObjectSetText(name, name, 8, "Arial", EMPTY);
        ObjectSet(name, OBJPROP_COLOR, Color);
    }
    else
    {
        ObjectMove(name, 0, Time[10], lvl);
    }
}


void drawLine(double lvl,string name, color Col,int type)
{
         if(ObjectFind(name) != 0)
         {
            ObjectCreate(name, OBJ_HLINE, 0, Time[0], lvl,Time[0],lvl);
            
            if(type == 1)
            ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID);
            else
            ObjectSet(name, OBJPROP_STYLE, STYLE_DOT);
            
            ObjectSet(name, OBJPROP_COLOR, Col);
            ObjectSet(name,OBJPROP_WIDTH,1);
            
         }
         else
         {
            ObjectDelete(name);
            ObjectCreate(name, OBJ_HLINE, 0, Time[0], lvl,Time[0],lvl);
            
            if(type == 1)
            ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID);
            else
            ObjectSet(name, OBJPROP_STYLE, STYLE_DOT);
            
            ObjectSet(name, OBJPROP_COLOR, Col);        
            ObjectSet(name,OBJPROP_WIDTH,1);
          
         }
}

Comments