_255ePivot_ResSup2
Download scriptThis script is designed to automatically identify and plot key price levels on your trading chart based on the previous day's market activity. It specifically focuses on "Pivot," "Resistance," and "Support" levels, which are essential landmarks that traders use to gauge market sentiment and potential reversal points.
How the Logic Works
The tool operates by analyzing the price data from the completed trading session of the previous day to establish boundaries for the current day. Here is the step-by-step breakdown of its logic:
1. Identifying the Previous Day's Range The script scans the historical data to find the exact beginning and end of the previous trading day. It identifies three critical pieces of information from that period:
- The highest price reached (High).
- The lowest price reached (Low).
- The closing price (Close).
2. Calculating Key Price Points Once it has those three values, the script uses a mathematical formula to calculate a central "Pivot" point. Depending on the user's settings, it chooses between two different calculation methods to determine this center:
- Standard Method: A simple average of the high, low, and close prices.
- Modified Method: A weighted average that places more significance on the closing price of the previous day.
3. Projecting Support and Resistance After establishing the central Pivot point, the script calculates two outer boundaries:
- Resistance Level: The upper boundary, calculated by adding the range of the previous day's movement to the pivot point.
- Support Level: The lower boundary, calculated by subtracting that same range from the pivot point.
4. Visualizing on the Chart The script is programmed to "carry over" these levels onto your current chart. Instead of disappearing when a new day starts, the levels remain visible as horizontal markers. This allows you to see exactly where the "ceiling" (Resistance) and "floor" (Support) sit for the current trading session based on yesterday's performance.
5. Operational Constraints To ensure accuracy, the script is optimized for specific timeframes. It is designed to work effectively on lower timeframes (such as 1-hour or smaller) by calculating daily data and projecting it forward, providing a clear visual map of where price might encounter friction during your active trading hours.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| ^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 2
#property indicator_color1 LightBlue
#property indicator_color2 Magenta
//---- 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 ExtMapBuffer1[];
double ResBuffer[];
double SupBuffer[];
//+------------------------------------------------------------------+
//| Ïðîâåðêà íîâîãî äíÿ |
//+------------------------------------------------------------------+
bool isNewDay(int _shift)
{
//----
result=false;
if ( (TimeHour(Time[_shift])==0) && (TimeMinute(Time[_shift])==0) ) result=true;
//----
return(result);
}
//+------------------------------------------------------------------+
//| Ïîëó÷èòü óðîâíè FP,Res1 è Sup1 ïðîøåäøåãî äíÿ |
//+------------------------------------------------------------------+
void GetRS2ofDay(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);
ResBuffer[_shift]=NormalizeDouble(FP+(FH-FL),Digits);
SupBuffer[_shift]=NormalizeDouble(FP-(FH-FL),Digits);
//----
}
//+------------------------------------------------------------------+
//| Êîïèðîâàòü FP,Res1 è Sup1 ïðîøåäøåãî äíÿ |
//+------------------------------------------------------------------+
void CopyLevels2Day(int _shift)
{
ExtMapBuffer1[_shift]=ExtMapBuffer1[_shift];
ResBuffer[_shift]=ResBuffer[_shift+1];
SupBuffer[_shift]=SupBuffer[_shift+1];
}
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
if (Formula!=0)Formula=1;
string label1="Pivot_Res2("+Formula+")";
string label2="Pivot_Sup2("+Formula+")";
//---- indicators
IndicatorBuffers(2);
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,160);
SetIndexBuffer(0,ResBuffer);
SetIndexEmptyValue(0,0.0);
SetIndexLabel(0,label2);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1,160);
SetIndexBuffer(1,SupBuffer);
SetIndexEmptyValue(1,0.0);
SetIndexLabel(1,label2);
SetIndexBuffer(0,ExtMapBuffer1);
//----
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)) GetRS2ofDay(shift); else CopyLevels2Day(shift);
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments