Floor_Pivots_Weekly_Mid
Download scriptThis script is designed for the MetaTrader platform to automate the calculation and visual display of specific "Pivot Points"—key price levels used by traders to identify potential support and resistance areas. Specifically, this tool focuses on weekly calculations, helping users see important price zones based on the previous week's market activity.
How the Logic Works
The script operates by analyzing historical price data (Highs, Lows, and Closing prices) to project specific levels onto your current chart. Here is the step-by-step breakdown of its logic:
1. Weekly Identification The script constantly scans the price history to find the start of a new trading week (specifically identifying Mondays). Once it detects a new week, it gathers the high, low, and closing prices from the preceding week.
2. Core Pivot Calculations Using those three values from last week, the script calculates several standard "Floor Pivot" points:
- The Pivot Point (PP): The mathematical average of last week's High, Low, and Close.
- Pivot Range High (PRH) & Low (PRL): These determine the boundaries of the pivot range based on the distance between the average price and the volatility of the previous week.
3. Mid-Point Calculations (The Unique Feature) Unlike standard pivot scripts that only show primary levels, this script specializes in "Mid-Points." It calculates the halfway marks between various primary levels to provide more granular detail:
- Weekly M1 - M4: These are the midpoints between the primary Resistance and Support levels (e.g., the midpoint between Resistance 1 and Resistance 2, or the midpoint between Support 1 and Support 2).
4. Visual Display & Labeling As the script runs, it performs the following visual actions:
- Dynamic Plotting: It draws these specific mid-points and range levels directly on your chart as arrows/markers.
- Real-time Updates: The labels move automatically with the current price action so you can always see where the most recent calculations land.
- Text Labels: It places descriptive text (like "Weekly M4" or "Weekly PR High") next to the markers, ensuring that a user can immediately identify which level is which without having to guess.
Summary for the User
In short, this script takes the "messy" data of last week's price action and distills it into six specific, easy-to-read mid-point levels. It allows you to see exactly where the "middle ground" sits between major resistance and support zones on a weekly basis, helping you identify potential entry or exit zones with greater precision.
//+------------------------------------------------------------------+
//| Pivot_Range_Weekly_Mid.mq4 |
//| Copyright © 2009, kris.pivo[at]gmail.com |
//+------------------------------------------------------------------+
#property copyright "© Kris, 2009" //|
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 7
#property indicator_color1 C'000,100,000'
#property indicator_color2 C'000,100,000'
#property indicator_color3 C'080,080,080'
#property indicator_color4 C'200,200,200'
#property indicator_color5 C'080,080,080'
#property indicator_color6 C'100,000,000'
#property indicator_color7 C'100,000,000'
//---- input parameters
int fontsize=8;
//---- buffers
double BufferR2R1[]; // M4 - Mid R1-R2
double BufferR1PP[]; // M3 - Mid PP-R1
double BufferPRH[]; // Pivot Range High
//double BufferPP[]; // Pivot Point
double BufferPRL[]; // Pivot Range Low
double BufferPPS1[]; // M2 - Mid PP-S1
double BufferS1S2[]; // M1 - Mid S1-S2
double WH,WL,WC,PP,PD,PRH,PRL;
double S1,R1,S2,R2,S3,R3;
double R2R1, R1PP, PPS1, S1S2;
double last_week_high, last_week_low, last_week_close, this_week_open;
//+------------------------------------------------------------------+
int deinit() {
ObjectDelete("PivR2R1");
ObjectDelete("PivR1PP");
ObjectDelete("PivPRH");
// ObjectDelete("PivPP");
ObjectDelete("PivPRL");
ObjectDelete("PivPPS1");
ObjectDelete("PivS1S2");
ObjectDelete("LabPivR2R1");
ObjectDelete("LabPivR1PP");
ObjectDelete("LabPivPRH");
// ObjectDelete("LabPivPP");
ObjectDelete("LabPivPRL");
ObjectDelete("LabPivPPS1");
ObjectDelete("LabPivS1S2");
Comment("");
return(0); }
//+------------------------------------------------------------------+
int init()
{
string short_name;
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,160);
SetIndexBuffer(0,BufferR2R1);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1,160);
SetIndexBuffer(1,BufferR1PP);
SetIndexStyle(2,DRAW_ARROW);
SetIndexArrow(2,160);
SetIndexBuffer(2,BufferPRH);
// SetIndexStyle(3,DRAW_ARROW);
// SetIndexArrow(3,167);
// SetIndexBuffer(3,BufferPP);
SetIndexStyle(4,DRAW_ARROW);
SetIndexArrow(4,160);
SetIndexBuffer(4,BufferPRL);
SetIndexStyle(5,DRAW_ARROW);
SetIndexArrow(5,160);
SetIndexBuffer(5,BufferPPS1);
SetIndexStyle(6,DRAW_ARROW);
SetIndexArrow(6,160);
SetIndexBuffer(6,BufferS1S2);
short_name="Floor Pivot Mid Weekly";
IndicatorShortName(short_name);
SetIndexLabel(0,short_name);
SetIndexDrawBegin(0,1);
return(0); }
int start()
{
int counted_bars=IndicatorCounted();
int limit, i;
if (counted_bars==0)
{
ObjectCreate("PivR2R1", OBJ_TEXT, 0,0,0);
ObjectSetText("PivR2R1", " Weekly M4",fontsize,"Arial",indicator_color1);
ObjectCreate("PivR1PP", OBJ_TEXT, 0,0,0);
ObjectSetText("PivR1PP", " Weekly M3",fontsize,"Arial",indicator_color2);
ObjectCreate("PivPRH", OBJ_TEXT, 0,0,0);
ObjectSetText("PivPRH", " Weekly PR High",fontsize,"Arial",indicator_color3);
// ObjectCreate("PivPP", OBJ_TEXT, 0,0,0);
// ObjectSetText("PivPP", " Weekly Pivot Point",fontsize,"Arial",indicator_color4);
ObjectCreate("PivPRL", OBJ_TEXT, 0,0,0);
ObjectSetText("PivPRL", " Weekly PR Low",fontsize,"Arial",indicator_color5);
ObjectCreate("PivPPS1", OBJ_TEXT, 0,0,0);
ObjectSetText("PivPPS1", " Weekly M2",fontsize,"Arial",indicator_color6);
ObjectCreate("PivS1S2", OBJ_TEXT, 0,0,0);
ObjectSetText("PivS1S2", " Weekly M1",fontsize,"Arial",indicator_color7);
}
if(counted_bars<0) return(-1);
//----
limit=(Bars-counted_bars)-1;
//----
for(i=limit; i>=0;i--)
{
// Monday
if(1==TimeDayOfWeek(Time[i]) && 1!=TimeDayOfWeek(Time[i+1]) ) // 0=Sunday, 1=Monday, ...
{
last_week_close=Close[i+1];
this_week_open=Open[i];
WH = last_week_high;
WL = last_week_low;
WC = last_week_close;
PP = (WH + WL + WC)/3;
PD = MathAbs(((WH + WL)/2) - PP);
PRH = PP + PD;
PRL = PP - PD;
R1 = (2*PP)- WL;
S1 = (2*PP)- WH;
R2 = PP+(R1-S1);
S2 = PP-(R1-S1);
R2R1 = (R2+R1)/2;
R1PP = (R1+PP)/2;
PPS1 = (PP+S1)/2;
S1S2 = (S1+S2)/2;
last_week_low = Low[i];
last_week_high = High[i];
//----
ObjectMove("PivR2R1", 0, Time[i],R2R1);
ObjectMove("PivR1PP", 0, Time[i],R1PP);
ObjectMove("PivPRH", 0, Time[i],PRH);
// ObjectMove("PivPP", 0, Time[i],PP);
ObjectMove("PivPRL", 0, Time[i],PRL);
ObjectMove("PivPPS1", 0, Time[i],PPS1);
ObjectMove("PivS1S2", 0, Time[i],S1S2);
}
last_week_high=MathMax(last_week_high, High[i]);
last_week_low=MathMin(last_week_low, Low[i]);
BufferR2R1[i] = R2R1;
BufferR1PP[i] = R1PP;
BufferPRH[i] = PRH;
// BufferPP[i] = PP;
BufferPRL[i] = PRL;
BufferPPS1[i] = PPS1;
BufferS1S2[i] = S1S2;
DoLabel( "LabPivR2R1", BufferR2R1[0], indicator_color1 );
DoLabel( "LabPivR1PP", BufferR1PP[0], indicator_color2 );
DoLabel( "LabPivPRH", BufferPRH[0], indicator_color3 );
// DoLabel( "LabPivPP", BufferPP[0], indicator_color4 );
DoLabel( "LabPivPRL", BufferPRL[0], indicator_color5 );
DoLabel( "LabPivPPS1", BufferPPS1[0], indicator_color6 );
DoLabel( "LabPivS1S2", BufferS1S2[0], indicator_color7 );
}
return(0); }
void DoLabel( string dName, double dValue, color dColor )
{
if (ObjectFind(dName) != 0)
{
ObjectCreate(dName,OBJ_ARROW,0,Time[0],dValue);
ObjectSet(dName,OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE);
ObjectSet(dName,OBJPROP_COLOR,dColor);
}
else
{
ObjectMove(dName,0,Time[0],dValue);
}
}
//+-----------------------------------------------------------------------------------------+
//| THE END |
//+-----------------------------------------------------------------------------------------+
Comments