This technical indicator is designed to help traders visualize key price milestones from the previous trading day directly on their current charts. By identifying these specific levels, it provides a clear visual reference for market structure and potential support or resistance zones.
Core Functionality
The primary purpose of this script is to automatically track and display three critical data points from the preceding day's price action:
- Previous Day High: The highest price reached during the last 24-hour trading cycle.
- Previous Day Low: The lowest price reached during the last 24-hour trading cycle.
- Previous Day Open: The specific price at which the market began trading on the previous day.
How the Logic Works
The indicator operates by scanning historical price data and identifying transitions between different calendar days. It follows a specific logical flow to ensure accuracy:
- Data Scanning: The script moves backward through the price history, examining each candle's high and low values.
- Extreme Identification: As it scans, it constantly updates its internal "memory" of what the highest and lowest points are for the current day being analyzed.
- Day Transition Detection: The moment the script detects that the calendar date has changed (e.g., moving from yesterday to today), it "locks in" the high, low, and opening values from the completed day.
- Dynamic Plotting: Once these values are locked, the script draws three distinct lines on your chart. These lines correspond to the previous day's highs, lows, and opening price, allowing you to see exactly where those boundaries sit in relation to today’s live price movement.
Visual Presentation
To ensure the information is easy to read at a glance:
- High and Low Levels: These are displayed in Aqua, making them stand out as primary boundary markers.
- Opening Level: The Previous Day Open is highlighted in Red, providing a distinct visual contrast to help differentiate it from the high/low boundaries.
- Labels: The script automatically places text labels on the chart (e.g., "Prev. Day High") so there is no ambiguity about what each line represents.
Practical Use for Traders
By automating this process, the indicator removes the need for manual calculation or looking back at historical charts to find previous price levels. It provides a "clean" view of the market's previous boundaries, which many traders use to identify breakout points, reversals, or areas where price might stall.
/*+------------------------------------------------------------------+
| FileName: i_DCG_Camarilla.mq4
| Author: Copyright © 2005, Fermin Da Costa Gomez
| Version : 01 (Inital code)
|
+------------------------------------------------------------------+*/
#property copyright "Copyright © 2005, Fermin Da Costa Gomez"
#property link "http://forex.viahetweb.nl"
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Aqua
#property indicator_color2 Aqua
#property indicator_color3 Red
//---- 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", " Prev. Day High",fontsize,"Arial", Aqua);
ObjectCreate("PrevDayLo", OBJ_TEXT, 0, 0, 0);
ObjectSetText("PrevDayLo", " Prev. Day Low",fontsize,"Arial", Aqua);
ObjectCreate("PrevDayOpen", OBJ_TEXT, 0, 0, 0);
ObjectSetText("PrevDayOpen", " Prev. Day 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