This script is designed as a technical analysis tool for the MetaTrader platform, specifically created to identify key price levels known as "Pivot Points." These pivots serve as structural markers that help traders understand market sentiment and potential areas of support or resistance.
Core Logic and Functionality
The primary purpose of this tool is to automatically calculate and display a series of dynamic price levels based on the price action of previous trading sessions. Instead of relying on arbitrary numbers, the script uses historical data—specifically the highs, lows, and closing prices—to project where the market might find balance in the current session.
How it Works
1. Data Collection and Detection The tool monitors the price movement from bar to bar. It specifically looks for "session breaks"—moments when the calendar day changes. When a new day begins, the script captures the high point, low point, and closing price of the preceding period to use as the foundation for its calculations.
2. Pivot Point Generation Once the data from the previous session is captured, the script generates several standard pivot levels:
- The Main Pivot (P): A central balance point derived from the average of the previous high, low, and close.
- Resistance Levels (R1, R2, R3): These represent "ceilings" where price may face selling pressure.
- Support Levels (S1, S2, S3): These represent "floors" where price may find buying interest.
3. Midpoint Identification (M0–M5) Beyond the standard levels, this specific script performs additional calculations to identify the "Midpoints" between these major supports and resistances. It calculates five distinct midpoint lines (labeled M0 through M5). These finer markers allow for a more granular view of the market structure, showing the halfway points between significant zones.
4. Visual Representation The script handles all the heavy lifting by automatically calculating these values and plotting them on your chart in real-time. It creates visual labels and lines that update as new price data arrives, ensuring that you always have a clear view of the current day's structural boundaries without needing to perform manual math.
Summary for the User
In short, this tool acts as an automated "map maker." Every time a new trading day starts, it looks back at what happened previously and draws a series of gray horizontal reference lines on your chart. These lines represent the most statistically significant areas of interest, helping you visualize where the market is likely to react, stall, or reverse.
//+------------------------------------------------------------------+
//| Pivot (Midnight to Midnight)_M .mq4 |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Pivot.mq4 |
//| Copyright © 2004, Poul_Trade_Forum |
//| Aborigen |
//| http://forex.kbpauk.ru/ |
//+------------------------------------------------------------------+
#property copyright "Poul Trade Forum"
#property link "http://forex.kbpauk.ru/"
#property indicator_chart_window
//#property indicator_separate_window
#property indicator_buffers 7
#property indicator_color1 Gray
#property indicator_color2 Gray
#property indicator_color3 Gray
#property indicator_color4 Gray
#property indicator_color5 Gray
#property indicator_color6 Gray
//---- input parameters
//---- buffers
double M0Buffer[];
double M1Buffer[];
double M2Buffer[];
double M3Buffer[];
double M4Buffer[];
double M5Buffer[];
string m0="M 0", m1="M 1";
string m2="M 2", m3="M 3", m4="M 4", m5="M 5";
int fontsize=10;
double M0,M1,M2,M3,M4,M5;
double P,S1,R1,S2,R2,S3,R3;
double LastHigh,LastLow,x;
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- TODO: add your code here
ObjectDelete("m0");
ObjectDelete("m1");
ObjectDelete("m2");
ObjectDelete("m3");
ObjectDelete("m4");
ObjectDelete("m5");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
IndicatorBuffers(7);
//---- indicator line
SetIndexStyle(0,DRAW_LINE,0,0,Gray);
SetIndexStyle(1,DRAW_LINE,0,0,Gray);
SetIndexStyle(2,DRAW_LINE,0,0,Gray);
SetIndexStyle(3,DRAW_LINE,0,0,Gray);
SetIndexStyle(4,DRAW_LINE,0,0,Gray);
SetIndexStyle(5,DRAW_LINE,0,0,Gray);
SetIndexBuffer(0,M0Buffer);
SetIndexBuffer(1,M1Buffer);
SetIndexBuffer(2,M2Buffer);
SetIndexBuffer(3,M3Buffer);
SetIndexBuffer(4,M4Buffer);
SetIndexBuffer(5,M5Buffer);
//---- name for DataWindow and indicator subwindow label
short_name="Pivot Point M";
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("m0", OBJ_TEXT, 0, 0, 0);
ObjectSetText("m0", " M 1",fontsize,"Arial",White);
ObjectCreate("m1", OBJ_TEXT, 0, 0, 0);
ObjectSetText("m1", " M 2",fontsize,"Arial",White);
ObjectCreate("m2", OBJ_TEXT, 0, 0, 0);
ObjectSetText("m2", " M 3",fontsize,"Arial",White);
ObjectCreate("m3", OBJ_TEXT, 0, 0, 0);
ObjectSetText("m3", " M 4",fontsize,"Arial",White);
ObjectCreate("m4", OBJ_TEXT, 0, 0, 0);
ObjectSetText("m4", " M 5",fontsize,"Arial",White);
ObjectCreate("m5", OBJ_TEXT, 0, 0, 0);
ObjectSetText("m5", " M 6",fontsize,"Arial",White);
}
if(counted_bars<0) return(-1);
//---- 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];
if (TimeDay(Time[i])!=TimeDay(Time[i+1]))
{
P=(LastHigh+LastLow+Close[i+1])/3;
R1 = (2*P)-LastLow;
S1 = (2*P)-LastHigh;
R2 = P+(LastHigh - LastLow);
S2 = P-(LastHigh - LastLow);
R3 = (2*P)+(LastHigh-(2*LastLow));
S3 = (2*P)-((2* LastHigh)-LastLow);
M0 = (S2 + S3)/2;
M1 = (S1 + S2)/2;
M2 = (P + S1)/2;
M3 = (P + R1)/2;
M4 = (R1 + R2)/2;
M5 = (R2 + R3)/2;
LastLow=Open[i]; LastHigh=Open[i];
ObjectMove("m0", 0, Time[i],M0);
ObjectMove("m1", 0, Time[i],M1);
ObjectMove("m2", 0, Time[i],M2);
ObjectMove("m3", 0, Time[i],M3);
ObjectMove("m4", 0, Time[i],M4);
ObjectMove("m5", 0, Time[i],M5);
}
M0Buffer[i]=M0;
M1Buffer[i]=M1;
M2Buffer[i]=M2;
M3Buffer[i]=M3;
M4Buffer[i]=M4;
M5Buffer[i]=M5;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments