VX_FibPiv_rws_001

Download script
Author: Copyright � 2008, V-X
VX_FibPiv_rws_001

This script is a specialized technical analysis tool designed to automatically calculate and display "Support and Resistance" levels on a trading chart. It simplifies complex market data into a clean, visual dashboard that helps traders identify potential price boundaries.

Core Logic Overview

The script functions by analyzing the price action of the previous trading day to project key levels for the current day. Here is the step-by-step logical flow:

1. Data Collection The tool automatically looks back at the daily price history. It specifically identifies three key pieces of information from the previous session:

  • The highest price reached (High)
  • The lowest price reached (Low)
  • The final price at the end of the day (Close)

The script includes built-in intelligence to handle weekends; for instance, if the current market session starts on a Monday, it intelligently searches back to find the last valid trading Friday to ensure the calculations remain accurate.

2. Mathematical Calculations Once the high, low, and close prices are identified, the script performs a series of calculations based on standard financial "Pivot Point" formulas combined with Fibonacci ratios:

  • The Pivot Point: This is the central equilibrium price for the day.
  • Resistance Levels (R1, R2, R3): These represent potential "ceilings" where the price might face selling pressure. The script uses specific multipliers (like 0.382 and 0.618) to determine these levels based on the previous day's price range.
  • Support Levels (S1, S2, S3): These represent potential "floors" where the price might find buying support. Similar to the resistance levels, these are mirrored below the central Pivot Point.

3. Visual Display (The Dashboard) Instead of cluttering the actual price chart with hundreds of lines, this script creates a professional on-screen "Gauge" or dashboard.

  • It takes all the calculated values (R1 through S3 and the Pivot) and places them in a neatly organized text list on your chart window.
  • The display is customizable, allowing you to set the font, size, and color of the labels so they remain readable against different background colors.
  • The dashboard updates dynamically, ensuring that as new daily data becomes available, the levels shown are always relevant to the current trading session.

Summary for the User

Essentially, this tool acts as an automated analyst. It looks at what happened yesterday, calculates where the "walls" and "floors" of the market are likely to be today using established mathematical ratios, and presents that information in a clean, easy-to-read text box on your screen.

Price Data Components
Series array that contains open time of each bar
10 Views
0 Downloads
0 Favorites
VX_FibPiv_rws_001
//+------------------------------------------------------------------+ 
//|   VX_FibPiv_rws                                                  | 
//|                                                                  | 
//|   Copyright © 2008, V-X                                          |
//|                                                                  |
//|   Thanks to Kalenzo for S&R formula                              |
//|   Thanks to TRO for the source code                              |
//+------------------------------------------------------------------+ 

#property copyright "Copyright © 2008, V-X"
#property link      "vogimerox_x@hotmail.com"

#property indicator_chart_window

extern int myChartY = 100 ;
extern string myFont  = "Courier" ; // "Verdana"
extern int myFontSize = 12 ; //9
extern int myChartPeriod = 1440 ;
extern color myColorH = Gold ;
extern color myColor1 = Gold ;
extern color myColor2 = Gold ;
extern color myColor3 = Gold ;
extern color myColor4 = Gold ;
extern color myColor5 = Gold ;
extern color myColor6 = Gold ;
extern color myColor7 = Gold ;


int i;

double X01,X02,X03,X04,X05 ;
double X06 ;   
double X07 ;
double r3, r2, r1, p, s1, s2, s3 ; 
string symbol, tChartPeriod ;  
int    digits, period, win ;
double point ;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   if(myChartPeriod == 0) { myChartPeriod = Period() ; }    
   tChartPeriod =  TimeFrameToString(myChartPeriod) ;
   symbol       =  Symbol() ;
   digits       =  Digits ;
   point        =  Point ;
 
   win          = 0 ;
    
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
ObjectsDeleteAll( win, 21);
ObjectsDeleteAll( win, 22);
ObjectsDeleteAll( win, 23);     
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   
//----
double rates[1][6],yesterday_close,yesterday_high,yesterday_low;
ArrayCopyRates(rates, Symbol(), PERIOD_D1);

if(DayOfWeek() == 1)
{
   if(TimeDayOfWeek(iTime(Symbol(),PERIOD_D1,1)) == 5)
   {
       yesterday_close = rates[1][4];
       yesterday_high = rates[1][3];
       yesterday_low = rates[1][2];
   }
   else
   {
      for(int d = 5;d>=0;d--)
      {
         if(TimeDayOfWeek(iTime(Symbol(),PERIOD_D1,d)) == 5)
         {
             yesterday_close = rates[d][4];
             yesterday_high = rates[d][3];
             yesterday_low = rates[d][2];
         }
         
      }  
      
   }
}
else
{
    yesterday_close = rates[1][4];
    yesterday_high = rates[1][3];
    yesterday_low = rates[1][2];
}


//---- Calculate Pivots

Comment("\nYesterday quotations:\nH ",yesterday_high,"\nL ",yesterday_low, "\nC ",yesterday_close);
double R = yesterday_high - yesterday_low;//range
p = (yesterday_high + yesterday_low + yesterday_close)/3;// Standard Pivot
r3 = p + (R * 1.000);
r2 = p + (R * 0.618);
r1 = p + (R * 0.382);
s1 = p - (R * 0.382);
s2 = p - (R * 0.618);
s3 = p - (R * 1.000);

DoShowGauge() ;
   return(0);
  }

void DoShowGauge()
{

X01  = r3 ;
X02  = r2 ;
X03  = r1 ;
X04  = p ;
X05  = s1 ;
X06  = s2 ;
X07  = s3 ;

string StrH   = " S&R" ;
string StrX01 = "R3  " ; 
string StrX02 = "R2  " ; 
string StrX03 = "R1  " ; 
string StrX04 = "Piv  " ;  
string StrX05 = "S1  " ; 
string StrX06 = "S2  " ;
string StrX07 = "S3  " ;

  
color color_X01=myColor1;
color color_X02=myColor2;
color color_X03=myColor3;  
color color_X04=myColor4;
color color_X05=myColor5;
color color_X06=myColor6;
color color_X07=myColor7;  


   int WindowToUse;
   int Corner_line, Xdist_line;
   int Corner_text, Corner_vSRFP, Xdist_text, Xdist_vSRFP;
   int Ydist_line5;
   int Corner_pivots, Xdist_pivots, Ydist_pivots;
   int Ydist_X01, Ydist_X02, Ydist_X03, Ydist_X04, Ydist_X05, Ydist_X06, Ydist_X07, Ydist_X08, Ydist_X09, Ydist_X10 ;
  
   int YdistInc ;
   
    WindowToUse =  0;
    Corner_line = 1;
    Corner_text = 1; Corner_vSRFP = 1;
    Xdist_line = 21; Xdist_text = 93; Xdist_vSRFP = 23;
    Corner_pivots = 1; Xdist_pivots = 21; 
    
    Ydist_pivots = myChartY;  
    Ydist_line5 = Ydist_pivots + 11; YdistInc = 15 ;
    
    Ydist_X01 = Ydist_pivots + 25; 
    Ydist_X02 = Ydist_X01 + YdistInc; 
    Ydist_X03 = Ydist_X01 + YdistInc*2; 
    Ydist_X04 = Ydist_X01 + YdistInc*3; 
    Ydist_X05 = Ydist_X01 + YdistInc*4;
    Ydist_X06 = Ydist_X01 + YdistInc*5;    
    Ydist_X07 = Ydist_X01 + YdistInc*6; 

   ObjectCreate("SRFP", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("SRFP",tChartPeriod + StrH,myFontSize, myFont, myColorH);
   ObjectSet("SRFP", OBJPROP_CORNER, Corner_pivots);
   ObjectSet("SRFP", OBJPROP_XDISTANCE, Xdist_pivots);
   ObjectSet("SRFP", OBJPROP_YDISTANCE, Ydist_pivots);
   
   ObjectCreate("line5SRFP", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("line5SRFP","-------------",myFontSize, myFont, myColorH);
   ObjectSet("line5SRFP", OBJPROP_CORNER, Corner_line);
   ObjectSet("line5SRFP", OBJPROP_XDISTANCE, Xdist_line);
   ObjectSet("line5SRFP", OBJPROP_YDISTANCE, Ydist_line5);
   
   ObjectCreate("X01_LabelRGE", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("X01_LabelRGE",StrX01,myFontSize, myFont, myColor1 );
   ObjectSet("X01_LabelRGE", OBJPROP_CORNER, Corner_text);
   ObjectSet("X01_LabelRGE", OBJPROP_XDISTANCE, Xdist_text);
   ObjectSet("X01_LabelRGE", OBJPROP_YDISTANCE, Ydist_X01);
   
   ObjectCreate("X01_ValueRGE", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("X01_ValueRGE"," "+DoubleToStr(X01,digits),myFontSize, myFont, color_X01);
   ObjectSet("X01_ValueRGE", OBJPROP_CORNER, Corner_vSRFP);
   ObjectSet("X01_ValueRGE", OBJPROP_XDISTANCE, Xdist_vSRFP);
   ObjectSet("X01_ValueRGE", OBJPROP_YDISTANCE, Ydist_X01);
    
   ObjectCreate("X02_LabelRGE", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("X02_LabelRGE",StrX02,myFontSize, myFont, myColor2 );
   ObjectSet("X02_LabelRGE", OBJPROP_CORNER, Corner_text);
   ObjectSet("X02_LabelRGE", OBJPROP_XDISTANCE, Xdist_text);
   ObjectSet("X02_LabelRGE", OBJPROP_YDISTANCE, Ydist_X02);
   
   ObjectCreate("X02_ValueRGE", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("X02_ValueRGE"," "+DoubleToStr(X02,digits),myFontSize, myFont, color_X02);
   ObjectSet("X02_ValueRGE", OBJPROP_CORNER, Corner_vSRFP);
   ObjectSet("X02_ValueRGE", OBJPROP_XDISTANCE, Xdist_vSRFP);
   ObjectSet("X02_ValueRGE", OBJPROP_YDISTANCE, Ydist_X02);

   ObjectCreate("X03_LabelRGE", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("X03_LabelRGE",StrX03,myFontSize, myFont, myColor3 );
   ObjectSet("X03_LabelRGE", OBJPROP_CORNER, Corner_text);
   ObjectSet("X03_LabelRGE", OBJPROP_XDISTANCE, Xdist_text);
   ObjectSet("X03_LabelRGE", OBJPROP_YDISTANCE, Ydist_X03);
   
   ObjectCreate("X03_ValueRGE", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("X03_ValueRGE"," "+DoubleToStr(X03,digits),myFontSize, myFont, color_X03);
   ObjectSet("X03_ValueRGE", OBJPROP_CORNER, Corner_vSRFP);
   ObjectSet("X03_ValueRGE", OBJPROP_XDISTANCE, Xdist_vSRFP);
   ObjectSet("X03_ValueRGE", OBJPROP_YDISTANCE, Ydist_X03);

   ObjectCreate("X04_LabelRGE", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("X04_LabelRGE",StrX04,myFontSize, myFont, myColor4 );
   ObjectSet("X04_LabelRGE", OBJPROP_CORNER, Corner_text);
   ObjectSet("X04_LabelRGE", OBJPROP_XDISTANCE, Xdist_text);
   ObjectSet("X04_LabelRGE", OBJPROP_YDISTANCE, Ydist_X04);
   
   ObjectCreate("X04_ValueRGE", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("X04_ValueRGE"," "+DoubleToStr(X04,digits),myFontSize, myFont, color_X04);
   ObjectSet("X04_ValueRGE", OBJPROP_CORNER, Corner_vSRFP);
   ObjectSet("X04_ValueRGE", OBJPROP_XDISTANCE, Xdist_vSRFP);
   ObjectSet("X04_ValueRGE", OBJPROP_YDISTANCE, Ydist_X04);  
       
   
   ObjectCreate("X05_LabelRGE", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("X05_LabelRGE",StrX05,myFontSize, myFont, myColor5 );
   ObjectSet("X05_LabelRGE", OBJPROP_CORNER, Corner_text);
   ObjectSet("X05_LabelRGE", OBJPROP_XDISTANCE, Xdist_text);
   ObjectSet("X05_LabelRGE", OBJPROP_YDISTANCE, Ydist_X05);
   
   ObjectCreate("X05_ValueRGE", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("X05_ValueRGE"," "+DoubleToStr(X05,digits),myFontSize, myFont, color_X05);
   ObjectSet("X05_ValueRGE", OBJPROP_CORNER, Corner_vSRFP);
   ObjectSet("X05_ValueRGE", OBJPROP_XDISTANCE, Xdist_vSRFP);
   ObjectSet("X05_ValueRGE", OBJPROP_YDISTANCE, Ydist_X05);
    
   ObjectCreate("X06_LabelRGE", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("X06_LabelRGE",StrX06,myFontSize, myFont, myColor6 );
   ObjectSet("X06_LabelRGE", OBJPROP_CORNER, Corner_text);
   ObjectSet("X06_LabelRGE", OBJPROP_XDISTANCE, Xdist_text);
   ObjectSet("X06_LabelRGE", OBJPROP_YDISTANCE, Ydist_X06);
   
   ObjectCreate("X06_ValueRGE", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("X06_ValueRGE"," "+DoubleToStr(X06,digits),myFontSize, myFont, color_X06);
   ObjectSet("X06_ValueRGE", OBJPROP_CORNER, Corner_vSRFP);
   ObjectSet("X06_ValueRGE", OBJPROP_XDISTANCE, Xdist_vSRFP);
   ObjectSet("X06_ValueRGE", OBJPROP_YDISTANCE, Ydist_X06);

   ObjectCreate("X07_LabelRGE", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("X07_LabelRGE",StrX07,myFontSize, myFont, myColor7 );
   ObjectSet("X07_LabelRGE", OBJPROP_CORNER, Corner_text);
   ObjectSet("X07_LabelRGE", OBJPROP_XDISTANCE, Xdist_text);
   ObjectSet("X07_LabelRGE", OBJPROP_YDISTANCE, Ydist_X07);
   
   ObjectCreate("X07_ValueRGE", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("X07_ValueRGE"," "+DoubleToStr(X07,digits),myFontSize, myFont, color_X07);
   ObjectSet("X07_ValueRGE", OBJPROP_CORNER, Corner_vSRFP);
   ObjectSet("X07_ValueRGE", OBJPROP_XDISTANCE, Xdist_vSRFP);
   ObjectSet("X07_ValueRGE", OBJPROP_YDISTANCE, Ydist_X07);


}

//+------------------------------------------------------------------+ 

string TimeFrameToString(int tf)
{
   string tfs;
   switch(tf) {
      case PERIOD_M1:  tfs="M1"  ; break;
      case PERIOD_M5:  tfs="M5"  ; break;
      case PERIOD_M15: tfs="M15" ; break;
      case PERIOD_M30: tfs="M30" ; break;
      case PERIOD_H1:  tfs="H1"  ; break;
      case PERIOD_H4:  tfs="H4"  ; break;
      case PERIOD_D1:  tfs="D1"  ; break;
      case PERIOD_W1:  tfs="W1"  ; break;
      case PERIOD_MN1: tfs="MN";
   }
   return(tfs);
}

Comments