Cams_Weekly_Rev

Cams_Weekly_Rev
Miscellaneous
Implements a curve of type %1
0 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