Pivot_ESAZ_Day_v1
Download scriptThis script is a professional technical analysis tool designed for the MetaTrader platform. Its primary purpose is to automatically calculate and visualize specific "Pivot Points" on a trading chart. These levels are essential for traders who want to identify potential areas of support (where price might stop falling) and resistance (where price might stop rising).
Core Logic Overview
The script operates by analyzing historical daily price data to establish a framework for the current and upcoming trading days. It looks at three primary components from previous sessions: the High, the Low, and the Closing price. By combining these figures, it calculates a central "Pivot" point and then projects several levels above and below that point.
Key Functionalities
1. Automated Level Calculation Instead of requiring manual entry, the script automatically identifies the price range of previous days. It uses this range to mathematically project:
- Resistance Levels (Upward): Multiple tiers of "ceiling" prices where selling pressure might increase.
- Support Levels (Downward): Multiple tiers of "floor" prices where buying interest might emerge.
- Central Pivot: The equilibrium point for the current price action.
2. Dynamic Visual Mapping The tool is designed to be highly visual. It creates and draws various geometric objects on your chart, including:
- Horizontal Lines: Clear markers for all calculated support and resistance tiers.
- Vertical Guidelines: Time-based markers that help orient the trader with the start and end of specific trading periods.
- Price Markers: Specific dots or arrows that highlight key price coordinates immediately upon the start of a new day.
3. Multi-Day History The script is not limited to just one day at a time. It can be configured to display levels for multiple preceding days (based on user input). This allows traders to see a "map" of historical levels, helping them identify clusters where significant price action has occurred in the past.
4. Real-Time Management To ensure the chart remains clean and relevant, the script includes an automated cleanup routine. Every time the day changes or new data is processed, it clears out old visual objects before drawing the new ones. This prevents the chart from becoming cluttered with expired information while ensuring the most recent data is always accurate.
Summary for the Trader
Essentially, this tool acts as a navigation map. It takes complex daily price statistics and simplifies them into a visual set of "boundaries." By looking at these lines, a trader can quickly see where the market is likely to react, helping to inform entry and exit decisions based on established technical zones.
//+------------------------------------------------------------------+
//| Pivot_ESAZ_Day.mq4 |
//| DimDimych |
//| http://goodservice.su/forum/25-3550-1 |
//+------------------------------------------------------------------+
#property copyright "DimDimych"
#property link "http://goodservice.su/forum/25-3550-1"
#property indicator_chart_window
//---- input parameters
extern int CountDays =1;
extern int GMT =0;
extern color pivot =Gold;
extern color day =Yellow;
extern color level_up =DodgerBlue;
extern color level_dn =Tomato;
extern color setka =Lime;
extern color metka =MidnightBlue;
//---- indicator buffers
double range[];
double ny_close[];
double low[];
double high[];
datetime time1;
datetime time2;
datetime ny_time[];
int shift, num;
int ny_shift[];
datetime prevDay=0;
bool fTime;
// ----
void ObjDel()
{
if (ObjectsTotal() > 0)
for (num=0;num<=CountDays;num++)
{
ObjectDelete("PPw["+num+"]");
ObjectDelete("R1w["+num+"]");
ObjectDelete("R2w["+num+"]");
ObjectDelete("R3w["+num+"]");
ObjectDelete("R4w["+num+"]");
ObjectDelete("S1w["+num+"]");
ObjectDelete("S2w["+num+"]");
ObjectDelete("S3w["+num+"]");
ObjectDelete("S4w["+num+"]");
ObjectDelete("GL1w["+num+"]");
ObjectDelete("GL2w["+num+"]");
ObjectDelete("GL3w["+num+"]");
ObjectDelete("GL4w["+num+"]");
ObjectDelete("GL5w["+num+"]");
ObjectDelete("GL6w["+num+"]");
ObjectDelete("GL7w["+num+"]");
ObjectDelete("GL8w["+num+"]");
ObjectDelete("GL9w["+num+"]");
ObjectDelete("GL10w["+num+"]");
ObjectDelete("GL11w["+num+"]");
ObjectDelete("GL12w["+num+"]");
ObjectDelete("GL13w["+num+"]");
ObjectDelete("GL14w["+num+"]");
ObjectDelete("GL15w["+num+"]");
ObjectDelete("GL16w["+num+"]");
ObjectDelete("pV["+num+"]");
}
ObjectDelete("mPw");
ObjectDelete("mR1w");
ObjectDelete("mR2w");
ObjectDelete("mR3w");
ObjectDelete("mR4w");
ObjectDelete("mS1w");
ObjectDelete("mS2w");
ObjectDelete("mS3w");
ObjectDelete("mS4w");
ObjectDelete("pV0");
}
// ----
void PlotLine(string name,double value,double value1,double line_color,double style)
{
double valueN=NormalizeDouble(value,Digits);
double valueN1=NormalizeDouble(value1,Digits);
bool res = ObjectCreate(name,OBJ_TREND,0,time1,valueN,time2,valueN1);
ObjectSet(name, OBJPROP_WIDTH, 1);
ObjectSet(name, OBJPROP_STYLE, style);
ObjectSet(name, OBJPROP_RAY, false);
ObjectSet(name, OBJPROP_BACK, true);
ObjectSet(name, OBJPROP_COLOR, line_color);
}
//***********
void PlotVLine(string name,double tm,double line_color)
{
bool res = ObjectCreate(name,OBJ_VLINE,0,tm,0);
ObjectSet(name, OBJPROP_WIDTH, 0);
ObjectSet(name, OBJPROP_STYLE, 2);
ObjectSet(name, OBJPROP_COLOR, line_color);
}
//***********
void PlotPrice(string name, double value, double line_color)
{
double valueN=NormalizeDouble(value,Digits);
bool res = ObjectCreate(name, OBJ_ARROW, 0, time2,valueN);
ObjectSet(name, OBJPROP_COLOR, line_color);
ObjectSet(name, OBJPROP_WIDTH, 1);
ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_RIGHTPRICE);
}
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
fTime = true;
IndicatorBuffers(2);
SetIndexBuffer(0,range);
SetIndexBuffer(1,ny_close);
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
ObjDel();
Comment("");
return(0);
}
//+------------------------------------------------------------------+
//| LNX_Pivots_v3.1 |
//+------------------------------------------------------------------+
int start()
{
int i;
double P,R1,R2,R3,R4,S1,S2,S3,S4;
datetime cDay = iTime(NULL,PERIOD_D1,0) + (GMT-Period()/60.0)*3600;
if (cDay != prevDay || fTime)
{
ObjDel();
ArrayResize(ny_time,CountDays+1);
ArrayResize(ny_shift,CountDays+1);
ArrayResize(high,CountDays+1);
ArrayResize(low,CountDays+1);
ArrayResize(range,CountDays+1);
for (shift=0;shift<=CountDays;shift++)
{
ny_time[shift] = iTime(NULL,PERIOD_D1,shift) + (GMT-Period()/60.0)*3600;
ny_shift[shift] = iBarShift(NULL,0,ny_time[shift]);
ny_close[shift] = iClose(NULL,0,ny_shift[shift]);
}
for (shift=0;shift<=CountDays-1;shift++)
{
int length = ny_shift[shift+1]-ny_shift[shift];
high[shift] = High[iHighest(NULL,0,MODE_HIGH,length,ny_shift[shift])];
low[shift] = Low[iLowest(NULL,0,MODE_LOW,length,ny_shift[shift])];
range[shift] = high[shift] - low[shift];
}
for (shift=0;shift<=CountDays-1;shift++)
{
P = (ny_close[shift]+high[shift]+low[shift])/3;
Comment(range[0]/Point);
time1 = ny_time[shift]+Period()*60;
if (shift==0)
{
time2 = ny_time[shift] + 24*3600+Period()*60 ;
PlotVLine("pV0",time2,day);
PlotPrice("mPw",P,metka);
PlotPrice("mR1w",P+range[shift]/2,metka);
PlotPrice("mR2w",P+range[shift],metka);
PlotPrice("mS1w",P-range[shift]/2,metka);
PlotPrice("mS2w",P-range[shift],metka);
PlotPrice("mR3w",P+range[shift]+range[shift]/2,metka);
PlotPrice("mR4w",P+range[shift]*2,metka);
PlotPrice("mS3w",P-range[shift]-range[shift]/2,metka);
PlotPrice("mS4w",P-range[shift]*2,metka);
}
else
time2 = ny_time[shift-1]+Period()*60;
PlotVLine("pV["+shift+"]",time1,day);
int pstyle=0;
PlotLine("PPw["+shift+"]",P,P,pivot,pstyle);
PlotLine("R1w["+shift+"]",P+range[shift]/2, P+range[shift]/2,level_up,pstyle);
PlotLine("R2w["+shift+"]",P+range[shift], P+range[shift],level_up,pstyle);
PlotLine("R3w["+shift+"]",P+range[shift]+range[shift]/2, P+range[shift]+range[shift]/2,level_up,pstyle);
PlotLine("R4w["+shift+"]",P+range[shift]*2, P+range[shift]*2,level_up,pstyle);
PlotLine("S1w["+shift+"]",P-range[shift]/2, P-range[shift]/2,level_dn,pstyle);
PlotLine("S2w["+shift+"]",P-range[shift], P-range[shift],level_dn,pstyle);
PlotLine("S3w["+shift+"]",P-range[shift]-range[shift]/2, P-range[shift]-range[shift]/2,level_dn,pstyle);
PlotLine("S4w["+shift+"]",P-range[shift]*2, P-range[shift]*2,level_dn,pstyle);
PlotLine("GL1w["+shift+"]",P, P+range[shift]/2,setka,pstyle);
PlotLine("GL2w["+shift+"]",P+range[shift]/2, P+range[shift],setka,pstyle);
PlotLine("GL3w["+shift+"]",P+range[shift], P+range[shift]+range[shift]/2,setka,pstyle);
PlotLine("GL4w["+shift+"]",P+range[shift]+range[shift]/2,P+range[shift]*2,setka,pstyle);
PlotLine("GL5w["+shift+"]",P+range[shift]/2, P,setka,pstyle);
PlotLine("GL6w["+shift+"]",P+range[shift], P+range[shift]/2,setka,pstyle);
PlotLine("GL7w["+shift+"]",P+range[shift]+range[shift]/2,P+range[shift],setka,pstyle);
PlotLine("GL8w["+shift+"]",P+range[shift]*2, P+range[shift]+range[shift]/2,setka,pstyle);
PlotLine("GL9w["+shift+"]",P, P-range[shift]/2,setka,pstyle);
PlotLine("GL10w["+shift+"]",P-range[shift]/2, P-range[shift],setka,pstyle);
PlotLine("GL11w["+shift+"]",P-range[shift], P-range[shift]-range[shift]/2,setka,pstyle);
PlotLine("GL12w["+shift+"]",P-range[shift]-range[shift]/2,P-range[shift]*2,setka,pstyle);
PlotLine("GL13w["+shift+"]",P-range[shift]/2, P,setka,pstyle);
PlotLine("GL14w["+shift+"]",P-range[shift], P-range[shift]/2,setka,pstyle);
PlotLine("GL15w["+shift+"]",P-range[shift]-range[shift]/2,P-range[shift],setka,pstyle);
PlotLine("GL16w["+shift+"]",P-range[shift]*2, P-range[shift]-range[shift]/2,setka,pstyle);
}
fTime = false;
prevDay = cDay;
}
return(0);
}
//+------------------------------------------------------------------+
Comments