Weekly Mid-Points

 

For those on the forum who use weekly pivots, I have attached a modified version of JellyBean's weekly pivots indicator. This modification creates an indicator that shows the weekly midpoints. One could load this and the weekly pivots indicator on their chart and then save both as a template. When you want to view both the weekly pivots and the weekly mid-points, then you just load the template. All credit goes to JellyBean for the original indicator.

//+------------------------------------------------------------------+
//|                                        Pivot Points - Weekly.mq4 |
//+------------------------------------------------------------------+

#property copyright "Jellybean"

#define R3_NAME "Weekly R3"
#define R2_NAME "Weekly R2"
#define R1_NAME "Weekly R1"
#define PIVOT_NAME "Weekly PP"
#define S1_NAME "Weekly S1"
#define S2_NAME "Weekly S2"
#define S3_NAME "Weekly S3"

#define FONT "Arial"

#define R3_COL Orange
#define R2_COL Orange
#define R1_COL Orange
#define PIVOT_COL Black
#define S1_COL Orange
#define S2_COL Orange
#define S3_COL Orange

#property indicator_chart_window                // draw in chart window
#property indicator_buffers 7                   // 7 lines
#property indicator_color1 R3_COL
#property indicator_color2 R2_COL
#property indicator_color3 R1_COL
#property indicator_color4 PIVOT_COL
#property indicator_color5 S1_COL
#property indicator_color6 S2_COL
#property indicator_color7 S3_COL

// Arrays for levels
double Res3[], Res2[], Res1[], Pivot[], Sup1[], Sup2[], Sup3[];
string ThisSymbol;
datetime BarTime, WeekStartTime;
int VisibleBars, WeekStartBar, LeftMostBar, RightMostBar;


//+------------------------------------------------------------------+
//| Initialization                                                   |
//+------------------------------------------------------------------+
int init()
{
   ThisSymbol = Symbol();

   // Attach indicator arrays to buffers
   SetIndexBuffer( 0, Res3);
   SetIndexBuffer( 1, Res2);
   SetIndexBuffer( 2, Res1);
   SetIndexBuffer( 3, Pivot);
   SetIndexBuffer( 4, Sup1);
   SetIndexBuffer( 5, Sup2);
   SetIndexBuffer( 6, Sup3);

   // Set styles
   SetIndexStyle( 0, DRAW_LINE, STYLE_SOLID, 1);
   SetIndexStyle( 1, DRAW_LINE, STYLE_SOLID, 1);
   SetIndexStyle( 2, DRAW_LINE, STYLE_SOLID, 1);
   SetIndexStyle( 3, DRAW_LINE, STYLE_SOLID, 1);
   SetIndexStyle( 4, DRAW_LINE, STYLE_SOLID, 1);
   SetIndexStyle( 5, DRAW_LINE, STYLE_SOLID, 1);
   SetIndexStyle( 6, DRAW_LINE, STYLE_SOLID, 1);

   // 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 );

   // Set labels
   SetIndexLabel( 0, R3_NAME );
   SetIndexLabel( 1, R2_NAME );
   SetIndexLabel( 2, R1_NAME );
   SetIndexLabel( 3, PIVOT_NAME );
   SetIndexLabel( 4, S1_NAME );
   SetIndexLabel( 5, S2_NAME );
   SetIndexLabel( 6, S3_NAME );

   // Put text on the chart
   /*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( PIVOT_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 );*/

   // Set the text characteristics
   ObjectSetText( R3_NAME, R3_NAME, 8, FONT, R3_COL );
   ObjectSetText( R2_NAME, R2_NAME, 8, FONT, R2_COL );
   ObjectSetText( R1_NAME, R1_NAME, 8, FONT, R1_COL );
   ObjectSetText( PIVOT_NAME, PIVOT_NAME, 8, FONT, PIVOT_COL );
   ObjectSetText( S1_NAME, S1_NAME, 8, FONT, S1_COL );
   ObjectSetText( S2_NAME, S2_NAME, 8, FONT, S2_COL );
   ObjectSetText( S3_NAME, S3_NAME, 8, FONT, S3_COL );
   
//   iBars( NULL, PERIOD_W1 );     // to force loading of weekly data
   WeekStartTime = Time[Bars-1];
   
   return(0);
}

//+------------------------------------------------------------------+
//| De-initialization                                                |
//+------------------------------------------------------------------+
int deinit()
{
   // Remove texts
   ObjectDelete( R3_NAME );
   ObjectDelete( R2_NAME );
   ObjectDelete( R1_NAME );
   ObjectDelete( PIVOT_NAME );
   ObjectDelete( S1_NAME );
   ObjectDelete( S2_NAME );
   ObjectDelete( S3_NAME );

   return(0);
}

//+------------------------------------------------------------------+
//| Main iteration                                                   |
//+------------------------------------------------------------------+
int start()
{
   int i, Count;
   double WeekHigh, WeekLow;
   double Range;

   i = Bars - IndicatorCounted() - 1;

   while(i >= 0)
   {
      // If the Week changes...
      if( TimeDayOfWeek( Time[i+1] ) > TimeDayOfWeek( Time[i] ) )
      {
         // Determine High & Low for the previous week
         Count = iBarShift( NULL, 0, WeekStartTime ) - i;           // number of bars in the week
         WeekHigh = High[ iHighest( NULL, 0, MODE_HIGH, Count, i+1 ) ];
         WeekLow = Low[ iLowest( NULL, 0, MODE_LOW, Count, i+1 ) ];
         // Pivot point calculations
         Pivot[i] = (WeekHigh + WeekLow + Close[i+1]) / 3;
         Range = WeekHigh - WeekLow;
         
          
         // THIS IS THE CODE THAT "TRICKS" THE INDICATOR INTO THINKING IT IS CALCULATING THE WEEKLY MID-POINTS
         
         Res3[i] = (2 * Pivot[i] - WeekLow) + Range; 
         Res2[i] = Pivot[i] + Range;   
         Res1[i] = 2 * Pivot[i] - WeekLow;                                               
         Sup1[i] = 2 * Pivot[i] - WeekHigh;                     
         Sup2[i] = Pivot[i] - Range;                           
         Sup3[i] = (2 * Pivot[i] - WeekHigh) - Range;                            
         
         Res3[i] = Res3[i] - (0.5 * (Pivot[i] - WeekLow));
         Res2[i] = Res2[i] - (0.5 * (Range - Pivot[i] + WeekLow));
         Res1[i] = Res1[i] - (0.5 * (Pivot[i] - WeekLow));
         Sup1[i] = Sup1[i] + (0.5 * (WeekHigh - Pivot[i]));
         Sup2[i] = Sup2[i] + (0.5 * (Pivot[i] + Range - WeekHigh));
         Sup3[i] = Sup3[i] + (0.5 * (WeekHigh - Pivot[i]));
        
      
         // Don't draw the transition between levels
         Res3[i+1] = EMPTY_VALUE;
         Res2[i+1] = EMPTY_VALUE;
         Res1[i+1] = EMPTY_VALUE;
         Pivot[i+1] = EMPTY_VALUE;
         Sup1[i+1] = EMPTY_VALUE;
         Sup2[i+1] = EMPTY_VALUE;
         Sup3[i+1] = EMPTY_VALUE;
            
         
         
      // Remember when the Week changed over
         WeekStartTime = Time[i];
      }
      else     // no change to pivot levels
      {
         Res3[i] = Res3[i+1];
         Res2[i] = Res2[i+1];
         Res1[i] = Res1[i+1];
         Pivot[i] = Pivot[i+1];
         Sup1[i] = Sup1[i+1];
         Sup2[i] = Sup2[i+1];
         Sup3[i] = Sup3[i+1];
      }

      // 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() ) )
      {
         WeekStartBar = iBarShift( ThisSymbol, Period(), WeekStartTime );
         LeftMostBar = WindowFirstVisibleBar()-7;
         RightMostBar = 15;
         if( WeekStartBar < RightMostBar )
         {                                                           // Rightmost
            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( PIVOT_NAME, 0, Time[RightMostBar], Pivot[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] );
         }
         else if ( WeekStartBar > LeftMostBar )
         {                                                           // Leftmost
            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( PIVOT_NAME, 0, Time[LeftMostBar], Pivot[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] );
         }
         else
         {
            // Move it with the bars
            ObjectMove( R3_NAME, 0, WeekStartTime, Res3[i] );
            ObjectMove( R2_NAME, 0, WeekStartTime, Res2[i] );
            ObjectMove( R1_NAME, 0, WeekStartTime, Res1[i] );
            ObjectMove( PIVOT_NAME, 0, WeekStartTime, Pivot[i] );
            ObjectMove( S1_NAME, 0, WeekStartTime, Sup1[i] );
            ObjectMove( S2_NAME, 0, WeekStartTime, Sup2[i] );
            ObjectMove( S3_NAME, 0, WeekStartTime, Sup3[i] );
         }
      }
      
      VisibleBars = WindowBarsPerChart();

      i--;
   }

   return(0);
}
 

If I am spammer I will delete this

/*--> PPandPN.mq4 <--*/
#property copyright "who"
#property indicator_chart_window
#property indicator_buffers 7
#property indicator_color1 DarkGray
#property indicator_color2 Green
#property indicator_color3 Red
#property indicator_color4 Green
#property indicator_color5 Red
#property indicator_color6 Green
#property indicator_color7 Red
#property indicator_width1 2
double B0[],B1[],B2[],B3[],B4[],B5[],B6[];
extern int Pivot_from = 43200;
extern bool Previous_Pivot = 0;
int time = -1;
int init() {
   SetIndexBuffer ( 0 , B0 ); SetIndexLabel ( 0 , "Pivot" );
   SetIndexBuffer ( 1 , B1 ); SetIndexLabel ( 1 , "R1" );
   SetIndexBuffer ( 2 , B2 ); SetIndexLabel ( 2 , "S1" );
   SetIndexBuffer ( 3 , B3 ); SetIndexLabel ( 3 , "R2" );
   SetIndexBuffer ( 4 , B4 ); SetIndexLabel ( 4 , "S2" );
   SetIndexBuffer ( 5 , B5 ); SetIndexLabel ( 5 , "R3" );
   SetIndexBuffer ( 6 , B6 ); SetIndexLabel ( 6 , "S3" );
   return( 0 ); }

int start() {
   if ( time == Previous_Pivot * Time[ 0 ] % ( Pivot_from * 60 ) ) return( 0 );
   int i = iBars ( NULL , Pivot_from ) - IndicatorCounted() - 1 , cnt; // Bars
   double H , L, R , C;
   while( i > Previous_Pivot - 1 ) {
    cnt = iBarShift ( NULL , Pivot_from , Time[ i ] ); // , 1
    H = iHigh ( NULL , Pivot_from , cnt );
    L = iLow ( NULL , Pivot_from , cnt );
    C = iClose ( NULL , Pivot_from , cnt );
    R = H - L;
    B0[ i ] = ( H + L + C ) / 3;
    B1[ i ] = 2 * B0[ i ] - L;
    B2[ i ] = 2 * B0[ i ] - H;
    B3[ i ] = B0[ i ] + R;
    B4[ i ] = B0[ i ] - R;
    B5[ i ] = B1[ i ] + R;
    B6[ i ] = B2[ i ] - R;
    time = Time[ i ];
    i --;
   }
   return(0); }
//+------------------------------------------------------------------+
/*
PHigh — the maximum price of the previous bar/period;
PLow — the minimum price of the previous bar/period;
PClose — the close price of the previous bar/period;
PP — PreviousPivots(Daily but Any Period) ~ or the typical price;
PIVOT POINTS WERE ... 
Range = PHigh - PLow;
PP = ( PHigh + PLow + PClose ) / 3
R1 = 2 * PP - PLow
R2 = PP + Range
R3 = R1 + Range
S1 = 2 * PP - PHigh
S2 = PP - Range
S3 = S1 - Range
*/
 
For those who don't have Jellybean's weekly pivots, I have attached it.
Files:
 
Here I have attached the weekly midpoint indicator. These 2 indicators in my opinion are best viewed on the 4 hr chart.
Files:
 
hi~thank you for your amazing work! is it possible to add for weekly and monthly the formula for top central and bottom central? see below...



TC,. (Pivot - BC) + Pivot
Pivot '" (High + Low + Close)!3
BC = (High + Low)/2

thank you!
 

do you have something like this indi which works on daily to work on weekly and monthly ar maybe yearly?


Thanks

Files: