Navigation:Home > Content >

Dynamic_Pivot_Fibo_Levels.mq4

Time: 2015-01-07 | Download file:Dynamic_Pivot_Fibo_Levels.mq4

//+------------------------------------------------------------------+
//|                                    Dynamic Pivot Fibo levels.mq4 |
//|                                          Copyright © 2008, Dr.GM |
//|                                              [email protected] |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//|                                                   TSR_Ranges.mq4 |
//|                                         Copyright © 2006, Ogeima |
//|                                             [email protected] |
//| made for FXiGoR for the TSR Trend Slope Retracement method       |
//| modified to the DYNAMIC Daily Range Breakout System              |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, Dr.GM"
#property link      "[email protected]"

#property indicator_chart_window
//---------external---------------
extern int System=4;
extern int TF=2;

//----------internal--------------
double  Risk_to_Reward_ratio =  3.0;
int nDigits;

double         LH;            // High of Yesterday Candle
double         LL;             // Low of Yesterday Candle
double         LC;           // Close of Yesterday Candle
double         LO;           // Open of Yesterday Candle
double         Rn;               // Range of yesterday Candle ( High - Low )
double         P;               // Pivot Level

double   U236;
double   U382;
double   U50;
double   U618;
double   U100;
double   U1618;
   
double   D236;
double   D382;
double   D50;
double   D618;
double   D100;
double   D1618;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   ObjectsDeleteAll();
   Comment("...");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
   
//----
bool Periods;
if (TF==0 ) Periods=PERIOD_H4;
if (TF==1 ) Periods=PERIOD_D1;
if (TF==2 ) Periods=PERIOD_W1;
if (TF==3 ) Periods=PERIOD_MN1;
if (TF>3 || TF<0 ) Periods=PERIOD_D1;

//0 = H4
//1 = D1
//2 = W1
//3 = MN1


      //----
   int R1=0,R5=0,R10=0,R20=0,RAvg=0;
   int RoomUp=0,RoomDown=0,StopLoss_Long=0,StopLoss_Short=0;
   double   SL_Long=0,SL_Short=0;
   double   low0=0,high0=0;
   string   Text="";
   int i=0;

   R1 =  (iHigh(NULL,Periods,1)-iLow(NULL,Periods,1))/Point;
   for(i=1;i<=5;i++)
      R5    =    R5  +  (iHigh(NULL,Periods,i)-iLow(NULL,Periods,i))/Point;
   for(i=1;i<=10;i++)
      R10   =    R10 +  (iHigh(NULL,Periods,i)-iLow(NULL,Periods,i))/Point;
   for(i=1;i<=20;i++)
      R20   =    R20 +  (iHigh(NULL,Periods,i)-iLow(NULL,Periods,i))/Point;

   R5 = R5/5;
   R10 = R10/10;
   R20 = R20/20;
   RAvg  =  (R1+R5+R10+R20)/4;    


   
      
   LH = iHigh(NULL,Periods,1); //--LastHigh
   LL = iLow(NULL,Periods,1);  //--LastLow
   LC = iClose(NULL,Periods,1);//--LastClose
   LO = iOpen(NULL,Periods,1); //--LastOpen
   Rn = LH-LL;

if(System==0) P=(LH); //--Pivot point  
if(System==1) P=(LL); 
if(System==2) P=(LC); 
if(System==3) P=(LH+LL)/2; 
if(System==4) P=(LH+LL+LC)/3;   
if(System==5) P=(LH+LL+LC+LO)/4;    

//0= last High
//1= last Open
//2= last Close
//3= last Range
//4= last Typical
//5= last Weighted
    
 
   U236=(RAvg*0.236)*Point+P;
   U382=(RAvg*0.382)*Point+P;
   U50=(RAvg*0.50)*Point+P;
   U618=(RAvg*0.618)*Point+P;
   U100=(RAvg*1)*Point+P;
   U1618=(RAvg*1.618)*Point+P;
   
   D236=P-(RAvg*0.236)*Point;
   D382=P-(RAvg*0.382)*Point;
   D50=P-(RAvg*0.5)*Point;
   D618=P-(RAvg*0.618)*Point;
   D100=P-(RAvg*1)*Point;
   D1618=P-(RAvg*1.618)*Point;
   
         //----------------------------------------------------- 

          if(ObjectFind("Pivotl") != 0)
      {
      ObjectCreate("Pivotl", OBJ_TEXT, 0, Time[10], P);
      ObjectSetText("Pivotl", "Pivot", 9, "Arial", DarkBlue);
      }
      else
      {
      ObjectMove("Pivotl", 0, Time[10], P);
      }
           
      if(ObjectFind("Pivotline") != 0)
      {
      ObjectCreate("Pivotline", OBJ_HLINE, 0, Time[40],P);
      ObjectSet("Pivotline", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("Pivotline", OBJPROP_WIDTH, 1);
      ObjectSet("Pivotline", OBJPROP_COLOR, DarkBlue);
      }
      else
      {
      ObjectMove("Pivotline", 0, Time[40], P);
      }
      
     //----------------------------------------------------- 
              //----------------------------------------------------- 

          if(ObjectFind("U236l") != 0)
      {
      ObjectCreate("U236l", OBJ_TEXT, 0, Time[10], U236);
      ObjectSetText("U236l", "Fibo 23.6%", 9, "Arial", DarkGreen);
      }
      else
      {
      ObjectMove("U236l", 0, Time[10], U236);
      }
           
      if(ObjectFind("U236line") != 0)
      {
      ObjectCreate("U236line", OBJ_HLINE, 0, Time[40],U236);
      ObjectSet("U236line", OBJPROP_STYLE, STYLE_DOT);
      ObjectSet("U236line", OBJPROP_WIDTH, 1);
      ObjectSet("U236line", OBJPROP_COLOR, DarkGreen);
      }
      else
      {
      ObjectMove("U236line", 0, Time[40], U236);
      }
      
     //----------------------------------------------------- 
     
                   //----------------------------------------------------- 

          if(ObjectFind("U382l") != 0)
      {
      ObjectCreate("U382l", OBJ_TEXT, 0, Time[10], U382);
      ObjectSetText("U382l", "Fibo 38.2 %", 9, "Arial", DarkGreen);
      }
      else
      {
      ObjectMove("U382l", 0, Time[10], U382);
      }
           
      if(ObjectFind("U382line") != 0)
      {
      ObjectCreate("U382line", OBJ_HLINE, 0, Time[40],U382);
      ObjectSet("U382line", OBJPROP_STYLE, STYLE_DOT);
      ObjectSet("U382line", OBJPROP_WIDTH, 1);
      ObjectSet("U382line", OBJPROP_COLOR, DarkGreen);
      }
      else
      {
      ObjectMove("U382line", 0, Time[40], U382);
      }
      
     //----------------------------------------------------- 
                        //----------------------------------------------------- 

          if(ObjectFind("U50l") != 0)
      {
      ObjectCreate("U50l", OBJ_TEXT, 0, Time[10], U50);
      ObjectSetText("U50l", "Fibo 50 %", 9, "Arial", DarkGreen);
      }
      else
      {
      ObjectMove("U50l", 0, Time[10], U50);
      }
           
      if(ObjectFind("U50line") != 0)
      {
      ObjectCreate("U50line", OBJ_HLINE, 0, Time[40],U50);
      ObjectSet("U50line", OBJPROP_STYLE, STYLE_DOT);
      ObjectSet("U50line", OBJPROP_WIDTH, 1);
      ObjectSet("U50line", OBJPROP_COLOR, DarkGreen);
      }
      else
      {
      ObjectMove("U50line", 0, Time[40], U50);
      }
      
     //----------------------------------------------------- 
                             //----------------------------------------------------- 

          if(ObjectFind("U618l") != 0)
      {
      ObjectCreate("U618l", OBJ_TEXT, 0, Time[10], U618);
      ObjectSetText("U618l", "Fibo 61.8 %", 9, "Arial", DarkGreen);
      }
      else
      {
      ObjectMove("U618l", 0, Time[10], U618);
      }
           
      if(ObjectFind("U618line") != 0)
      {
      ObjectCreate("U618line", OBJ_HLINE, 0, Time[40],U618);
      ObjectSet("U618line", OBJPROP_STYLE, STYLE_DOT);
      ObjectSet("U618line", OBJPROP_WIDTH, 1);
      ObjectSet("U618line", OBJPROP_COLOR, DarkGreen);
      }
      else
      {
      ObjectMove("U618line", 0, Time[40], U618);
      }
      
     //----------------------------------------------------- 
                                  //----------------------------------------------------- 

          if(ObjectFind("U100l") != 0)
      {
      ObjectCreate("U100l", OBJ_TEXT, 0, Time[10], U100);
      ObjectSetText("U100l", "Fibo 100 %", 9, "Arial", DarkGreen);
      }
      else
      {
      ObjectMove("U100l", 0, Time[10], U100);
      }
           
      if(ObjectFind("U100line") != 0)
      {
      ObjectCreate("U100line", OBJ_HLINE, 0, Time[40],U100);
      ObjectSet("U100line", OBJPROP_STYLE, STYLE_DOT);
      ObjectSet("U100line", OBJPROP_WIDTH, 1);
      ObjectSet("U100line", OBJPROP_COLOR, DarkGreen);
      }
      else
      {
      ObjectMove("U100line", 0, Time[40], U100);
      }
      
     //----------------------------------------------------- 
 //============================================================

              //----------------------------------------------------- 

          if(ObjectFind("D236l") != 0)
      {
      ObjectCreate("D236l", OBJ_TEXT, 0, Time[10], D236);
      ObjectSetText("D236l", "Fibo 23.6%", 9, "Arial", Maroon );
      }
      else
      {
      ObjectMove("D236l", 0, Time[10], D236);
      }
           
      if(ObjectFind("D236line") != 0)
      {
      ObjectCreate("D236line", OBJ_HLINE, 0, Time[40],D236);
      ObjectSet("D236line", OBJPROP_STYLE, STYLE_DOT);
      ObjectSet("D236line", OBJPROP_WIDTH, 1);
      ObjectSet("D236line", OBJPROP_COLOR, Maroon);
      }
      else
      {
      ObjectMove("D236line", 0, Time[40], D236);
      }
      
     //----------------------------------------------------- 
     
                   //----------------------------------------------------- 

          if(ObjectFind("D382l") != 0)
      {
      ObjectCreate("D382l", OBJ_TEXT, 0, Time[10], D382);
      ObjectSetText("D382l", "Fibo 38.2 %", 9, "Arial", Maroon);
      }
      else
      {
      ObjectMove("D382l", 0, Time[10], D382);
      }
           
      if(ObjectFind("D382line") != 0)
      {
      ObjectCreate("D382line", OBJ_HLINE, 0, Time[40],D382);
      ObjectSet("D382line", OBJPROP_STYLE, STYLE_DOT);
      ObjectSet("D382line", OBJPROP_WIDTH, 1);
      ObjectSet("D382line", OBJPROP_COLOR, Maroon);
      }
      else
      {
      ObjectMove("D382line", 0, Time[40], D382);
      }
      
     //----------------------------------------------------- 
                        //----------------------------------------------------- 

          if(ObjectFind("D50l") != 0)
      {
      ObjectCreate("D50l", OBJ_TEXT, 0, Time[10], D50);
      ObjectSetText("D50l", "Fibo 50 %", 9, "Arial", Maroon);
      }
      else
      {
      ObjectMove("D50l", 0, Time[10], D50);
      }
           
      if(ObjectFind("D50line") != 0)
      {
      ObjectCreate("D50line", OBJ_HLINE, 0, Time[40],D50);
      ObjectSet("D50line", OBJPROP_STYLE, STYLE_DOT);
      ObjectSet("D50line", OBJPROP_WIDTH, 1);
      ObjectSet("D50line", OBJPROP_COLOR, Maroon);
      }
      else
      {
      ObjectMove("D50line", 0, Time[40], D50);
      }
      
     //----------------------------------------------------- 
                             //----------------------------------------------------- 

          if(ObjectFind("D618l") != 0)
      {
      ObjectCreate("D618l", OBJ_TEXT, 0, Time[10], D618);
      ObjectSetText("D618l", "Fibo 61.8 %", 9, "Arial", Maroon);
      }
      else
      {
      ObjectMove("D618l", 0, Time[10], D618);
      }
           
      if(ObjectFind("D618line") != 0)
      {
      ObjectCreate("D618line", OBJ_HLINE, 0, Time[40],D618);
      ObjectSet("D618line", OBJPROP_STYLE, STYLE_DOT);
      ObjectSet("D618line", OBJPROP_WIDTH, 1);
      ObjectSet("D618line", OBJPROP_COLOR, Maroon);
      }
      else
      {
      ObjectMove("D618line", 0, Time[40], D618);
      }
      
     //----------------------------------------------------- 
                                  //----------------------------------------------------- 

          if(ObjectFind("D100l") != 0)
      {
      ObjectCreate("D100l", OBJ_TEXT, 0, Time[10], D100);
      ObjectSetText("D100l", "Fibo 100 %", 9, "Arial", Maroon);
      }
      else
      {
      ObjectMove("D100l", 0, Time[10], D100);
      }
           
      if(ObjectFind("D100line") != 0)
      {
      ObjectCreate("D100line", OBJ_HLINE, 0, Time[40],D100);
      ObjectSet("D100line", OBJPROP_STYLE, STYLE_DOT);
      ObjectSet("D100line", OBJPROP_WIDTH, 1);
      ObjectSet("D100line", OBJPROP_COLOR, Maroon);
      }
      else
      {
      ObjectMove("D100line", 0, Time[40], D100);
      }
      //--------------------------------------------------
      
                if(ObjectFind("U1618l") != 0)
      {
      ObjectCreate("U1618l", OBJ_TEXT, 0, Time[10], U1618);
      ObjectSetText("U1618l", "Fibo 161.8 %", 9, "Arial", DarkGreen);
      }
      else
      {
      ObjectMove("U1618l", 0, Time[10], U1618);
      }
           
      if(ObjectFind("U1618line") != 0)
      {
      ObjectCreate("U1618line", OBJ_HLINE, 0, Time[40],U1618);
      ObjectSet("U1618line", OBJPROP_STYLE, STYLE_DOT);
      ObjectSet("U1618line", OBJPROP_WIDTH, 1);
      ObjectSet("U1618line", OBJPROP_COLOR, DarkGreen);
      }
      else
      {
      ObjectMove("U1618line", 0, Time[40], U1618);
      }
      
      //----------------------------------------------
            
                if(ObjectFind("D1618l") != 0)
      {
      ObjectCreate("D1618l", OBJ_TEXT, 0, Time[10], D1618);
      ObjectSetText("D1618l", "Fibo 161.8 %", 9, "Arial", Maroon);
      }
      else
      {
      ObjectMove("D1618l", 0, Time[10], D1618);
      }
           
      if(ObjectFind("D1618line") != 0)
      {
      ObjectCreate("D1618line", OBJ_HLINE, 0, Time[40],D1618);
      ObjectSet("D1618line", OBJPROP_STYLE, STYLE_DOT);
      ObjectSet("D1618line", OBJPROP_WIDTH, 1);
      ObjectSet("D1618line", OBJPROP_COLOR, Maroon);
      }
      else
      {
      ObjectMove("D1618line", 0, Time[40], D1618);
      }
      
      //----------------------------------------------
      
      
   string Credits ="Dr.Mahmoud A. (AKA:Dr.GM) [email protected] " + "\n" + "Ogeima" ; // + " add your name here"
  Text =   "Created By: " + "\n"+  Credits + "\n" ;
 

   Comment(Text);
//----
   return(0);
  }
//+------------------------------------------------------------------+

Recommend