Cams_Weekly_Rev

Download script
Cams_Weekly_Rev

This script is a specialized technical analysis tool designed for the MetaTrader 4 platform. It automatically identifies and plots specific price levels based on the high, low, and closing values of the previous week. These levels are intended to help traders visualize potential support and resistance zones or "pivot" points for the current trading week.

Core Logic and Functionality

Weekly Data Analysis The script constantly monitors the market's price action to determine the boundaries of the previous week. Specifically, it identifies three key pieces of data from the prior week:

  • The highest price reached (High)
  • The lowest price reached (Low)
  • The final price at which the week ended (Close)

Automatic Level Calculation Every Monday (or when a new weekly candle opens), the script takes these three values and calculates a specific "Range" (the distance between the previous week's high and low). It then uses the previous week’s closing price as a central anchor point to project six unique horizontal levels:

  • Upper Levels (H1, H2, H3): These are calculated by adding specific fractions of the weekly range to the previous week's closing price.
  • Lower Levels (L1, L2, L3): These are calculated by subtracting specific fractions of the weekly range from the previous week's closing price.

Visual Representation To make this data useful for a trader at a glance, the script handles several visual tasks:

  • Dynamic Plotting: It places arrows and text labels directly on your trading chart to mark these six calculated price levels.
  • Real-Time Updates: As the current week progresses, the script tracks the new highs and lows of the current week in real-time. This ensures that as soon as a new Monday arrives, the labels and levels automatically adjust based on the newly finalized data from the week just finished.
  • Clean Interface: The script includes a cleanup routine that removes these objects when removed from the chart, ensuring your workspace remains organized.

Summary for the Trader

In essence, this tool automates the "math" of weekly price action. Instead of manually calculating where specific fractions of last week's movement sit relative to its closing price, the script draws these boundaries clearly on your screen. It provides a structural map of the current week, highlighting key areas where price might react based on the previous week's volatility and range.

Miscellaneous
Implements a curve of type %1
12 Views
0 Downloads
0 Favorites
Cams_Weekly_Rev
//+------------------------------------------------------------------+
//|                                              Cams_Weekly_Rev.mq4 |
//|                         Copyright © 2009, kris.pivo[at]gmail.com |
//+------------------------------------------------------------------+
#property copyright "© Kris, 2009"                                 //|
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 8
#property indicator_color1 Green
#property indicator_color2 Red
#property indicator_color3 DarkGreen
#property indicator_color4 Maroon
#property indicator_color5 DarkGreen
#property indicator_color6 Maroon
#property indicator_color7 Green
#property indicator_color8 Red
//---- input parameters
int fontsize=8;
//---- buffers
double BufferH3[];
double BufferH2[];
double BufferH1[];
double BufferL1[];
double BufferL2[];
double BufferL3[];

double WH,WL,WC,Range;
double H1,H2,H3,L1,L2,L3;
double last_week_high, last_week_low, last_week_close, this_week_open;
//+------------------------------------------------------------------+

int deinit() {
   ObjectDelete("LineH3");
   ObjectDelete("LineH2");
   ObjectDelete("LineH1");
   ObjectDelete("LineL1");
   ObjectDelete("LineL2");
   ObjectDelete("LineL3");

	ObjectDelete("LabH3");
	ObjectDelete("LabH2");
	ObjectDelete("LabH1");
	ObjectDelete("LabL1");
	ObjectDelete("LabL2");
	ObjectDelete("LabL3");
	
	Comment("");
	return(0); }
//+------------------------------------------------------------------+

int init()
  {
   string short_name;

   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,167);
   SetIndexBuffer(1,BufferH3);

   SetIndexStyle(2,DRAW_ARROW);
   SetIndexArrow(2,160);
   SetIndexBuffer(2,BufferH2);
   
   SetIndexStyle(3,DRAW_ARROW);
   SetIndexArrow(3,160);
   SetIndexBuffer(3,BufferH1);

   SetIndexStyle(4,DRAW_ARROW);
   SetIndexArrow(4,160);
   SetIndexBuffer(4,BufferL1);

   SetIndexStyle(5,DRAW_ARROW);
   SetIndexArrow(5,160);
   SetIndexBuffer(5,BufferL2);

   SetIndexStyle(6,DRAW_ARROW);
   SetIndexArrow(6,167);
   SetIndexBuffer(6,BufferL3);

//---- name for DataWindow and indicator subwindow label
   short_name="Fibonacci Weekly";
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);
//----
   SetIndexDrawBegin(0,1);
//----
   return(0);
  }

int start()
  {
   int counted_bars=IndicatorCounted();
   int limit, i;
//---- indicator calculation
   if (counted_bars==0)
     {
      ObjectCreate("LineH3", OBJ_TEXT, 0,0,0);
      ObjectSetText("LineH3", "                                            Cam H3",fontsize,"Arial",indicator_color2);
      ObjectCreate("LineH2", OBJ_TEXT, 0,0,0);
      ObjectSetText("LineH2", "                                            Cam H2",fontsize,"Arial",indicator_color3);
      ObjectCreate("LineH1", OBJ_TEXT, 0,0,0);
      ObjectSetText("LineH1", "                                            Cam H1",fontsize,"Arial",indicator_color4);
      ObjectCreate("LineL1", OBJ_TEXT, 0,0,0);
      ObjectSetText("LineL1", "                                            Cam L1",fontsize,"Arial",indicator_color5);
      ObjectCreate("LineL2", OBJ_TEXT, 0,0,0);
      ObjectSetText("LineL2", "                                            Cam L2",fontsize,"Arial",indicator_color6);
      ObjectCreate("LineL3", OBJ_TEXT, 0,0,0);
      ObjectSetText("LineL3", "                                            Cam L3",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;
         double Range = (WH - WL);
         
         H3 = WC + (Range * 1/4);
         H2 = WC + (Range * 1/6);
         H1 = WC + (Range * 1/12);

         L1 = WC - (Range * 1/12);
         L2 = WC - (Range * 1/6);
         L3 = WC - (Range * 1/4);
         
         last_week_low  = Low[i];
         last_week_high = High[i];
//----
         ObjectMove("LineH3", 0, Time[i],H3);
         ObjectMove("LineH2", 0, Time[i],H2);
         ObjectMove("LineH1", 0, Time[i],H1);
         ObjectMove("LineL1", 0, Time[i],L1);
         ObjectMove("LineL2", 0, Time[i],L2);
         ObjectMove("LineL3", 0, Time[i],L3);
        }
      last_week_high=MathMax(last_week_high, High[i]);
      last_week_low=MathMin(last_week_low, Low[i]);
      
//      BufferH4[i]=H4;
      BufferH3[i]=H3;
      BufferH2[i]=H2;
      BufferH1[i]=H1;
      BufferL1[i]=L1;
      BufferL2[i]=L2;
      BufferL3[i]=L3;

   DoLabel( "LabH3", BufferH3[0], indicator_color2 );
   DoLabel( "LabH2", BufferH2[0], indicator_color3 );
   DoLabel( "LabH1", BufferH1[0], indicator_color4 );
   DoLabel( "LabL1", BufferL1[0], indicator_color5 );
   DoLabel( "LabL2", BufferL2[0], indicator_color6 );
   DoLabel( "LabL3", BufferL3[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