PrevDay_HiLo_kelvin_001
Download scriptThis tool is designed to provide traders with a clear visual reference of the previous day's price action directly on their current trading chart. By automatically identifying and marking specific historical price points, it helps users understand key levels of support, resistance, and opening behavior from the preceding session.
How it Works
The script constantly scans your price history to track three primary metrics: the High, the Low, and the Open prices of the previous trading day. Here is the step-by-step logic of how it processes this information:
- Price Tracking: The tool monitors every bar on your chart. It looks for the highest and lowest prices reached during a specific day's session.
- Day Change Detection: The script is programmed to recognize when the calendar day changes. Every time a new day begins, it "locks in" the high, low, and open prices of the day that just finished.
- Visual Mapping: Once the data for the previous day is finalized, the tool places horizontal markers on your chart at those exact price levels.
- The High and Low levels are highlighted to show you the boundaries of yesterday's movement.
- The Open level is marked to show where the previous session started.
- Dynamic Updating: The script automatically adjusts these markers as it moves through different timeframes, ensuring that the "Previous Day" data remains relevant to the current price action you are viewing.
Key Features for Traders
- Automated Analysis: You don't have to manually look back at yesterday's candles to find the peak or valley; the tool does this calculation for you instantly.
- Visual Labels: The tool includes text labels on the chart (such as "HIGH," "LOW," and "OPEN") so you can identify each price level at a glance without confusion.
- Clean Interface: It is designed to sit cleanly on your chart window, providing essential data points while keeping the workspace organized.
Technical Constraints
To ensure accuracy, the script is optimized for shorter timeframes (specifically those under 240 minutes). This ensures that the transition between "days" is calculated correctly based on the price bars shown on your screen.
/*+------------------------------------------------------------------+
| FileName:
| Author: Copyright © 2005,
| Version : 01 (Inital code)
|
+------------------------------------------------------------------+*/
#property copyright "Copyright © 2005, "
#property link "http://"
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Aqua
#property indicator_color2 Aqua
#property indicator_color3 Black
//---- input parameters
//---- buffers
double PrevDayHiBuffer[];
double PrevDayLoBuffer[];
double PrevDayOpenBuffer[];
int fontsize=10;
double PrevDayHi, PrevDayLo, PrevDayOpen;
double LastHigh,LastLow,x;
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- TODO: add your code here
ObjectDelete("PrevDayHi");
ObjectDelete("PrevDayLo");
ObjectDelete("PrevDayOpen");
//
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- indicator line
SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_LINE);
SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(0, PrevDayHiBuffer);
SetIndexBuffer(1, PrevDayLoBuffer);
SetIndexBuffer(2, PrevDayOpenBuffer);
//---- name for DataWindow and indicator subwindow label
short_name="Prev Hi-Lo levels";
IndicatorShortName(short_name);
SetIndexLabel(0, short_name);
//----
SetIndexDrawBegin(0,1);
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
int limit, i;
//---- indicator calculation
if (counted_bars==0)
{
x=Period();
if (x>240) return(-1);
ObjectCreate("PrevDayHi", OBJ_TEXT, 0, 0, 0);
ObjectSetText("PrevDayHi", " HIGH",fontsize,"Arial", Aqua);
ObjectCreate("PrevDayLo", OBJ_TEXT, 0, 0, 0);
ObjectSetText("PrevDayLo", " LOW",fontsize,"Arial", Aqua);
ObjectCreate("PrevDayOpen", OBJ_TEXT, 0, 0, 0);
ObjectSetText("PrevDayOpen", " OPEN",fontsize,"Arial", Red);
//---- last counted bar will be recounted
// if(counted_bars>0) counted_bars--;
}
limit=(Bars-counted_bars)-1;
for (i=limit; i>=0;i--)
{
if (High[i+1]>LastHigh) LastHigh=High[i+1];
if (Low[i+1]<LastLow) LastLow=Low[i+1];
//Print("TimeDay(Time[i]=",TimeDay(Time[i]),"TimeDay(Time[i+1])",TimeDay(Time[i+1]));
if (TimeDay(Time[i])!=TimeDay(Time[i+1]))
{
PrevDayHi=LastHigh;
PrevDayLo=LastLow;
PrevDayOpen=Open[i];
LastLow=Open[i];
LastHigh=Open[i];
ObjectMove("PrevDayHi", 0, Time[i], PrevDayHi);
ObjectMove("PrevDayLo", 0, Time[i], PrevDayLo);
ObjectMove("PrevDayOpen", 0, Time[i], PrevDayOpen);
}
PrevDayHiBuffer[i]=PrevDayHi;
PrevDayLoBuffer[i]=PrevDayLo;
PrevDayOpenBuffer[i]=PrevDayOpen;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments