CPR (Central Pivot Range)

Created at 27 Aug 2013, 04:48
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
Capo85's avatar

Capo85

Joined 27.08.2013

CPR (Central Pivot Range)
27 Aug 2013, 04:48


Hello,

I tried converting this indicator using the MQ4 to C# converter but it did not work. I can have the camarilla pivots removed. Can someone please help convert this to CAlgo? I can show everyone alot of useful trading strategies with the 2 day pivot relationships using the CPR. 

 

Thanks so much

The Mq4 Code starts below:

 

 

 


//+------------------------------------------------------------------+
//|                                              SDK-Pivots-v1.2.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright 2011, f451"
#property link      ""

/*------------------------------------------------------------------------------------
Introduction:

  
   Time-Zone Inputs:

   LocalTimeZone: TimeZone for which MT4 shows your local time, 
                  e.g. 1 or 2 for Europe (GMT+1 or GMT+2 (daylight 
                  savings time).  Use zero for no adjustment.                 
                  The MetaQuotes demo server uses GMT +2.
                  
   DestTimeZone:  TimeZone for the session from which to calculate
                  the levels (e.g. 1 or 2 for the European session
                  (without or with daylight savings time).  
                  Use zero for GMT
                             
   Example: If your MT server is living in the EST (Eastern Standard Time, 
            GMT-5) zone and want to calculate the levels for the London trading
            session (European time in summer GMT+1), then enter -5 for 
            LocalTimeZone, 1 for Dest TimeZone. 
            
            Please understand that the LocalTimeZone setting depends on the
            time on your MetaTrader charts (for example the demo server 
            from MetaQuotes always lives in CDT (+2) or CET (+1), no matter
            what the clock on your wall says. If in doubt, leave everything to zero.
---------------------------------------------------------------------------------------

SDK-Pivots-v1.2:  

                                                                                               
--------------------------------------------------------------------------------*/

#property indicator_chart_window
extern bool   Indicator_On?                  = true;
extern int    Local_HrsServerTzFromGMT       = 3;    //Data collection Tz of your server
extern int    Dest_HrsNewTZfromGMT           = 0;    //New destination Tz governing data
extern int    Show_1Daily_2FibonacciPivots   = 1;
extern bool   FullScreenLines                = false;
extern bool   withMarginPrices               = true;
extern bool   LineLabelsIncludePrice         = true;
extern int    MoveLabels_LR_DecrIncr         = 0;    //-# to move left, +# to move right
extern int    PercentageOffset               = 25;   //-# to move left, +# to move right
extern color  PivotLinesLabelColor           = Gray;
extern int    LineLabelsFontSize             = 8;
extern int    L_Label_Norm_Bold_Black_123    = 2;
extern int    ZoomAdjust_3_6_15_30_50        = 20;    //for 8,9 fontsize: 2, 5, 10, 20, 40
extern color  R_Color                        = Crimson;
extern int    R_LineStyle_01234              = 2;
extern int    R_SolidLineThickness           = 1; 
extern color  CentralPivotColor              = PaleGoldenrod;
extern int    CentralPivotLineStyle_01234    = 0;
extern int    CentralPivotSolidLineThickness = 1; 
extern color  C_Color                        = Yellow;
extern int    C_LineStyle_01234              = 0;
extern int    C_SolidLineThickness           = 2; 
extern bool   ShowTwoDayPivots               = true;
extern color  S_Color                        = CornflowerBlue;
extern int    S_LineStyle_01234              = 2;
extern int    S_SolidLineThickness           = 1; 
extern color  MidPivotsColor                 = Gray;
extern int    MidPivotsLineStyle_01234       = 2;
extern int    MidPivotsLineThickness         = 1; 
extern bool   ShowMidPivots                  = true;
extern color  YesterdayHighLowColor          = BurlyWood;
extern int    HighLowLineStyle_01234         = 2;
extern int    HighLowSolidLineThickness      = 1; 
extern bool   ShowYesterdayHighLow           = true;
extern color  TodayOpenColor                 = Gainsboro;
extern int    TodayOpenLineStyle_01234       = 2;
extern int    TodayOpenSolidLineThickness    = 1; 
extern bool   ShowTodayOpen                  = true;
extern color  CamarillaHiColor               = LightSkyBlue;
extern color  CamarillaLoColor               = IndianRed;
extern int    CamarillaLineStyle_01234       = 0;
extern int    CamarillaSolidLineThickness    = 1; 
extern bool   ShowCamarilla                  = true;
extern bool   ShowInnerCamarillas            = false;
extern color  PeriodSeparatorLinesColor      = RosyBrown;
extern int    SeparatorLinesStyle_01234      = 2;
extern int    SeparatorLinesThickness        = 1;
extern bool   ShowPeriodSeparatorLines       = true;
extern color  PeriodSeparatorsLabelsColor    = DarkGray;
extern int    PlaceAt_TopBot_12_OfChart      = 2;
extern int    SeparatorLabelFontSize         = 8;
extern int    S_Label_Norm_Bold_Black_123    = 2;
extern bool   ShowPeriodSeparatorLabels      = true;
extern int    Relabeler_Adjustment           = 8;       //-# to advance trigger, +# to delay trigger
extern bool   Show_Relabeler_Comment         = false;
extern bool   Show_Data_Comment              = true;
extern int    Days                           = 5;       // number of Days back to calculate pivots and central pivot range.

int MoveLabels, MoveLabels2;
int A,B; //relabeler triggers
int digits; //decimal digits for symbol's price
int offset;
double pts;

string ObjPivot = "[PIVOT]";
string ObjCamarilla = "[CAMARILLA]";
string ObjSeparator = "[TIME]";

string dayString[];
int idxfirstbar[];
int idxlastbar[];
double day_open[];
double day_close[];
double day_high[];
double day_low[];
double p[];
double bc[];
double tc[];


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
   pts = MarketInfo( Symbol(), MODE_POINT  ); 
   if (Digits == 5 || (Digits == 3 && StringFind(Symbol(), "JPY") != -1))
    { pts = Point*10; }
    else if (Digits == 6 || (Digits == 4 && StringFind(Symbol(), "JPY") != -1))
    { pts = Point*100; }
    else
    { pts = Point; }

    if (Ask>10) digits=2; else digits=4;
   return(0);
}

//+------------------------------------------------------------------+
//| Custom indicator de-initialization function                      |
//+------------------------------------------------------------------+
int deinit()
{
   int obj_total= ObjectsTotal(); 
   for (int i= obj_total; i>=0; i--)
   {
      string name= ObjectName(i);   
      if ((StringSubstr(name,0,7)==ObjPivot) || (StringSubstr(name,0,11)==ObjCamarilla) || (StringSubstr(name,0,6)==ObjSeparator)) ObjectDelete(name);
   }    
   Comment(" ");
   return(0);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   if (Indicator_On? == false) {deinit();return(0);}
   if (Period() > PERIOD_H4) {deinit();return(0);}
   
   MoveLabels = (WindowFirstVisibleBar()/2)- MoveLabels_LR_DecrIncr;
   MoveLabels2=  MoveLabels+ZoomAdjust_3_6_15_30_50;
   
   static datetime timelastupdate= 0;
   static datetime lasttimeframe= 0;  
   
   datetime startofday= 0,
            startline= 0,
            endline=0,
            startlabel= 0;
                 
   ArrayResize(dayString,Days+1);
   ArrayResize(day_open,Days+1);
   ArrayResize(day_close,Days+1);
   ArrayResize(day_high,Days+1);
   ArrayResize(day_low,Days+1);
   ArrayResize(p,Days+1);
   ArrayResize(bc,Days+1);
   ArrayResize(tc,Days+1);
   ArrayResize(idxfirstbar,Days+1);
   ArrayResize(idxlastbar,Days+1);
             
   lasttimeframe= Period();
   timelastupdate= CurTime();   
 
   //-----let's find out which bars mark the beginning and end going back the user specified days -----
   ComputeDayIndices(Local_HrsServerTzFromGMT, Dest_HrsNewTZfromGMT, Days);   
   GetOHLC(idxfirstbar,idxlastbar, day_open, day_high, day_low, day_close);
   
   // set label offset
   int PC = idxfirstbar[1]-idxlastbar[1]; //# of bars btwn day separators - use as offset
   offset = MathRound((PercentageOffset/100) * PC); 
    
   //----relabeler code--------------------------------------------------------------------------------------
   A=0; B=0; //reset:  relabeler off, margin labels off
   if (FullScreenLines == true && withMarginPrices == true) {B = 1;} //B=1 asserts margin labels
   if (FullScreenLines == true && withMarginPrices == false){B = 0;} //B=0 prevents margin labels
   if (FullScreenLines == false)
   {
      int AA = WindowFirstVisibleBar();  //# of visible bars on chart
      int BB = ( (Time[0]-Time[idxfirstbar[0]])/(Period()*60)); //# of bars btwn current time and first day separator   
      int RR = (AA - BB); //# number of bars btwn first day Separator and chart left margin
      int AL = Relabeler_Adjustment; //default of zero activates relabeler as first day separator goes off-screen
      if (RR >  AL){A = 0;} //labels not near enough to chart left margin to trigger relabeler
      if (RR <= AL){A = 1; if(withMarginPrices == true) B = 1;} //labels close enough - switch to full-screen 
   }
       
   //----Autolabeler test comment
   string test = "A = "+A+",  ";  
   test = test + "Current time to Separator = "+BB+" candles.";
   test = test + "   Separator to Chart left = "+RR+" candles.";
   test = test + "   Total candles visable = "+AA+" candles.";   
   test = test + "   Relabeler is set to trigger when Separator is  "+AL+"  candles from chart left. \n";
   test = test + "   Number of candles between days = " + PC;
   if(Show_Relabeler_Comment ==true){Comment(test);} else {Comment (" ");}
   
   //----clear all objects before redrawing screen
   int obj_total= ObjectsTotal(); 
   for (int x= obj_total; x>=0; x--)
   {
      string name= ObjectName(x);   
      if((StringSubstr(name,0,7)==ObjPivot) || (StringSubstr(name,0,11)==ObjCamarilla) || (StringSubstr(name,0,6)==ObjSeparator)) ObjectDelete(name);
   }    

   //------draw the vertical bars/labels that mark the session spans------------------------------------------
   if(ShowPeriodSeparatorLines == true)
   {
      int DZ = Dest_HrsNewTZfromGMT;
      string GMT = "(GMT +0)  ";
      if(DZ>0 &&  DZ<10) {GMT = "(GMT +"+ Dest_HrsNewTZfromGMT +")  ";}
      if(DZ>9) {GMT = "(GMT +"+ Dest_HrsNewTZfromGMT +")";}
      if(DZ<0 &&  DZ>-10) {GMT = "(GMT +"+ Dest_HrsNewTZfromGMT +")  ";}
      if(DZ<-9) GMT = "(GMT "+ Dest_HrsNewTZfromGMT +")";
      if(SeparatorLinesStyle_01234>0) {SeparatorLinesThickness=1;}
      double top = WindowPriceMax();
       double bottom = WindowPriceMin();
       double scale = top - bottom;    
       double YadjustTop = scale/5000; //250;
       double YadjustBot = scale/(350/SeparatorLabelFontSize);     
      double level = top - YadjustTop; if (PlaceAt_TopBot_12_OfChart==2){level = bottom + YadjustBot;}
      for (int dy = 0; dy < Days; dy++)
      {
         SetTimeLine("Day "+DoubleToStr(dy,0), dayString[dy] + GMT, idxfirstbar[dy]+0,  PeriodSeparatorsLabelsColor, level);
      }    
   }
    
   //---- Calculate Pivot Levels ------------------------------------------------------------------------------- 
   // TODO: generalise all pivot calcs at some point
   double q, d, r1,r2,r3,r4,r5, s1,s2,s3,s4,s5;
   
   d     = (day_high[0] - day_low[0]);
   q     = (day_high[1] - day_low[1]); // RANGE
   
   // calculate pivots going back as many days as specified
   for (int idx = 1; idx <= Days; idx++)
   {
      p[idx]  = (day_high[idx] + day_low[idx] + day_close[idx]) / 3;  
      bc[idx] = (day_high[idx] + day_low[idx])/2;
      tc[idx]  = 2*p[idx] - bc[idx];
      
      if (bc[idx] > tc[idx])
      {
         double temp = bc[idx];
         bc[idx] = tc[idx];
         tc[idx] = temp;
      
      }
   }
   
   if(Show_1Daily_2FibonacciPivots == 1) 
   {
      r1 = (2*p[1])-day_low[1];
      r2 = p[1]+(day_high[1] - day_low[1]);       //r2 = p-s1+r1;
      r3 = (2*p[1])+(day_high[1]-(2*day_low[1])); // r3 = r1 + (day_high[1] - yersterday_low);
      r4 = r3 + (r2 - r1);
      s1 = (2*p[1])-day_high[1];
      s2 = p[1]-(day_high[1] - day_low[1]);                 //s2 = p-r1+s1;
      s3 = (2*p[1])-day_high[1] - (day_high[1]-day_low[1]); // s3 = s1 - (day_high[1] - day_low[1]);
      s4 = s3 - (s1-s2);
   }
   if(Show_1Daily_2FibonacciPivots == 2)
   {
      r1 = p[1] + (q * 0.382);   
      r2 = p[1] + (q * 0.618);  
        r3 = p[1] +  q;  
      r4 = p[1] + (q * 1.618);
      r5 = p[1] + (q * 2.618);
      s2 = p[1] - (q * 0.618);   
      s1 = p[1] - (q * 0.382); 
         s3 = p[1] -  q; 
      s4 = p[1] - (q * 1.618);
      s5 = p[1] - (q * 2.618);
   }
   if(FullScreenLines==false&&A==0) //lines start at separators, no margin labels in this mode
   {
       startlabel= Time[idxfirstbar[0]+offset]; 
       startline = Time[idxfirstbar[0]+1];  //was "+1", "+0" stops line at Separator
       if (Time[0] > Time[idxfirstbar[0]]){startline = Time[idxfirstbar[0]];}
   }
   if(FullScreenLines==false&&A==1) //lines started at separators, but switched to full screen, value of B governs margin labels
   {
       startlabel= Time[MoveLabels]+offset;
       startline = WindowFirstVisibleBar();
   }      
   if(FullScreenLines==true) //lines selected to be full screen, margin labels governed by value of B in relabeler code
   {
       startlabel=Time[MoveLabels]+offset;     
       startline = WindowFirstVisibleBar();
   } 
   if(R_LineStyle_01234>0){R_SolidLineThickness=0;} 
   if(S_LineStyle_01234>0){S_SolidLineThickness=0;} 
   if(C_LineStyle_01234>0){S_SolidLineThickness=0;} 
   SetLevel(" R5 ", r5, R_Color, R_LineStyle_01234, R_SolidLineThickness, startline, startlabel, B);  
   SetLevel(" R4 ", r4, R_Color, R_LineStyle_01234, R_SolidLineThickness, startline, startlabel, B);
   SetLevel(" R3 ", r3, R_Color, R_LineStyle_01234, R_SolidLineThickness, startline, startlabel, B);   
   SetLevel(" R2 ", r2, R_Color, R_LineStyle_01234, R_SolidLineThickness, startline, startlabel, B); 
   SetLevel(" R1 ", r1, R_Color, R_LineStyle_01234, R_SolidLineThickness, startline, startlabel, B); 
   SetLevel(" BC ", bc[1], C_Color, C_LineStyle_01234, C_SolidLineThickness, startline, startlabel, B); 
   SetLevel(" TC ", tc[1], C_Color, C_LineStyle_01234, C_SolidLineThickness, startline, startlabel, B); 
   
   if(Show_1Daily_2FibonacciPivots == 1)
   {     
      SetLevel(" PV ", p[1], CentralPivotColor, CentralPivotLineStyle_01234 , CentralPivotSolidLineThickness, startline, startlabel, B);
   }
   if(Show_1Daily_2FibonacciPivots == 2)
   {  
      SetLevel(" FPV ", p[1], CentralPivotColor, CentralPivotLineStyle_01234 , CentralPivotSolidLineThickness, startline, startlabel, B);
   }    
   SetLevel(" S1 ", s1, S_Color, S_LineStyle_01234, S_SolidLineThickness, startline, startlabel, B);
   SetLevel(" S2 ", s2, S_Color, S_LineStyle_01234, S_SolidLineThickness, startline, startlabel, B);
   SetLevel(" S3 ", s3, S_Color, S_LineStyle_01234, S_SolidLineThickness, startline, startlabel, B);    
   SetLevel(" S4 ", s4, S_Color, S_LineStyle_01234, S_SolidLineThickness, startline, startlabel, B);
   SetLevel(" S5 ", s5, S_Color, S_LineStyle_01234, S_SolidLineThickness, startline, startlabel, B);
   
   //----- Camarilla Lines
   if (ShowCamarilla==true) 
   {
      if(CamarillaLineStyle_01234>0){CamarillaSolidLineThickness=0;}
      double cr5, cr4, cr3, cr2, cr1, cs1, cs2, cs3, cs4, cs5; // Expanded Camarilla Equation values based on Frank Ochoa
      cr5 = (day_high[1]/day_low[1])*day_close[1];
      cr4 = (q*0.55)+day_close[1];
      cr3 = (q*0.275)+day_close[1];
       cr2 = (q*0.1833)+day_close[1];
       cr1 = (q*0.09167)+day_close[1];
       cs1 = day_close[1]-(q*0.09167);    
       cs2 = day_close[1]-(q*0.1833);
       cs3 = day_close[1]-(q*0.275);
       cs4 = day_close[1]-(q*0.55);
       cs5 = day_close[1]-(cr5-day_close[1]);    
       if (ShowInnerCamarillas)
       {
          SetLevel(" R1 ", cr1, CamarillaLoColor, CamarillaLineStyle_01234, CamarillaSolidLineThickness, startline, startlabel, B, 0, 1);
         SetLevel(" R2 ", cr2, CamarillaLoColor, CamarillaLineStyle_01234, CamarillaSolidLineThickness, startline, startlabel, B, 0, 1);
         SetLevel(" S1 ", cs1, CamarillaHiColor, CamarillaLineStyle_01234, CamarillaSolidLineThickness, startline, startlabel, B, 0, 1);
         SetLevel(" S2 ", cs2, CamarillaHiColor, CamarillaLineStyle_01234, CamarillaSolidLineThickness, startline, startlabel, B, 0, 1);
       }       
      SetLevel(" R3 ", cr3, CamarillaLoColor, CamarillaLineStyle_01234, CamarillaSolidLineThickness, startline, startlabel, B, 0, 1);
      SetLevel(" R4 ", cr4, CamarillaLoColor, CamarillaLineStyle_01234, CamarillaSolidLineThickness, startline, startlabel, B, 0, 1);
      SetLevel(" R5 ", cr5, CamarillaLoColor, CamarillaLineStyle_01234, CamarillaSolidLineThickness, startline, startlabel, B, 0, 1);
      SetLevel(" S3 ", cs3, CamarillaHiColor, CamarillaLineStyle_01234, CamarillaSolidLineThickness, startline, startlabel, B, 0, 1);
      SetLevel(" S4 ", cs4, CamarillaHiColor, CamarillaLineStyle_01234, CamarillaSolidLineThickness, startline, startlabel, B, 0, 1);
      SetLevel(" S5 ", cs5, CamarillaHiColor, CamarillaLineStyle_01234, CamarillaSolidLineThickness, startline, startlabel, B, 0, 1);
   }
   
   //------ Midpoints Pivots (mid-levels between pivots)
   if (ShowMidPivots==true) 
   {
      if(FullScreenLines==false&&A==0)
      {
         startlabel= Time[idxfirstbar[0]+offset]; 
         startline = Time[idxfirstbar[0]+1];  //was "+1", "+0" stops line at Separator
         if (Time[0] > Time[idxfirstbar[0]]){startline = Time[idxfirstbar[0]];}
      }
      if(FullScreenLines==false&&A==1)
      {
         startlabel= Time[MoveLabels]+offset;
         startline = WindowFirstVisibleBar();
      } 
      if(FullScreenLines==true)
      {
         startlabel=Time[MoveLabels]+offset;     
         startline = WindowFirstVisibleBar();
      }          
      if(MidPivotsLineStyle_01234>0){MidPivotsLineThickness=0;}
      SetLevel(" mR5", (r4+r5)/2, MidPivotsColor, MidPivotsLineStyle_01234, MidPivotsLineThickness, startline, startlabel, B);
      SetLevel(" mR4", (r3+r4)/2, MidPivotsColor, MidPivotsLineStyle_01234, MidPivotsLineThickness, startline, startlabel, B);
      SetLevel(" mR3", (r2+r3)/2, MidPivotsColor, MidPivotsLineStyle_01234, MidPivotsLineThickness, startline, startlabel, B);
      SetLevel(" mR2", (r1+r2)/2, MidPivotsColor, MidPivotsLineStyle_01234, MidPivotsLineThickness, startline, startlabel, B);
      SetLevel(" mR1", (p[1]+r1)/2,  MidPivotsColor, MidPivotsLineStyle_01234, MidPivotsLineThickness, startline, startlabel, B);
      SetLevel(" mS1", (p[1]+s1)/2,  MidPivotsColor, MidPivotsLineStyle_01234, MidPivotsLineThickness, startline, startlabel, B);
      SetLevel(" mS2", (s1+s2)/2, MidPivotsColor, MidPivotsLineStyle_01234, MidPivotsLineThickness, startline, startlabel, B);
      SetLevel(" mS3", (s2+s3)/2, MidPivotsColor, MidPivotsLineStyle_01234, MidPivotsLineThickness, startline, startlabel, B);
      SetLevel(" mS4", (s3+s4)/2, MidPivotsColor, MidPivotsLineStyle_01234, MidPivotsLineThickness, startline, startlabel, B);
      SetLevel(" mS5", (s4+s5)/2, MidPivotsColor, MidPivotsLineStyle_01234, MidPivotsLineThickness, startline, startlabel, B);
   }

   //---- Yesterday High/Low
   if (ShowYesterdayHighLow == true)
   {
      if(FullScreenLines==false&&A==0)
      {
         startlabel= Time[idxfirstbar[0]+1+ZoomAdjust_3_6_15_30_50 ]; 
         startline = Time[idxfirstbar[1]+1];  //was "+1", "+0" stops line at Separator
         if (Time[0] > Time[idxfirstbar[0]]){startline = Time[idxfirstbar[1]];}
      }
      if(FullScreenLines==false&&A==1)
      {
         startlabel= Time[MoveLabels2];
         startline = WindowFirstVisibleBar(); 
      } 
      if(FullScreenLines==true)
      {
        startlabel=Time[MoveLabels2];     
        startline = WindowFirstVisibleBar();
      }  
      if(HighLowLineStyle_01234>0){HighLowSolidLineThickness=0;}
      SetLevel(" yHigh",day_high[1],YesterdayHighLowColor,HighLowLineStyle_01234, HighLowSolidLineThickness, startline, startlabel, B);      
      SetLevel(" yLow ",day_low[1],YesterdayHighLowColor,HighLowLineStyle_01234, HighLowSolidLineThickness, startline, startlabel, B);
   }

   //---- Today Open
   if (ShowTodayOpen == true)
   {
      if(FullScreenLines==false&&A==0)
      {
         startlabel= Time[idxfirstbar[0]+1+ZoomAdjust_3_6_15_30_50]; 
         startline = Time[idxfirstbar[0]+1+ZoomAdjust_3_6_15_30_50];  //was "+1", "+0" stops line at Separator
      }
      if(FullScreenLines==false&&A==1)
      {
         startlabel= Time[MoveLabels2];
         startline = WindowFirstVisibleBar();
      } 
      if(FullScreenLines==true)
      {
         startlabel=Time[MoveLabels2];     
         startline = WindowFirstVisibleBar();
      }  
      if(TodayOpenLineStyle_01234>0){TodayOpenSolidLineThickness=0;} 
      SetLevel(" Open", day_open[0],TodayOpenColor,TodayOpenLineStyle_01234, TodayOpenSolidLineThickness, startline, startlabel, B);
   }

   if (ShowTwoDayPivots)
   {
      for (idx = 2; idx <=Days; idx++)
      {
         startlabel= Time[idxlastbar[idx]-1+offset];  
         startline = Time[idxlastbar[idx]-1];  //was "+1", "+0" stops line at Separator
         endline   = Time[idxlastbar[idx-1]-1]; 
         SetLevel(" BC "+DoubleToStr(idx,0), bc[idx], C_Color, C_LineStyle_01234, C_SolidLineThickness, startline, startlabel, 0, endline); 
         SetLevel(" TC "+DoubleToStr(idx,0), tc[idx], C_Color, C_LineStyle_01234, C_SolidLineThickness, startline, startlabel, 0, endline);
         SetLevel(" PV "+DoubleToStr(idx,0), p[idx], CentralPivotColor, CentralPivotLineStyle_01234, CentralPivotSolidLineThickness, startline, startlabel, 0, endline);
      }
   }

   //------ Comment for upper left corner
   if (Show_Data_Comment) 
   {
      string comment= "\n";      
      comment= comment + "Range: Yesterday "+DoubleToStr(MathRound(q/pts),0) 
                       +" pips, Today "+DoubleToStr(MathRound(d/pts),0)+" pips" + "\n";
      comment= comment + "Highs: Yesterday "+DoubleToStr(day_high[1],Digits)  
                       +", Today "+DoubleToStr(day_high[0],Digits) +"\n";
      comment= comment + "Lows:  Yesterday "+DoubleToStr(day_low[1],Digits)  
                       +", Today "+DoubleToStr(day_low[0],Digits)  +"\n";
      comment= comment + "Close: Yesterday "+DoubleToStr(day_close[1],Digits) + "\n";
      comment= comment + "Pivot: Yesterday " + DoubleToStr(p[2],Digits) + " Today " + DoubleToStr(p[1],Digits) + "\n";
      comment= comment + "Central Pivot Range: Yesterday " + DoubleToStr(MathRound((tc[2]-bc[2])/pts),0)+" pips, Today " + DoubleToStr(MathRound((tc[1]-bc[1])/pts),0)+" pips" + "\n";
      comment= comment + "Fibos: 38.2% " + DoubleToStr(day_low[1] + q*0.382, Digits) + ", " + DoubleToStr(day_high[1] - q*0.382,Digits) + "\n"; 
      comment= comment + "Fibos: 61.8% " + DoubleToStr(day_low[1] + q*0.618, Digits) + ", " + DoubleToStr(day_high[1] - q*0.618,Digits) + "\n";                      
      Comment(comment); 
   }
   return(0);


//+-------------------------------------------------------------------------------------+
//| Get Open, High, Low, Close of the day                                               |
//+-------------------------------------------------------------------------------------+
void GetOHLC(int idxfirstbar[], int idxlastbar[], double &open[], double &high[], double &low[], double &close[])
{
   //------walk forward through user specificed number of days and collect high/lows within the day------------------------------
   for (int d = 0; d <= Days; d++)
   {
      high[d] = -99999; // not high enough to remain alltime high
      low[d] =  +99999; // not low enough to remain alltime low
      for (int k = idxfirstbar[d]; k>=idxlastbar[d]; k--)
      {
         if (open[d]==0)  // grab first value for open
         open[d]= Open[k];                           
         high[d]= MathMax(High[k], high[d]);
         low[d]= MathMin(Low[k], low[d]);      
         // overwrite close in loop until we leave with the last iteration's value
         close[d]= Close[k];
      }
   } 
}

//+-------------------------------------------------------------------------------------+
//| Compute index of first/last bar of Yesterday and today                              |
//+-------------------------------------------------------------------------------------+
void ComputeDayIndices(int tzlocal, int tzdest, int days)
{     
   int tzdiff= tzlocal - tzdest,
       tzdiffsec= tzdiff*3600,
       dayminutes= 24 * 60,
       barsperday= dayminutes/Period();
   
   int dayofweek= TimeDayOfWeek(Time[0] - tzdiffsec),  // what day is today in the dest timezone?
       dayofweektofind= -1; 
      // due to gaps in the data, and shift of time around weekends (due 
      // to time zone) it is not as easy as to just look back for a bar 
      // with 00:00 time 
       
   idxfirstbar[0]= 0; 
   for (int z = 0; z <= days; z++)
   {
      switch (dayofweek) 
      { 
         case 6: // sat
         case 0: // sun
         case 1: // mon
               dayofweektofind = 5; // Yesterday in terms of trading was previous friday
               break;           
         default:
               dayofweektofind = dayofweek -1;
               break;
      }
      //----search  backwards for the last occurrence (backwards) of the day today (today's first bar)-----------
      for (int i=(z*barsperday)+1; i<=(z+1)*barsperday+1; i++) 
      {
         datetime timec= Time[i] - tzdiffsec;
         if (TimeDayOfWeek(timec)!=dayofweek) 
         {
            idxfirstbar[z]= i-1;
            idxlastbar[z+1] = i;
            break;
         }
      }
      if (dayofweektofind == 1)  { dayString[z+1] = "      Monday    "; dayString[z] = "     Tuesday    ";}  
      if (dayofweektofind == 2)  { dayString[z+1] = "     Tuesday    "; dayString[z] = "Wednesday    ";}
      if (dayofweektofind == 3)  { dayString[z+1] = "Wednesday    "; dayString[z] = "    Thursday    ";}
      if (dayofweektofind == 4)  { dayString[z+1] = "    Thursday    "; dayString[z] = "        Friday    ";}
      if (dayofweektofind == 5)  { dayString[z+1] = "        Friday    "; dayString[z] = "      Monday    ";}
      dayofweek = dayofweektofind;
   }
}

//+-----------------------------------------------------------------------------------------+
//| Helper sub-routine that creates lines and their labels                                  |                                                                                  |
//+-----------------------------------------------------------------------------------------+
void SetLevel(string text, double level, color col1, int linestyle,
        int thickness, datetime startline, datetime startlabel, int CC, datetime endline = 0, int type = 0)
{
   int digits= Digits; 
   string labelname, linename, pricelabel;
   
   if (endline==0) endline = Time[0];
   if (type == 1)  // scope to include Obj for Central Pivots etc etc
   {
      labelname = ObjCamarilla+" " + text + " Label";
      linename= ObjCamarilla + " " + text + " Line";
   }
   else
   {
      labelname = ObjPivot+" " + text + " Label";
      linename= ObjPivot + " " + text + " Line";
   }

   //----create or move the horizontal line-------------------------------------------------      
   int Z;
   if (CC == 0){Z = OBJ_TREND;}
   if (CC == 1){Z = OBJ_HLINE;}  
   if (ObjectFind(linename) != 0) 
   {
       ObjectCreate(linename, Z, 0, startline, level, endline, level);
       ObjectSet   (linename, OBJPROP_RAY, false);
       ObjectSet   (linename, OBJPROP_STYLE, linestyle);
       ObjectSet   (linename, OBJPROP_COLOR, col1);
       ObjectSet   (linename, OBJPROP_WIDTH, thickness);
       ObjectSet   (linename, OBJPROP_BACK, true); 
   }
   else
   {
       ObjectMove  (linename, 1, endline, level);
       ObjectMove  (linename, 0, startline, level);
   }     
 
   //----create or move the labels-----------------------------------------------------------
     string FontStyle;   
     if (L_Label_Norm_Bold_Black_123 <= 1){FontStyle = "Arial";}
     if (L_Label_Norm_Bold_Black_123 == 2){FontStyle = "Arial Bold";}
     if (L_Label_Norm_Bold_Black_123 >= 3){FontStyle = "Arial Black";}
     pricelabel= "                         " + text;
     if (LineLabelsIncludePrice && StrToInteger(text)==0) {pricelabel= pricelabel + ": "+DoubleToStr(level, Digits);}  
     
     if (ObjectFind(labelname) != 0)
     {
        ObjectCreate  (labelname, OBJ_TEXT, 0, startlabel, level);       
        ObjectSetText (labelname, pricelabel, LineLabelsFontSize, FontStyle, PivotLinesLabelColor);
        ObjectSet     (labelname, OBJPROP_BACK, true); 
     }
     else
     {
        ObjectMove(labelname, 0, startlabel, level);
     }       
}

//+-------------------------------------------------------------------------------------------+
//| Helper=draws vertical timelines & gets "Yesterday/today" from elsewhere and displays them.|                                                        
//+-------------------------------------------------------------------------------------------+
void SetTimeLine(string objname, string text, int idx, color col1, double vleveltext) 
{
   string FontStyle; string name= "[TIME] " + objname; int x= Time[idx];
   if (ObjectFind(name) != 0)
   { 
      ObjectCreate(name, OBJ_TREND, 0, x, 0, x, 100);
      ObjectSet(name, OBJPROP_STYLE, SeparatorLinesStyle_01234);
      ObjectSet(name, OBJPROP_COLOR, PeriodSeparatorLinesColor);
      ObjectSet(name, OBJPROP_WIDTH, SeparatorLinesThickness); 
   }
   else 
   {
      ObjectMove(name, 0, x, 0); 
      ObjectMove(name, 1, x, 100);
   }  
   if(ShowPeriodSeparatorLabels ==true)
   {  
      if (S_Label_Norm_Bold_Black_123 <= 1){FontStyle = "Arial";}
      if (S_Label_Norm_Bold_Black_123 == 2){FontStyle = "Arial Bold";}
      if (S_Label_Norm_Bold_Black_123 >= 3){FontStyle = "Arial Black";}
      if (ObjectFind(name + " Label") != 0) 
      {
         ObjectCreate (name + " Label", OBJ_TEXT, 0, x, vleveltext);
         ObjectSetText(name + " Label", text, SeparatorLabelFontSize, FontStyle,  PeriodSeparatorsLabelsColor);    
      }       
      else 
      {
         ObjectMove(name + " Label", 0, x, vleveltext);            
       }     
   }
}

//+-------------------------------------------------------------------------------------------+
//|                       End of Program                                                      |                                                        
//+-------------------------------------------------------------------------------------------+


@Capo85
Replies

algotrader
27 Aug 2013, 21:03

Unfortunately, your indicator can not be converted. It uses functions WindowFirstVisibleBar, WindowPriceMin, WindowPriceMax and comparing the strings. Those operators are not supported in the converter. Probably if you rewrite your indicator without such operators, you will be able to convert it.


@algotrader

Capo85
27 Aug 2013, 22:00

is there anyone on the forum that you could direct me too that would be able to help program this?

 

Mainly this part is all i need

   //---- Calculate Pivot Levels ------------------------------------------------------------------------------- 
   // TODO: generalise all pivot calcs at some point
   double q, d, r1,r2,r3,r4,r5, s1,s2,s3,s4,s5;
   
   d     = (day_high[0] - day_low[0]);
   q     = (day_high[1] - day_low[1]); // RANGE
   
   // calculate pivots going back as many days as specified
   for (int idx = 1; idx <= Days; idx++)
   {
      p[idx]  = (day_high[idx] + day_low[idx] + day_close[idx]) / 3;  
      bc[idx] = (day_high[idx] + day_low[idx])/2;
      tc[idx]  = 2*p[idx] - bc[idx];
      
      if (bc[idx] > tc[idx])
      {
         double temp = bc[idx];
         bc[idx] = tc[idx];
         tc[idx] = temp;

 

 


@Capo85

algotrader
27 Aug 2013, 23:29

Please check out this indicator: /algos/indicators/show/323


@algotrader

Capo85
28 Aug 2013, 00:28

RE:

Wow thanks so much!!!!


@Capo85