Weekly Pivot Fibo
Download scriptThis script is designed to automatically calculate and display specific technical analysis levels on your trading chart. It identifies key price points based on historical data from the previous week, providing traders with visual "support" and "resistance" boundaries.
Core Functionality
Data Sourcing The script looks specifically at the weekly price action. It retrieves three essential pieces of information from the prior week:
- The highest price reached.
- The lowest price reached.
- The closing price.
Automated Calculations Using these three values, the script performs a series of mathematical operations to determine various "Pivot" levels.
- The Central Pivot: It establishes a baseline "Pivot" point by averaging the weekly high, low, and close.
- Range Calculation: It determines the total price range (the distance between the high and low) of the previous week.
- Multi-Level Projection: It uses specific multipliers (such as Fibonacci-related ratios like 0.618, 1.618, and 2.618, along with others like 1.236 and 2.00) to project multiple levels both above and below the central pivot.
Visual Representation
Once the calculations are complete, the script automatically draws these levels directly onto your trading screen:
- Horizontal Lines: The script draws solid and dashed lines across the chart representing the calculated price points. This allows you to see exactly where historical volatility boundaries sit in real-time.
- Dynamic Labels: Each line is accompanied by a text label (e.g., "R238%", "S61%"). These labels tell you the specific name of the level, helping you identify whether a price point is a resistance (R) or support (S) level.
- Color Coding: The levels are assigned different colors (such as Yellow, Aqua, Lime, Magenta, and Red) to help distinguish between different zones of importance at a glance.
- On-Screen Commentary: In addition to the lines, the script displays a text summary in the corner of your chart, showing the specific High, Low, and Close values used for the current calculations, as well as the total range of the previous week.
Key Constraints & Requirements
- Timeframe Compatibility: The script is designed to work on any timeframe smaller than one day (e.g., 15-minute, 1-hour, or 4-hour charts). It will display an error message if applied to a weekly or monthly chart.
- Automatic Updates: The logic is built to refresh the lines and labels automatically as new price data becomes available, ensuring your levels stay current with the market's movement.
//+------------------------------------------------------------------+
//| Pivot.mq4 |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
//#property indicator_chart_window
extern bool ManualCalculation = false;
double LastWeek_high = 0;
double LastWeek_low = 0;
double LastWeek_close = 0;
double P=0;
double Q=0;
double H8,H7,H6,H5,H4,H3,H2,H1,L1,L2,L3,L4,L5,L6,L7,L8;
double nQ=0;
double nD=0;
double D=0;
double rates_d1[2][6];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
H8=0; H7=0; H6=0; H5=0; H4=0; H3=0; H2=0; H1=0; L1=0; L2=0; L3=0; L4=0; L5=0; L6=0; L7=0; L8=0;
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- TODO: add your code here
ObjectDelete("WP Label");
ObjectDelete("WP Line");
ObjectDelete("H8 Label");
ObjectDelete("H8 Line");
ObjectDelete("H7 Label");
ObjectDelete("H7 Line");
ObjectDelete("H6 Label");
ObjectDelete("H6 Line");
ObjectDelete("H5 Label");
ObjectDelete("H5 Line");
ObjectDelete("H4 Label");
ObjectDelete("H4 Line");
ObjectDelete("H3 Label");
ObjectDelete("H3 Line");
ObjectDelete("H2 Label");
ObjectDelete("H2 Line");
ObjectDelete("H1 Label");
ObjectDelete("H1 Line");
ObjectDelete("L1 Label");
ObjectDelete("L1 Line");
ObjectDelete("L2 Label");
ObjectDelete("L2 Line");
ObjectDelete("L3 Label");
ObjectDelete("L3 Line");
ObjectDelete("L4 Label");
ObjectDelete("L4 Line");
ObjectDelete("L5 Label");
ObjectDelete("L5 Line");
ObjectDelete("L6 Label");
ObjectDelete("L6 Line");
ObjectDelete("L7 Lable");
ObjectDelete("L7 Line");
ObjectDelete("L8 Lable");
ObjectDelete("L8 Line");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
//---- TODO: add your code here
//---- exit if period is greater than daily charts
if(Period() > 1440)
{
Print("Error - Chart period is greater than 1 day.");
return(-1); // then exit
}
//---- Get new daily prices
ArrayCopyRates(rates_d1, Symbol(), PERIOD_W1);
if ( ManualCalculation == false)
{
LastWeek_close = rates_d1[1][4];
LastWeek_high = rates_d1[1][3];
LastWeek_low = rates_d1[1][2];
}
//---- Calculate Pivots
Q = (LastWeek_high - LastWeek_low);
P = (LastWeek_high + LastWeek_low + LastWeek_close) / 3;
H8 = (Q*2.382)+P;
H7 = (Q*2.236)+P;
H6 = (Q*2.00)+P;
H5 = (Q*1.382)+P;
H4 = (Q*1.236)+P;
H3 = (Q*1.00)+P;
H2 = (Q*0.618)+P;
H1 = (Q*0.382)+P;
L1 = P-(Q*0.382);
L2 = P-(Q*0.618);
L3 = P-(Q*1.00);
L4 = P-(Q*1.236);
L5 = P-(Q*1.382);
L6 = P-(Q*2.00);
L7 = P-(Q*2.236);
L8 = P-(Q*2.382);
if (Q > 5)
{
nQ = Q;
}
else
{
nQ = Q*10000;
}
if (D > 5)
{
nD = D;
}
else
{
nD = D*10000;
}
Comment("High= ",LastWeek_high," Previous Week Range= ",nQ,"\nLow= ",LastWeek_low," Close= ",LastWeek_close);
//---- Set line labels on chart window
//---- Pivot Lines
if(ObjectFind("WP label") != 0)
{
ObjectCreate("WP label", OBJ_TEXT, 0, Time[0], P);
ObjectSetText("WP label", "Pivot", 10, "Arial", Yellow);
}
else
{
ObjectMove("WP label", 0, Time[16], P);
}
//--- Draw Pivot lines on chart
if(ObjectFind("WP line") != 0)
{
ObjectCreate("WP line", OBJ_HLINE, 0, Time[40], P);
ObjectSet("WP line", OBJPROP_STYLE, STYLE_DASHDOTDOT);
ObjectSet("WP line", OBJPROP_WIDTH, 0);
ObjectSet("WP line", OBJPROP_COLOR, Yellow);
}
else
{
ObjectMove("WP line", 0, Time[40], P);
}
if(ObjectFind("H8 label") != 0)
{
ObjectCreate("H8 label", OBJ_TEXT, 0, Time[10], H8);
ObjectSetText("H8 label", "R238%", 9, "Arial", Yellow);
}
else
{
ObjectMove("H8 label", 0, Time[16], H8);
}
if(ObjectFind("H7 label") != 0)
{
ObjectCreate("H7 label", OBJ_TEXT, 0, Time[10], H7);
ObjectSetText("H7 label", "R223%", 9, "Arial", Yellow);
}
else
{
ObjectMove("H7 label", 0, Time[16], H7);
}
if(ObjectFind("H6 label") != 0)
{
ObjectCreate("H6 label", OBJ_TEXT, 0, Time[10], H6);
ObjectSetText("H6 label", "R200%", 9, "Arial", Aqua);
}
else
{
ObjectMove("H6 label", 0, Time[16], H6);
}
if(ObjectFind("H5 label") != 0)
{
ObjectCreate("H5 label", OBJ_TEXT, 0, Time[10], H4);
ObjectSetText("H5 label", "R138%", 9, "Arial", Yellow);
}
else
{
ObjectMove("H5 label", 0, Time[16], H5);
}
if(ObjectFind("H4 label") != 0)
{
ObjectCreate("H4 label", OBJ_TEXT, 0, Time[10], H4);
ObjectSetText("H4 label", "R123%", 9, "Arial", Yellow);
}
else
{
ObjectMove("H4 label", 0, Time[16], H4);
}
if(ObjectFind("H3 label") != 0)
{
ObjectCreate("H3 label", OBJ_TEXT, 0, Time[10], H3);
ObjectSetText("H3 label", "R100%", 9, "Arial", Aqua);
}
else
{
ObjectMove("H3 label", 0, Time[16], H3);
}
if(ObjectFind("H2 label") != 0)
{
ObjectCreate("H2 label", OBJ_TEXT, 0, Time[10], H2);
ObjectSetText("H2 label", "R61%", 9, "Arial", Lime);
}
else
{
ObjectMove("H2 label", 0, Time[10], H2);
}
if(ObjectFind("H1 label") != 0)
{
ObjectCreate("H1 label", OBJ_TEXT, 0, Time[250], H1);
ObjectSetText("H1 label", "R38%", 9, "Arial", Magenta);
}
else
{
ObjectMove("H1 label", 0, Time[16], H1);
}
if(ObjectFind("L1 label") != 0)
{
ObjectCreate("L1 label", OBJ_TEXT, 0, Time[10], L1);
ObjectSetText("L1 label", "S38%", 9, "Arial", Magenta);
}
else
{
ObjectMove("L1 label", 0, Time[16], L1);
}
if(ObjectFind("L2 label") != 0)
{
ObjectCreate("L2 label", OBJ_TEXT, 0, Time[10], L2);
ObjectSetText("L2 label", "S61%", 9, "Arial", Red);
}
else
{
ObjectMove("L2 label", 0, Time[16], L2);
}
if(ObjectFind("L3 label") != 0)
{
ObjectCreate("L3 label", OBJ_TEXT, 0, Time[10], L3);
ObjectSetText("L3 label", "S100%", 9, "Arial", Aqua);
}
else
{
ObjectMove("L3 label", 0, Time[16], L3);
}
if(ObjectFind("L4 label") != 0)
{
ObjectCreate("L4 label", OBJ_TEXT, 0, Time[10], L4);
ObjectSetText("L4 label", "S123%", 9, "Arial", Yellow);
}
else
{
ObjectMove("L4 label", 0, Time[16], L4);
}
if(ObjectFind("L5 label") != 0)
{
ObjectCreate("L5 label", OBJ_TEXT, 0, Time[10], L5);
ObjectSetText("L5 label", "S138%", 9, "Arial", Yellow);
}
else
{
ObjectMove("L5 label", 0, Time[16], L5);
}
if(ObjectFind("L6 label") != 0)
{
ObjectCreate("L6 label", OBJ_TEXT, 0, Time[10], L6);
ObjectSetText("L6 label", "S200%", 9, "Arial", Aqua);
}
else
{
ObjectMove("L6 label", 0, Time[16], L6);
}
if(ObjectFind("L7 label") != 0)
{
ObjectCreate("L7 label", OBJ_TEXT, 0, Time[10], L7);
ObjectSetText("L7 label", "S223%", 9, "Arial", Yellow);
}
else
{
ObjectMove("L7 label", 0, Time[16], L7);
}
if(ObjectFind("L8 label") != 0)
{
ObjectCreate("L8 label", OBJ_TEXT, 0, Time[10], L8);
ObjectSetText("L8 label", "S238%", 9, "Arial", Yellow);
}
else
{
ObjectMove("L8 label", 0, Time[16], L8);
}
//---- Draw Camarilla lines on Chart
if(ObjectFind("H8 line") != 0)
{
ObjectCreate("H8 line", OBJ_HLINE, 0, Time[40], H8);
ObjectSet("H8 line", OBJPROP_STYLE, STYLE_SOLID);
ObjectSet("H8 line", OBJPROP_WIDTH, 1);
ObjectSet("H8 line", OBJPROP_COLOR, Yellow);
}
else
{
ObjectMove("H8 line", 0, Time[40], H8);
}
if(ObjectFind("H7 line") != 0)
{
ObjectCreate("H7 line", OBJ_HLINE, 0, Time[40], H7);
ObjectSet("H7 line", OBJPROP_STYLE, STYLE_SOLID);
ObjectSet("H7 line", OBJPROP_WIDTH, 1);
ObjectSet("H7 line", OBJPROP_COLOR, Yellow);
}
else
{
ObjectMove("H7 line", 0, Time[40], H7);
}
if(ObjectFind("H6 line") != 0)
{
ObjectCreate("H6 line", OBJ_HLINE, 0, Time[40], H6);
ObjectSet("H6 line", OBJPROP_STYLE, STYLE_SOLID);
ObjectSet("H6 line", OBJPROP_WIDTH, 1);
ObjectSet("H6 line", OBJPROP_COLOR, Aqua);
}
else
{
ObjectMove("H6 line", 0, Time[40], H6);
}
if(ObjectFind("H5 line") != 0)
{
ObjectCreate("H5 line", OBJ_HLINE, 0, Time[40], H5);
ObjectSet("H5 line", OBJPROP_STYLE, STYLE_SOLID);
ObjectSet("H5 line", OBJPROP_WIDTH, 1);
ObjectSet("H5 line", OBJPROP_COLOR, Yellow);
}
else
{
ObjectMove("H5 line", 0, Time[40], H5);
}
if(ObjectFind("H4 line") != 0)
{
ObjectCreate("H4 line", OBJ_HLINE, 0, Time[40], H4);
ObjectSet("H4 line", OBJPROP_STYLE, STYLE_SOLID);
ObjectSet("H4 line", OBJPROP_WIDTH, 1);
ObjectSet("H4 line", OBJPROP_COLOR, Yellow);
}
else
{
ObjectMove("H4 line", 0, Time[40], H4);
}
if(ObjectFind("H3 line") != 0)
{
ObjectCreate("H3 line", OBJ_HLINE, 0, Time[40], H3);
ObjectSet("H3 line", OBJPROP_STYLE, STYLE_SOLID);
ObjectSet("H3 line", OBJPROP_WIDTH, 1);
ObjectSet("H3 line", OBJPROP_COLOR, Aqua);
}
else
{
ObjectMove("H3 line", 0, Time[40], H3);
}
if(ObjectFind("H2 line") != 0)
{
ObjectCreate("H2 line", OBJ_HLINE, 0, Time[40], H2);
ObjectSet("H2 line", OBJPROP_STYLE, STYLE_SOLID);
ObjectSet("H2 line", OBJPROP_WIDTH, 1);
ObjectSet("H2 line", OBJPROP_COLOR, Lime);
}
else
{
ObjectMove("H2 line", 0, Time[40], H2);
}
if(ObjectFind("H1 line") != 0)
{
ObjectCreate("H1 line", OBJ_HLINE, 0, Time[40], H1);
ObjectSet("H1 line", OBJPROP_STYLE, STYLE_SOLID);
ObjectSet("H1 line", OBJPROP_WIDTH, 1);
ObjectSet("H1 line", OBJPROP_COLOR, Magenta);
}
else
{
ObjectMove("H1 line", 0, Time[40], H1);
}
if(ObjectFind("L1 line") != 0)
{
ObjectCreate("L1 line", OBJ_HLINE, 0, Time[40], L1);
ObjectSet("L1 line", OBJPROP_STYLE, STYLE_SOLID);
ObjectSet("L1 line", OBJPROP_WIDTH, 1);
ObjectSet("L1 line", OBJPROP_COLOR, Magenta);
}
else
{
ObjectMove("L1 line", 0, Time[40], L1);
}
if(ObjectFind("L2 line") != 0)
{
ObjectCreate("L2 line", OBJ_HLINE, 0, Time[40], L2);
ObjectSet("L2 line", OBJPROP_STYLE, STYLE_SOLID);
ObjectSet("L2 line", OBJPROP_WIDTH, 1);
ObjectSet("L2 line", OBJPROP_COLOR, Red);
}
else
{
ObjectMove("L2 line", 0, Time[40], L2);
}
if(ObjectFind("L3 line") != 0)
{
ObjectCreate("L3 line", OBJ_HLINE, 0, Time[40], L3);
ObjectSet("L3 line", OBJPROP_STYLE, STYLE_SOLID);
ObjectSet("L3 line", OBJPROP_WIDTH, 1);
ObjectSet("L3 line", OBJPROP_COLOR, Aqua);
}
else
{
ObjectMove("L3 line", 0, Time[40], L3);
}
if(ObjectFind("L4 line") != 0)
{
ObjectCreate("L4 line", OBJ_HLINE, 0, Time[40], L4);
ObjectSet("L4 line", OBJPROP_STYLE, STYLE_SOLID);
ObjectSet("L4 line", OBJPROP_WIDTH, 1);
ObjectSet("L4 line", OBJPROP_COLOR, Yellow);
}
else
{
ObjectMove("L4 line", 0, Time[40], L4);
}
if(ObjectFind("L5 line") != 0)
{
ObjectCreate("L5 line", OBJ_HLINE, 0, Time[40], L5);
ObjectSet("L5 line", OBJPROP_STYLE, STYLE_SOLID);
ObjectSet("L5 line", OBJPROP_WIDTH, 1);
ObjectSet("L5 line", OBJPROP_COLOR, Yellow);
}
else
{
ObjectMove("L5 line", 0, Time[40], L5);
}
if(ObjectFind("L6 line") != 0)
{
ObjectCreate("L6 line", OBJ_HLINE, 0, Time[40], L6);
ObjectSet("L6 line", OBJPROP_STYLE, STYLE_SOLID);
ObjectSet("L6 line", OBJPROP_WIDTH, 1);
ObjectSet("L6 line", OBJPROP_COLOR, Aqua);
}
else
{
ObjectMove("L6 line", 0, Time[40], L6);
}
if(ObjectFind("L7 line") != 0)
{
ObjectCreate("L7 line", OBJ_HLINE, 0, Time[40], L7);
ObjectSet("L7 line", OBJPROP_STYLE, STYLE_SOLID);
ObjectSet("L7 line", OBJPROP_WIDTH, 1);
ObjectSet("L7 line", OBJPROP_COLOR, Yellow);
}
else
{
ObjectMove("L7 line", 0, Time[40], L7);
}
if(ObjectFind("L8 line") != 0)
{
ObjectCreate("L8 line", OBJ_HLINE, 0, Time[40], L8);
ObjectSet("L8 line", OBJPROP_STYLE, STYLE_SOLID);
ObjectSet("L8 line", OBJPROP_WIDTH, 1);
ObjectSet("L8 line", OBJPROP_COLOR, Yellow);
}
else
{
ObjectMove("L8 line", 0, Time[40], L8);
}
//---- End Of Program
return(0);
}
//+------------------------------------------------------------------+
Comments