Help request for pivot point indicator modifying.

 

Hello,

I'm new to programing and I need some guidance on a indicator modifying. I'm trying to write my own indicator but it's going very slow for now.

So my problem is - i'm editing "Daily Pivot Points shifted for different day start time" posted by Jellybean (i've added Camarilla equation and some stile options) but i have 2 problems that i cant find solution to:

1. When the day changes the levels for the previous days remain BUT the labels are deleted - I like them to remain on the chart. I just cant figure what function deletes them.

2. Problem that i have is - I like to show the price at the levels names - like it shows on the picture


I'm adding my modified code

THANK YOU FOR YOUR TIME AND HELP.


Have a nice day/evening and happy life.


//+------------------------------------------------------------------+
//|                                                       PP-ss1.mq4 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      ""
#property version   "1.00"
#property strict
#property indicator_chart_window

#define R4_NAME "Daily R4"
#define R3_NAME "Daily R3"
#define R2_NAME "Daily R2"
#define R1_NAME "Daily R1"
#define TC_NAME "Daily TC"
#define PIVOT_NAME "Daily PP"
#define BC_NAME "Daily BC"
#define S1_NAME "Daily S1"
#define S2_NAME "Daily S2"
#define S3_NAME "Daily S3"
#define S4_NAME "Daily S4"
#define H5_NAME "H5 Long Target"
#define H4_NAME "H4 Long Breakout"
#define H3_NAME "H3 Short"
#define L3_NAME "L3 Long"
#define L4_NAME "L4 Short Breakout"
#define L5_NAME "L5 Short Target"

#define FONT "Arial"

#property indicator_chart_window
#property indicator_buffers 17

// Input(s)
extern int ShiftHrs = 2;   // Pivot day shift
                           // positive value moves pivot day earlier
extern int LineStyle = 1;
extern int LineThickness = 2;
extern color PivotColor = Gray;
extern color SuportColor = Green;
extern color ResistanceColor = Red;
extern color TCColor = Yellow;
extern color BCColor = Yellow;
extern bool ShowCamarilla = true;
extern color CamarillaColor = DimGray;
extern int CamarillaLineStyle = 2;
extern int CamarillaLineThickness = 1;
extern bool ShowLevelPrices = true;
extern bool ShowComment = true;
extern color DaySeparator = DarkGray;

// Buffers for levels
double Res4[],Res3[],Res2[],Res1[],TC[],Pivot[],BC[],Sup1[],Sup2[],Sup3[],Sup4[],H5[],H4[],H3[],L3[],L4[],L5[];

double PDayHigh,PDayLow;
string ThisSymbol;
datetime BarTime,PivotDayStartTime;
int VisibleBars,DayStartBar,LeftMostBar,RightMostBar;
//--------------------------------------------------------------------
// Initialization
//--------------------------------------------------------------------
int init()
  {
// Attach indicator arrays to buffers
   SetIndexBuffer(0,Res4);
   SetIndexBuffer(1,Res3);
   SetIndexBuffer(2,Res2);
   SetIndexBuffer(3,Res1);
   SetIndexBuffer(4,TC);
   SetIndexBuffer(5,Pivot);
   SetIndexBuffer(6,BC);
   SetIndexBuffer(7,Sup1);
   SetIndexBuffer(8,Sup2);
   SetIndexBuffer(9,Sup3);
   SetIndexBuffer(10,Sup4);
   SetIndexBuffer(11,H5);
   SetIndexBuffer(12,H4);
   SetIndexBuffer(13,H3);
   SetIndexBuffer(14,L3);
   SetIndexBuffer(15,L4);
   SetIndexBuffer(16,L5);

// Set styles
   SetIndexStyle(0,DRAW_LINE,LineStyle,LineThickness,ResistanceColor);
   SetIndexStyle(1,DRAW_LINE,LineStyle,LineThickness,ResistanceColor);
   SetIndexStyle(2,DRAW_LINE,LineStyle,LineThickness,ResistanceColor);
   SetIndexStyle(3,DRAW_LINE,LineStyle,LineThickness,ResistanceColor);
   SetIndexStyle(4,DRAW_LINE,LineStyle,LineThickness,TCColor);
   SetIndexStyle(5,DRAW_LINE,LineStyle,LineThickness,PivotColor);
   SetIndexStyle(6,DRAW_LINE,LineStyle,LineThickness,BCColor);
   SetIndexStyle(7,DRAW_LINE,LineStyle,LineThickness,SuportColor);
   SetIndexStyle(8,DRAW_LINE,LineStyle,LineThickness,SuportColor);
   SetIndexStyle(9,DRAW_LINE,LineStyle,LineThickness,SuportColor);
   SetIndexStyle(10,DRAW_LINE,LineStyle,LineThickness,SuportColor);
   SetIndexStyle(11,DRAW_LINE,CamarillaLineStyle,CamarillaLineThickness,CamarillaColor);
   SetIndexStyle(12,DRAW_LINE,CamarillaLineStyle,CamarillaLineThickness,CamarillaColor);
   SetIndexStyle(13,DRAW_LINE,CamarillaLineStyle,CamarillaLineThickness,CamarillaColor);
   SetIndexStyle(14,DRAW_LINE,CamarillaLineStyle,CamarillaLineThickness,CamarillaColor);
   SetIndexStyle(15,DRAW_LINE,CamarillaLineStyle,CamarillaLineThickness,CamarillaColor);
   SetIndexStyle(16,DRAW_LINE,CamarillaLineStyle,CamarillaLineThickness,CamarillaColor);
   
// Set empty values
   SetIndexEmptyValue(0,EMPTY_VALUE);
   SetIndexEmptyValue(1,EMPTY_VALUE);
   SetIndexEmptyValue(2,EMPTY_VALUE);
   SetIndexEmptyValue(3,EMPTY_VALUE);
   SetIndexEmptyValue(4,EMPTY_VALUE);
   SetIndexEmptyValue(5,EMPTY_VALUE);
   SetIndexEmptyValue(6,EMPTY_VALUE);
   SetIndexEmptyValue(7,EMPTY_VALUE);
   SetIndexEmptyValue(8,EMPTY_VALUE);
   SetIndexEmptyValue(9,EMPTY_VALUE);
   SetIndexEmptyValue(10,EMPTY_VALUE);
   SetIndexEmptyValue(11,EMPTY_VALUE);
   SetIndexEmptyValue(12,EMPTY_VALUE);
   SetIndexEmptyValue(13,EMPTY_VALUE);
   SetIndexEmptyValue(14,EMPTY_VALUE);
   SetIndexEmptyValue(15,EMPTY_VALUE);
   SetIndexEmptyValue(16,EMPTY_VALUE);

// Set labels
   SetIndexLabel(0,R4_NAME);
   SetIndexLabel(1,R3_NAME);
   SetIndexLabel(2,R2_NAME);
   SetIndexLabel(3,R1_NAME);
   SetIndexLabel(4,TC_NAME);
   SetIndexLabel(5,PIVOT_NAME);
   SetIndexLabel(6,BC_NAME);
   SetIndexLabel(7,S1_NAME);
   SetIndexLabel(8,S2_NAME);
   SetIndexLabel(9,S3_NAME);
   SetIndexLabel(10,S4_NAME);
   SetIndexLabel(11,H5_NAME);
   SetIndexLabel(12,H4_NAME);
   SetIndexLabel(13,H3_NAME);
   SetIndexLabel(14,L3_NAME);
   SetIndexLabel(15,L4_NAME);
   SetIndexLabel(16,L5_NAME);

// Put text on the chart
   ObjectCreate(R4_NAME,OBJ_TEXT,0,0,0);
   ObjectCreate(R3_NAME,OBJ_TEXT,0,0,0);
   ObjectCreate(R2_NAME,OBJ_TEXT,0,0,0);
   ObjectCreate(R1_NAME,OBJ_TEXT,0,0,0);
   ObjectCreate(TC_NAME,OBJ_TEXT,0,0,0);
   ObjectCreate(PIVOT_NAME,OBJ_TEXT,0,0,0);
   ObjectCreate(BC_NAME,OBJ_TEXT,0,0,0);
   ObjectCreate(S1_NAME,OBJ_TEXT,0,0,0);
   ObjectCreate(S2_NAME,OBJ_TEXT,0,0,0);
   ObjectCreate(S3_NAME,OBJ_TEXT,0,0,0);
   ObjectCreate(S4_NAME,OBJ_TEXT,0,0,0);
   ObjectCreate(H5_NAME,OBJ_TEXT,0,0,0);
   ObjectCreate(H4_NAME,OBJ_TEXT,0,0,0);
   ObjectCreate(H3_NAME,OBJ_TEXT,0,0,0);
   ObjectCreate(L3_NAME,OBJ_TEXT,0,0,0);
   ObjectCreate(L4_NAME,OBJ_TEXT,0,0,0);
   ObjectCreate(L5_NAME,OBJ_TEXT,0,0,0);

// Set the text characteristics
   ObjectSetText(R4_NAME,R4_NAME,8,FONT,ResistanceColor);
   ObjectSetText(R3_NAME,R3_NAME,8,FONT,ResistanceColor);
   ObjectSetText(R2_NAME,R2_NAME,8,FONT,ResistanceColor);
   ObjectSetText(R1_NAME,R1_NAME,8,FONT,ResistanceColor);
   ObjectSetText(TC_NAME,TC_NAME,8,FONT,TCColor);
   ObjectSetText(PIVOT_NAME,PIVOT_NAME,8,FONT,PivotColor);
   ObjectSetText(BC_NAME,BC_NAME,8,FONT,BCColor);
   ObjectSetText(S1_NAME,S1_NAME,8,FONT,SuportColor);
   ObjectSetText(S2_NAME,S2_NAME,8,FONT,SuportColor);
   ObjectSetText(S3_NAME,S3_NAME,8,FONT,SuportColor);
   ObjectSetText(S4_NAME,S4_NAME,8,FONT,SuportColor);
   ObjectSetText(H5_NAME,H5_NAME,8,FONT,CamarillaColor);
   ObjectSetText(H4_NAME,H4_NAME,8,FONT,CamarillaColor);
   ObjectSetText(H3_NAME,H3_NAME,8,FONT,CamarillaColor);
   ObjectSetText(L3_NAME,L3_NAME,8,FONT,CamarillaColor);
   ObjectSetText(L4_NAME,L4_NAME,8,FONT,CamarillaColor);
   ObjectSetText(L5_NAME,L5_NAME,8,FONT,CamarillaColor);
   
// Catch bad input
   if(MathAbs(ShiftHrs)>23)
     {
      Alert("ShiftHrs is too large. Reset to 0 hrs. ");
      ShiftHrs=0;
     }

   ThisSymbol=Symbol();
   PivotDayStartTime=Time[Bars-1];         // the first bar

   return(0);
  }
//--------------------------------------------------------------------
//| De-initialization                                                |
//--------------------------------------------------------------------
int deinit()
  {
// Remove texts
   ObjectDelete(R4_NAME);
   ObjectDelete(R3_NAME);
   ObjectDelete(R2_NAME);
   ObjectDelete(R1_NAME);
   ObjectDelete(TC_NAME);
   ObjectDelete(PIVOT_NAME);
   ObjectDelete(BC_NAME);
   ObjectDelete(S1_NAME);
   ObjectDelete(S2_NAME);
   ObjectDelete(S3_NAME);
   ObjectDelete(S4_NAME);
   ObjectDelete(H5_NAME);
   ObjectDelete(H4_NAME);
   ObjectDelete(H3_NAME);
   ObjectDelete(L3_NAME);
   ObjectDelete(L4_NAME);
   ObjectDelete(L5_NAME);

   return(0);
  }
//--------------------------------------------------------------------
//| Main iteration                                                   |
//--------------------------------------------------------------------
int start()
  {
   int Count;
   double Range;

//i = Bars - IndicatorCounted() - 1;
   int counted_bars=IndicatorCounted();
   if(counted_bars < 0)  return(-1);
   if(counted_bars>0) counted_bars--;
   int i=Bars-counted_bars;
   if(counted_bars==0) i-=1+1;

   while(i>=0)
     {
      // If the pivot day changes...
      if(PivotDay(Time[i+1],ShiftHrs)!=PivotDay(Time[i],ShiftHrs))
        {
         // Determine High & Low for the previous Pivot Day
         Count = iBarShift( NULL, 0, PivotDayStartTime ) - i;           // number of bars in the day
         PDayHigh = High[ iHighest( NULL, 0, MODE_HIGH, Count, i+1 ) ]; // Pivot Day high
         PDayLow = Low[ iLowest( NULL, 0, MODE_LOW, Count, i+1 ) ];     // Pivot Day low
         
                                                                // Pivot calculations
         Pivot[i]=(PDayHigh+PDayLow+Close[i+1])/3;    // Pivot point
         Range=PDayHigh-PDayLow;
         BC[i] = (PDayHigh+PDayLow)/2;                       // BC
         TC[i] = (Pivot[i]-BC[i])+Pivot[i];                  // TC
         Res1[i] = 2*Pivot[i]-PDayLow;                       // R1
         Res2[i] = Pivot[i]+Range;                           // R2
         Res3[i] = Res1[i]+Range;                            // R3
         Res4[i] = Res3[i]+(Res2[i]-Res1[i]);                // R4
         Sup1[i] = 2*Pivot[i]-PDayHigh;                      // S1
         Sup2[i] = Pivot[i]-Range;                           // S2
         Sup3[i] = Sup1[i]-Range;                            // S3
         Sup4[i] = Sup3[i]-(Sup1[i]-Sup2[i]);                // S4
         
         
        if (ShowCamarilla) 
        { 
      
         H5[i] = (PDayHigh/PDayLow)*Close[i+1];              //Camarilla Levels
              H4[i] = ((PDayHigh - PDayLow)*0.55)+Close[i+1];     //Camarilla Levels
              H3[i] = ((PDayHigh - PDayLow)*0.27)+Close[i+1];     //Camarilla Levels
              L3[i] = Close[i+1]-((PDayHigh - PDayLow)*0.27);       //Camarilla Levels
              L4[i] = Close[i+1]-((PDayHigh - PDayLow)*0.55);     //Camarilla Levels
              L5[i] = Close[i+1]- (H5[i] - Close[i+1]);           //Camarilla Levels
        } 
      
                                                               // Don't draw the transition between levels
                                                               
         Res4[i+1] = EMPTY_VALUE;
         Res3[i+1] = EMPTY_VALUE;
         Res2[i+1] = EMPTY_VALUE;
         Res1[i+1] = EMPTY_VALUE;
         TC[i+1] = EMPTY_VALUE;
         Pivot[i+1]= EMPTY_VALUE;
         BC[i+1] = EMPTY_VALUE;
         Sup1[i+1] = EMPTY_VALUE;
         Sup2[i+1] = EMPTY_VALUE;
         Sup3[i+1] = EMPTY_VALUE;
         Sup4[i+1] = EMPTY_VALUE;
         H5[i+1] = EMPTY_VALUE;
         H4[i+1] = EMPTY_VALUE;
         H3[i+1] = EMPTY_VALUE;
         L3[i+1] = EMPTY_VALUE;
         L4[i+1] = EMPTY_VALUE;
         L5[i+1] = EMPTY_VALUE;

         // Remember when the Day changed over
         PivotDayStartTime=Time[i];
        }
      else     // no change to pivot levels
        {
         Res4[i] = Res4[i+1];
         Res3[i] = Res3[i+1];
         Res2[i] = Res2[i+1];
         Res1[i] = Res1[i+1];
         TC[i] = TC[i+1];
         Pivot[i] = Pivot[i+1];
         BC[i] = BC[i+1];
         Sup1[i] = Sup1[i+1];
         Sup2[i] = Sup2[i+1];
         Sup3[i] = Sup3[i+1];
         Sup4[i] = Sup4[i+1];
         H5[i] = H5[i+1];
         H4[i] = H4[i+1];
         H3[i] = H3[i+1];
         L3[i] = L3[i+1];
         L4[i] = L4[i+1];
         L5[i] = L5[i+1];
        }

      // Move the labels to sensible places
      // If this is the last bar and (it's a new bar or time scale has changed)...
      if(i==0 && (BarTime!=Time[i] || VisibleBars!=WindowBarsPerChart()))
        {
         DayStartBar = iBarShift( ThisSymbol, Period(), PivotDayStartTime );
         LeftMostBar = WindowFirstVisibleBar()-7;
         RightMostBar= 15;
         if(DayStartBar<RightMostBar) // label too close to the right
           {
            ObjectMove(R4_NAME,0,Time[RightMostBar],Res4[i]);
            ObjectMove(R3_NAME,0,Time[RightMostBar],Res3[i]);
            ObjectMove(R2_NAME,0,Time[RightMostBar],Res2[i]);
            ObjectMove(R1_NAME,0,Time[RightMostBar],Res1[i]);
            ObjectMove(TC_NAME,0,Time[RightMostBar],TC[i]);
            ObjectMove(PIVOT_NAME,0,Time[RightMostBar],Pivot[i]);
            ObjectMove(BC_NAME,0,Time[RightMostBar],BC[i]);
            ObjectMove(S1_NAME,0,Time[RightMostBar],Sup1[i]);
            ObjectMove(S2_NAME,0,Time[RightMostBar],Sup2[i]);
            ObjectMove(S3_NAME,0,Time[RightMostBar],Sup3[i]);
            ObjectMove(S4_NAME,0,Time[RightMostBar],Sup4[i]);
            ObjectMove(H5_NAME,0,Time[RightMostBar],H5[i]);
            ObjectMove(H4_NAME,0,Time[RightMostBar],H4[i]);
            ObjectMove(H3_NAME,0,Time[RightMostBar],H3[i]);
            ObjectMove(L3_NAME,0,Time[RightMostBar],L3[i]);
            ObjectMove(L4_NAME,0,Time[RightMostBar],L4[i]);
            ObjectMove(L5_NAME,0,Time[RightMostBar],L5[i]);
           }
         else if(DayStartBar>LeftMostBar) // label too close to the left
           {
            ObjectMove(R4_NAME,0,Time[LeftMostBar],Res4[i]);
            ObjectMove(R3_NAME,0,Time[LeftMostBar],Res3[i]);
            ObjectMove(R2_NAME,0,Time[LeftMostBar],Res2[i]);
            ObjectMove(R1_NAME,0,Time[LeftMostBar],Res1[i]);
            ObjectMove(TC_NAME,0,Time[LeftMostBar],TC[i]);
            ObjectMove(PIVOT_NAME,0,Time[LeftMostBar],Pivot[i]);
            ObjectMove(BC_NAME,0,Time[LeftMostBar],BC[i]);
            ObjectMove(S1_NAME,0,Time[LeftMostBar],Sup1[i]);
            ObjectMove(S2_NAME,0,Time[LeftMostBar],Sup2[i]);
            ObjectMove(S3_NAME,0,Time[LeftMostBar],Sup3[i]);
            ObjectMove(S4_NAME,0,Time[LeftMostBar],Sup4[i]);
            ObjectMove(H5_NAME,0,Time[LeftMostBar],H5[i]);
            ObjectMove(H4_NAME,0,Time[LeftMostBar],H4[i]);
            ObjectMove(H3_NAME,0,Time[LeftMostBar],H3[i]);
            ObjectMove(L3_NAME,0,Time[LeftMostBar],L3[i]);
            ObjectMove(L4_NAME,0,Time[LeftMostBar],L4[i]);
            ObjectMove(L5_NAME,0,Time[LeftMostBar],L5[i]);
           }
         else                                      // move it with the bars
           {
            ObjectMove(R4_NAME,0,PivotDayStartTime,Res4[i]);
            ObjectMove(R3_NAME,0,PivotDayStartTime,Res3[i]);
            ObjectMove(R2_NAME,0,PivotDayStartTime,Res2[i]);
            ObjectMove(R1_NAME,0,PivotDayStartTime,Res1[i]);
            ObjectMove(TC_NAME,0,PivotDayStartTime,TC[i]);
            ObjectMove(PIVOT_NAME,0,PivotDayStartTime,Pivot[i]);
            ObjectMove(BC_NAME,0,PivotDayStartTime,BC[i]);
            ObjectMove(S1_NAME,0,PivotDayStartTime,Sup1[i]);
            ObjectMove(S2_NAME,0,PivotDayStartTime,Sup2[i]);
            ObjectMove(S3_NAME,0,PivotDayStartTime,Sup3[i]);
            ObjectMove(S4_NAME,0,PivotDayStartTime,Sup4[i]);
            ObjectMove(H5_NAME,0,PivotDayStartTime,H5[i]);
            ObjectMove(H4_NAME,0,PivotDayStartTime,H4[i]);
            ObjectMove(H3_NAME,0,PivotDayStartTime,H3[i]);
            ObjectMove(L3_NAME,0,PivotDayStartTime,L3[i]);
            ObjectMove(L4_NAME,0,PivotDayStartTime,L4[i]);
            ObjectMove(L5_NAME,0,PivotDayStartTime,L5[i]);
           }
        }

      VisibleBars=WindowBarsPerChart();
      BarTime=Time[i];
      i--;
     }
     
   return(0);
  }
//--------------------------------------------------------------------
// int PivotDay( datetime BarTime, datetime ShiftHrs )
// Returns the day of the week for pivot point calculations.
// datetime BarTime: time stamp of the bar of interest
// datetime Shift:   the pivot time - server time shift
//                   i.e. if the time for pivot calculation is ahead
//                   of server time, the shift is positive.
//--------------------------------------------------------------------
int PivotDay(datetime BarTime,datetime ShiftHrs)
  {
   int PDay=TimeDayOfWeek(BarTime+ShiftHrs*3600);

   if( PDay == 0 ) PDay = 1;      // Count Sunday as Monday
   if( PDay == 6 ) PDay = 5;      // Count Saturday as Friday

   return( PDay );
   }