^Pivot_ResSup_v1
Download scriptThis script is designed to automatically identify and display key price levels on your trading chart based on the previous day's market activity. It focuses on calculating "Pivot Points," which are standard technical analysis tools used by traders to determine potential support and resistance areas for the current trading session.
Core Logic and Functionality
1. Identifying Daily Transitions The tool first monitors the time data to detect when a new trading day begins. By recognizing the transition between days, it knows exactly when to reset its calculations and generate a fresh set of price levels based on the most recently completed 24-hour period.
2. Data Collection from the Previous Day To determine where the price might move today, the script looks back at the previous day's price action. It specifically captures three key pieces of information:
- The highest price reached (High)
- The lowest price reached (Low)
- The closing price (Close)
3. Calculating Key Levels Once it has the High, Low, and Close prices from yesterday, it applies a specific mathematical formula to project five distinct levels onto your current chart:
- Pivot Point: The central "balance" level of the market.
- Resistance Levels (Res): Upper boundaries where the price might face selling pressure or struggle to climb higher.
- Support Levels (Sup): Lower boundaries where the price might find a "floor" and begin to bounce back up.
The script offers two different calculation modes (Formula 0 and Formula 1), allowing for slight variations in how the central Pivot Point is weighted between the daily high and low.
4. Visual Continuity To ensure the chart remains clean and easy to read, the script handles these levels intelligently:
- Automatic Updates: When a new day starts, it calculates the new numbers immediately.
- Persistence: During the rest of the trading day, the script carries those same calculated levels forward so they remain visible as constant reference points for your active session.
- Timeframe Awareness: The tool is optimized for intraday trading; it is programmed to only activate on timeframes shorter than 4 hours (such as 1-hour or 15-minute charts) to ensure the data remains relevant to short-term price movements.
Summary for the Trader
Essentially, this script automates the "manual" work of a floor trader. Instead of you having to calculate where the major support and resistance zones are every morning, the script looks at yesterday's performance and draws five clear horizontal guideposts on your screen, helping you identify where the market might react or reverse during the current day.
//+------------------------------------------------------------------+
//| ^Pivot_ResSup.mq4 |
//| Modest, Rosh conversed only |
//| http://forexsystems.ru/phpBB/index.php |
//+------------------------------------------------------------------+
#property copyright "Modest, Rosh conversed only"
#property link "http://forexsystems.ru/phpBB/index.php"
//// Ñòðîèì Pivot è Res/Supp ïî FibonacciTrader Journal Issue 6
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_color1 Aqua
#property indicator_color2 Aqua
#property indicator_color3 Red
#property indicator_color4 Aqua
#property indicator_color5 Aqua
//---- input parameters
extern int Formula=0;
int i=1, shift;
double FP=0.0;
double FH=0.0, FL=0.0;
bool result;
//---- buffers
double ResBuffer2[];
double ResBuffer[];
double ExtMapBuffer1[];
double SupBuffer[];
double SupBuffer2[];
//+------------------------------------------------------------------+
//| Ïðîâåðêà íîâîãî äíÿ |
//+------------------------------------------------------------------+
bool isNewDay(int _shift)
{
//----
result=false;
//if ( (TimeHour(Time[_shift])==0) && (TimeMinute(Time[_shift])==0) ) result=true;
// òàê^^ íå ðàáîòàåò ïðè îòñóòñòâèè áàðà 0:00 . Òàêîå èçðåäêà áûâàåò
if(TimeDay(Time[_shift])!=TimeDay(Time[_shift+1]))result=true;
//----
return(result);
}
//+------------------------------------------------------------------+
//| Ïîëó÷èòü óðîâíè FP,Res1,Sup1,Res2 è Sup2 ïðîøåäøåãî äíÿ |
//+------------------------------------------------------------------+
void GetRSofDay(int _shift)
{
int prevDay=TimeDay(Time[_shift+1]);
//----
i=1;
while(TimeDay(Time[_shift+i])==prevDay) i++;
i--;
FH=High[Highest(NULL,0,MODE_HIGH,i,_shift+1)];
FL=Low[Lowest(NULL,0,MODE_LOW,i,_shift+1)];
if (Formula==0) FP=NormalizeDouble((FH+FL+Close[_shift+1])/3.0,Digits); else FP=NormalizeDouble((FH+FL+2*Close[_shift+1])/4.0,Digits);
ExtMapBuffer1[_shift]=FP;
ResBuffer[_shift]=NormalizeDouble(FP+(FP-FL),Digits);
SupBuffer[_shift]=NormalizeDouble(FP-(FH-FP),Digits);
ResBuffer2[_shift]=NormalizeDouble(FP+(FH-FL),Digits);
SupBuffer2[_shift]=NormalizeDouble(FP-(FH-FL),Digits);
//----
}
//+------------------------------------------------------------------+
//| Êîïèðîâàòü FP,Res1,Sup1,Res2 è Sup2 ïðîøåäøåãî äíÿ |
//+------------------------------------------------------------------+
void CopyLevelsDay(int _shift)
{
ExtMapBuffer1[_shift]=ExtMapBuffer1[_shift+1];
ResBuffer[_shift]=ResBuffer[_shift+1];
SupBuffer[_shift]=SupBuffer[_shift+1];
ResBuffer2[_shift]=ResBuffer2[_shift+1];
SupBuffer2[_shift]=SupBuffer2[_shift+1];
}
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
if (Formula!=0)Formula=1;
string label1="Pivot_Res2("+Formula+")";
string label2="Pivot_Res("+Formula+")";
string label3="Pivot_Point("+Formula+")";
string label4="Pivot_Sup("+Formula+")";
string label5="Pivot_Sup2("+Formula+")";
//---- indicators
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,160);
SetIndexBuffer(0,ResBuffer2);
SetIndexEmptyValue(0,0.0);
SetIndexLabel(0,label1);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1,160);
SetIndexBuffer(1,ResBuffer);
SetIndexEmptyValue(1,0.0);
SetIndexLabel(1,label2);
SetIndexStyle(2,DRAW_ARROW,0,2);
SetIndexArrow(2,160);
SetIndexBuffer(2,ExtMapBuffer1);
SetIndexEmptyValue(2,0.0);
SetIndexLabel(2,label3);
SetIndexStyle(3,DRAW_ARROW);
SetIndexArrow(3,160);
SetIndexBuffer(3,SupBuffer);
SetIndexEmptyValue(3,0.0);
SetIndexLabel(3,label4);
SetIndexStyle(4,DRAW_ARROW);
SetIndexArrow(4,160);
SetIndexBuffer(4,SupBuffer2);
SetIndexEmptyValue(4,0.0);
SetIndexLabel(4,label5);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit,firstDay;
int counted_bars=IndicatorCounted();
if (counted_bars<0) return(0);
if (counted_bars==0)
{
limit=Bars-1;
i=1;
firstDay=TimeDay(Time[limit]);
while(TimeDay(Time[limit-i])==firstDay) i++;
limit=limit-i-PERIOD_D1/Period();
}
if (counted_bars>0) limit=Bars-counted_bars;
//----
if (Period()>PERIOD_H4) return;
for(shift=limit;shift>=0;shift--)
{
if (isNewDay(shift)) GetRSofDay(shift); else CopyLevelsDay(shift);
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments