_OHMLC
Download scriptThis script is designed as a specialized trading tool for MetaTrader that automatically calculates and visualizes key price milestones based on historical data. It essentially breaks down the price action of a specific timeframe (such as a daily candle) into its core components to help traders identify important structural levels at a glance.
Core Functionality
1. Automated Level Calculation The tool scans the price history of your chosen period to extract four critical data points: the Open, High, Low, and Close prices. Using these, it mathematically derives several "Pivot" levels:
- Resistance Levels: Identifies the High point and the Open price as primary reference points.
- Mid-Point: Calculates the exact halfway mark between the day's High and Low.
- Support Levels: Identifies the Low point and the Closing price as secondary reference points.
2. Dynamic Visual Dashboard (The Gauge) One of the primary features is a clean, on-screen text dashboard (the "Gauge"). Instead of forcing you to look at complex lines across the whole chart, it creates a organized list in a corner of your screen. This dashboard displays:
- The specific price values for each calculated level (Open, High, Mid-Pt, Low, and Close).
- Real-time labels that clarify what each price represents.
3. Intelligent Color Coding To help with quick decision-making, the script uses a dynamic coloring system. It compares the current closing price against the calculated levels:
- If the current price is trading below certain key thresholds, the indicator changes the color of those specific labels (e.g., switching to Lime).
- This provides an immediate visual cue regarding the asset's position relative to established support and resistance zones.
4. Chart Plotting Options The script offers flexibility in how it presents data:
- Visual Markers: It can place specific symbols (arrows/wingdings) directly on the price candles where these key levels occur.
- Toggleable Features: You can choose to have the data displayed as a floating dashboard, as actual plot points on the chart, or both simultaneously, depending on your preferred trading style.
Summary for the Trader
In simple terms, this tool removes the manual math from your trading routine. Instead of calculating where the "middle" of a day's range is or identifying exactly where the previous candle closed, the script does it instantly and displays that information in an easy-to-read, color-coded summary on your screen. It helps you see the "skeleton" of the market's price movement clearly.
//+------------------------------------------------------------------+
//| _OHMLC |
//| |
//| |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_color1 White
#property indicator_color2 Lime
#property indicator_color3 MediumTurquoise
#property indicator_color4 Red
#property indicator_color5 Yellow
#property indicator_color6 Orange
#property indicator_color7 OrangeRed
//---- For the small screens
//extern string Display_infos = "=== If true, displayed on the chart ===";
//extern bool display_on_chart = true ; // If true, the open trade analysis, daily pivots and daily range will be displayed on the chart window
// indicators parameters
extern bool iPlotChart = false ;
extern bool iPlotGauge = true ;
extern int myPeriod = 1440 ;
extern int myChartY = 150 ;
extern int myStyle = 2 ;
extern int myWingDing = 115 ;
extern int myOffset = 1 ;
// indicators parameters
//---- buffers
double P1Buffer[];
double P2Buffer[];
double P3Buffer[];
double P4Buffer[];
double P5Buffer[];
double P6Buffer[];
double P7Buffer[];
//int myPeriod = PERIOD_D1;
int TimeZone=0;
bool pivots = true;
bool alert = true;
double yesterday_high=0;
double yesterday_open=0;
double yesterday_low=0;
double yesterday_close=0;
double today_open=0;
double today_high=0;
double today_low=0;
double rates_h1[2][6];
double rates_d1[2][6];
double Q,H,L,F;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- name for indicator window
string short_name=" ";
IndicatorShortName(short_name);
SetIndexBuffer(0, P1Buffer);
SetIndexBuffer(1, P2Buffer);
SetIndexBuffer(2, P3Buffer);
SetIndexBuffer(3, P4Buffer);
SetIndexBuffer(4, P5Buffer);
SetIndexBuffer(5, P6Buffer);
SetIndexBuffer(6, P7Buffer);
//----
SetIndexArrow(0, myWingDing);
SetIndexArrow(1, myWingDing);
SetIndexArrow(2, myWingDing);
SetIndexArrow(3, myWingDing);
SetIndexArrow(4, myWingDing);
SetIndexArrow(5, myWingDing);
SetIndexArrow(6, myWingDing);
SetIndexStyle(0, DRAW_ARROW, myStyle, 1);
SetIndexStyle(1, DRAW_ARROW, myStyle, 1);
SetIndexStyle(2, DRAW_ARROW, myStyle, 1);
SetIndexStyle(3, DRAW_ARROW, myStyle, 1);
SetIndexStyle(4, DRAW_ARROW, myStyle, 1);
SetIndexStyle(5, DRAW_ARROW, myStyle, 1);
SetIndexStyle(6, DRAW_ARROW, myStyle, 1);
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int j,total=OrdersTotal();
for(j=0;j<total;j++)
{
OrderSelect(j, SELECT_BY_POS, MODE_TRADES);
}
double x;
int i, dayi, counted_bars = IndicatorCounted();
//---- check for possible errors
if(counted_bars < 0)
return(-1);
//---- last counted bar will be recounted
if(counted_bars > 0)
counted_bars--;
int limit = Bars - counted_bars;
//----
for(i = limit - 1; i >= 0; i--)
{
dayi = iBarShift(Symbol(), myPeriod, Time[i], false);
// int dayi = iBarShift(Symbol(), myPeriod, Time[0], false);
// double yesterday_open = iOpen(Symbol(), myPeriod,dayi + 1);
// double yesterday_high = iHigh(Symbol(), myPeriod,dayi + 1);
// double yesterday_low = iLow(Symbol(), myPeriod,dayi + 1);
// double yesterday_close = iClose(Symbol(), myPeriod,dayi + 1);
double day_high = iHigh(Symbol(), myPeriod,dayi + myOffset );
double day_low = iLow(Symbol(), myPeriod,dayi + myOffset );
double day_close = iClose(Symbol(), myPeriod,dayi + myOffset );
double day_open = iOpen(Symbol(), myPeriod,dayi + myOffset );
double xRange = (day_high - day_low) ;
double xMid = (day_high + day_low)*0.50 ;
double R3 = day_open ; // Open
double R2 = day_high ; // High
double R1 = xMid ; // Middle
double P = day_low ; // Low
double S1 = day_close ; // Close
// double S2 = yesterday_low - (xRange * 0.382 ) ; // fib 382
// double S3 = yesterday_low - (xRange * 0.618 ) ; // fib 618
if ( iPlotChart ) {
P1Buffer[i] = R3 ;
P2Buffer[i] = R2 ;
P3Buffer[i] = R1 ;
P4Buffer[i] = P ;
P5Buffer[i] = S1 ;
// P6Buffer[i] = S2 ;
// P7Buffer[i] = S3 ;
}
} // iPlotChart
if ( iPlotGauge ) {
color color_r3=Red;
color color_r2=Red;
color color_r1=Red;
color color_p =Red;
color color_s1=Red;
color color_s2=Red;
color color_s3=Red;
if( day_close < R3) { color_r3=Lime; }
if( day_close < R2) { color_r2=Lime; }
if( day_close < R1) { color_r1=Lime; }
if( day_close < P ) { color_p=Lime; }
if( day_close < S1) { color_s1=Lime; }
// if( day_close < S2) { color_s2=Lime; }
// if( day_close < S3) { color_s3=Lime; }
int Precision, dig;
if( StringFind( Symbol(), "JPY", 0) != -1 ) { Precision = 100; dig = 2;}
else { Precision = 10000; dig = 4; }
color color_common_line = White;
color color_common_text = White;
color color_ind = PowderBlue;
color color_indic;
color color_title =Orchid;
int sPeriod= Period();
if (myPeriod != NULL){ sPeriod= myPeriod ; color_title=Yellow; }
//---- Set Pivots labels
int WindowToUse;
int Corner_line, Xdist_line;
int Corner_text, Corner_ValueOHMLC, Xdist_text, Xdist_ValueOHMLC;
int Ydist_line5;
int Corner_pivots, Xdist_pivots, Ydist_pivots;
int Ydist_R3, Ydist_R2, Ydist_R1, Ydist_PV, Ydist_S1, Ydist_S2, Ydist_S3;
int YdistInc ;
WindowToUse = 0;
Corner_line = 1;
Corner_text = 1; Corner_ValueOHMLC = 1;
Xdist_line = 21; Xdist_text = 93; Xdist_ValueOHMLC = 23;
Corner_pivots = 1; Xdist_pivots = 21;
Ydist_pivots = myChartY;
Ydist_line5 = Ydist_pivots + 11; YdistInc = 15 ;
Ydist_R3 = Ydist_pivots + 25;
Ydist_R2 = Ydist_R3 + YdistInc;
Ydist_R1 = Ydist_R3 + YdistInc*2;
Ydist_PV = Ydist_R3 + YdistInc*3;
Ydist_S1 = Ydist_R3 + YdistInc*4;
Ydist_S2 = Ydist_R3 + YdistInc*5;
Ydist_S3 = Ydist_R3 + YdistInc*6;
ObjectCreate("OHMLC", OBJ_LABEL, WindowToUse, 0, 0);
ObjectSetText("OHMLC",sPeriod + " OHMLC ",9, "Verdana", color_title);
ObjectSet("OHMLC", OBJPROP_CORNER, Corner_pivots);
ObjectSet("OHMLC", OBJPROP_XDISTANCE, Xdist_pivots);
ObjectSet("OHMLC", OBJPROP_YDISTANCE, Ydist_pivots);
ObjectCreate("line5OHMLC", OBJ_LABEL, WindowToUse, 0, 0);
ObjectSetText("line5OHMLC","---------------------",7, "Verdana", color_title);
ObjectSet("line5OHMLC", OBJPROP_CORNER, Corner_line);
ObjectSet("line5OHMLC", OBJPROP_XDISTANCE, Xdist_line);
ObjectSet("line5OHMLC", OBJPROP_YDISTANCE, Ydist_line5);
ObjectCreate("R3_LabelOHMLC", OBJ_LABEL, WindowToUse, 0, 0);
ObjectSetText("R3_LabelOHMLC","Open",9, "Verdana", White);
ObjectSet("R3_LabelOHMLC", OBJPROP_CORNER, Corner_text);
ObjectSet("R3_LabelOHMLC", OBJPROP_XDISTANCE, Xdist_text);
ObjectSet("R3_LabelOHMLC", OBJPROP_YDISTANCE, Ydist_R3);
ObjectCreate("R3_ValueOHMLC", OBJ_LABEL, WindowToUse, 0, 0);
ObjectSetText("R3_ValueOHMLC"," "+DoubleToStr(R3,dig),9, "Verdana", color_r3);
ObjectSet("R3_ValueOHMLC", OBJPROP_CORNER, Corner_ValueOHMLC);
ObjectSet("R3_ValueOHMLC", OBJPROP_XDISTANCE, Xdist_ValueOHMLC);
ObjectSet("R3_ValueOHMLC", OBJPROP_YDISTANCE, Ydist_R3);
ObjectCreate("R2_LabelOHMLC", OBJ_LABEL, WindowToUse, 0, 0);
ObjectSetText("R2_LabelOHMLC","High",9, "Verdana", Lime);
ObjectSet("R2_LabelOHMLC", OBJPROP_CORNER, Corner_text);
ObjectSet("R2_LabelOHMLC", OBJPROP_XDISTANCE, Xdist_text);
ObjectSet("R2_LabelOHMLC", OBJPROP_YDISTANCE, Ydist_R2);
ObjectCreate("R2_ValueOHMLC", OBJ_LABEL, WindowToUse, 0, 0);
ObjectSetText("R2_ValueOHMLC"," "+DoubleToStr(R2,dig),9, "Verdana", color_r2);
ObjectSet("R2_ValueOHMLC", OBJPROP_CORNER, Corner_ValueOHMLC);
ObjectSet("R2_ValueOHMLC", OBJPROP_XDISTANCE, Xdist_ValueOHMLC);
ObjectSet("R2_ValueOHMLC", OBJPROP_YDISTANCE, Ydist_R2);
ObjectCreate("R1_LabelOHMLC", OBJ_LABEL, WindowToUse, 0, 0);
ObjectSetText("R1_LabelOHMLC","Mid Pt",9, "Verdana", MediumTurquoise );
ObjectSet("R1_LabelOHMLC", OBJPROP_CORNER, Corner_text);
ObjectSet("R1_LabelOHMLC", OBJPROP_XDISTANCE, Xdist_text);
ObjectSet("R1_LabelOHMLC", OBJPROP_YDISTANCE, Ydist_R1);
ObjectCreate("R1_ValueOHMLC", OBJ_LABEL, WindowToUse, 0, 0);
ObjectSetText("R1_ValueOHMLC"," "+DoubleToStr(R1,dig),9, "Verdana", color_r1);
ObjectSet("R1_ValueOHMLC", OBJPROP_CORNER, Corner_ValueOHMLC);
ObjectSet("R1_ValueOHMLC", OBJPROP_XDISTANCE, Xdist_ValueOHMLC);
ObjectSet("R1_ValueOHMLC", OBJPROP_YDISTANCE, Ydist_R1);
ObjectCreate("Pivot_LabelOHMLC", OBJ_LABEL, WindowToUse, 0, 0);
ObjectSetText("Pivot_LabelOHMLC","Low",9, "Verdana", Red);
ObjectSet("Pivot_LabelOHMLC", OBJPROP_CORNER, Corner_text);
ObjectSet("Pivot_LabelOHMLC", OBJPROP_XDISTANCE, Xdist_text);
ObjectSet("Pivot_LabelOHMLC", OBJPROP_YDISTANCE, Ydist_PV);
ObjectCreate("Pivot_ValueOHMLC", OBJ_LABEL, WindowToUse, 0, 0);
ObjectSetText("Pivot_ValueOHMLC"," "+DoubleToStr(P,dig),9, "Verdana", color_p);
ObjectSet("Pivot_ValueOHMLC", OBJPROP_CORNER, Corner_ValueOHMLC);
ObjectSet("Pivot_ValueOHMLC", OBJPROP_XDISTANCE, Xdist_ValueOHMLC);
ObjectSet("Pivot_ValueOHMLC", OBJPROP_YDISTANCE, Ydist_PV);
ObjectCreate("S1_LabelOHMLC", OBJ_LABEL, WindowToUse, 0, 0);
ObjectSetText("S1_LabelOHMLC","Close",9, "Verdana", Yellow);
ObjectSet("S1_LabelOHMLC", OBJPROP_CORNER, Corner_text);
ObjectSet("S1_LabelOHMLC", OBJPROP_XDISTANCE, Xdist_text);
ObjectSet("S1_LabelOHMLC", OBJPROP_YDISTANCE, Ydist_S1);
ObjectCreate("S1_ValueOHMLC", OBJ_LABEL, WindowToUse, 0, 0);
ObjectSetText("S1_ValueOHMLC"," "+DoubleToStr(S1,dig),9, "Verdana", color_s1);
ObjectSet("S1_ValueOHMLC", OBJPROP_CORNER, Corner_ValueOHMLC);
ObjectSet("S1_ValueOHMLC", OBJPROP_XDISTANCE, Xdist_ValueOHMLC);
ObjectSet("S1_ValueOHMLC", OBJPROP_YDISTANCE, Ydist_S1);
/*
ObjectCreate("S2_LabelOHMLC", OBJ_LABEL, WindowToUse, 0, 0);
ObjectSetText("S2_LabelOHMLC","-.382",9, "Verdana", Orange);
ObjectSet("S2_LabelOHMLC", OBJPROP_CORNER, Corner_text);
ObjectSet("S2_LabelOHMLC", OBJPROP_XDISTANCE, Xdist_text);
ObjectSet("S2_LabelOHMLC", OBJPROP_YDISTANCE, Ydist_S2);
ObjectCreate("S2_ValueOHMLC", OBJ_LABEL, WindowToUse, 0, 0);
ObjectSetText("S2_ValueOHMLC"," "+DoubleToStr(S2,dig),9, "Verdana", color_s2);
ObjectSet("S2_ValueOHMLC", OBJPROP_CORNER, Corner_ValueOHMLC);
ObjectSet("S2_ValueOHMLC", OBJPROP_XDISTANCE, Xdist_ValueOHMLC);
ObjectSet("S2_ValueOHMLC", OBJPROP_YDISTANCE, Ydist_S2);
ObjectCreate("S3_LabelOHMLC", OBJ_LABEL, WindowToUse, 0, 0);
ObjectSetText("S3_LabelOHMLC","-.618",9, "Verdana", OrangeRed);
ObjectSet("S3_LabelOHMLC", OBJPROP_CORNER, Corner_text);
ObjectSet("S3_LabelOHMLC", OBJPROP_XDISTANCE, Xdist_text);
ObjectSet("S3_LabelOHMLC", OBJPROP_YDISTANCE, Ydist_S3);
ObjectCreate("S3_ValueOHMLC", OBJ_LABEL, WindowToUse, 0, 0);
ObjectSetText("S3_ValueOHMLC"," "+DoubleToStr(S3,dig),9, "Verdana", color_s3);
ObjectSet("S3_ValueOHMLC", OBJPROP_CORNER, Corner_ValueOHMLC);
ObjectSet("S3_ValueOHMLC", OBJPROP_XDISTANCE, Xdist_ValueOHMLC);
ObjectSet("S3_ValueOHMLC", OBJPROP_YDISTANCE, Ydist_S3);
*/
} // iPlotGauge
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
ObjectDelete("R3_LabelOHLMC");
ObjectDelete("R3_ValueOHLMC");
ObjectDelete("R2_LabelOHLMC");
ObjectDelete("R2_ValueOHLMC");
ObjectDelete("R1_LabelOHLMC");
ObjectDelete("R1_ValueOHLMC");
ObjectDelete("Pivot_LabelOHLMC");
ObjectDelete("Pivot_ValueOHLMC");
ObjectDelete("S1_LabelOHLMC");
ObjectDelete("S1_ValueOHLMC");
ObjectDelete("S2_LabelOHLMC");
ObjectDelete("S2_ValueOHLMC");
ObjectDelete("S3_LabelOHLMC");
ObjectDelete("S3_ValueOHLMC");
ObjectDelete("OHMLC");
ObjectDelete("line5OHMLC");
return(0);
}
Comments