MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal

Source code library - Expert Advisors, Indicators and Scripts

MetaTrader Market - the place where newest trading robots appear
To post a new code, please log in or register

Interesting script?
So post a link to it -
let others appraise it

You liked the script? Try it in the MetaTrader 5 terminal

2009.01.26 07:25
Daily Pivot Points shifted for different day start time

Daily Pivot Points shifted for different day start time - indicator for MetaTrader 4

| English Spanish Portuguese

Views:
39661
Rating:
votes: 3

This indicator plots horizontal lines at daily pivot levels R3, R2, R1, Pivot, S1, S2 & S3, using a day that is advanced (or retarded) from the server time (called Pivot Day). You can see in the illustration, that the pivot lines start earlier than the server time days (except for the most recent day, because it was a weekend).


The only input is the integer "ShiftHrs", which gives the number of hours to advance the pivot day. A negative value delays the day for pivot calculation. For example, if your server is on New York time (GMT-5) and you want pivot points in London time (GMT), then ShiftHrs is set to +5 (the default in the code).

Saturday and Sunday trading is not ignored (after all it was real trading). If the pivot day shift results in data appearing on Saturday, it was really Friday where it occured, so the indicator treats it as part of Friday. If the pivot day shift results in data appearing on Sunday, it was really Monday where it occured, so the indicator treats it as Monday.

It uses an indicator buffer for each line, so pivot levels of previous days remain visible. (This has a negative consequence: it is not possible to use the same technique to draw additional intermediate levels (S0.5, S1.5, etc.) because of the limit of 8 buffers.)

Labels are shown for the most recent day's levels.

This indicator can be applied to any chart period, although daily pivots on charts with long periods are meaningless.

The formulae for the caluclations are:

Pivot = ( High + Low + Close ) / 3
Range = High - Low
Resistance1 = 2 * Pivot - Low
Resistance2 = Pivot + Range
Resistance3 = Resistance1 + Range
Support1 = 2 * Pivot - High
Support2 = Pivot - Range
Support3 = Support1 - Range

2009.07.02 Note that I have corrected the calculations for Resistance3 and Support3 in line with the post by substanz. Sorry for the mistake :-(

I would accept any suggestions for improvement.


Jellybean


Last comments | Go to discussion (27)
MQL4 Comments
mql4_comments | 16 Jul 2011 at 07:04

Hi Jellybean,

I find your code very elegant. Is it possible to rewrite the code to include mid pivot levels under the same framework? If you can do this I would very much appreciate it.

Regards,

Mowuor

MQL4 Comments
mql4_comments | 13 Jan 2012 at 01:35
jazfonz:
macleod77:
Jellybean:
macleod77:

is there a way to add another pivot line? I want to add a line that is the average of the current session's pivot point added to the 2 prior sessions pivot points. it would be called the 3 Period Pivot Point Average.

Thanks


-E-

Hi MacLeod


Yes it is possible to do this. There is a limit of 8 indicator buffers and this indicator uses 7, so as long as you only want to add one more line, it should be OK.

Are you able to program this or are you asking me to do it?

Cheers

Jellybean


Thanks for the quick reply, I was going to give a crack at coding this, but since I'm new to MQL4 it might not go so well. Can i ask you questions if i run into issues? :) I really want to learn how to do this myself so i can write my own code. :)



Hi Mcleod, Jellybean, and other members,

I have attached a version of Jellybeans fantastic indicator that displays Midpoints between the pivot levels. Will attach a screen shot and also the indicator. As Jellybean mentions, MT4 has a limit of 8 indicator buffers so this midpoint indicator must be attached to your chart as a seperate indicator.

Also, i saw in the first page of comments that the indicator had been updated to show correct levels for R3/S3 however the version i downloaded did not appear to have such a correction? I have adjusted to what i think should be the correct levels, using the same formulas from pivotpointcalculator.com and attached my corrected version for those who may have also downloaded the older version of the indicator.

Jellybean (or anyone else) would you be able to adjust the code for the indicator to display WEEKLY Pivot levels as a seperate indicator? I am new to MQ4 and still learning the ropes, and will attempt to figuire this out myself, but any help would be greatly appreciated.

Thanks for your hard work and great indicator Jellybean, this is by far the best PP indicator i've come across!

//--------------------------------------------------------------------
// Pivot Points - Daily (Shifted).mq4
// Copyright © 2009, SwingTree Ltd
// 
// This indicator plots horizontal lines at daily pivot levels R3, R2,
// R1, Pivot, S1, S2 & S3, using a day that is advanced (or retarded)
// from the server time (called Pivot Day).
// 
// The only input is the integer "ShiftHrs", which gives the number of
// hours to advance the pivot day. A negative value delays the day for
// pivot calculation. For example, if your server is on New York time
// (GMT-5) and you want pivot points in London time (GMT), then
// ShiftHrs is set to +5 (the default in the code).
//
// Saturday and Sunday trading is not ignored (after all it was real
// trading). If the pivot day shift results in data appearing on
// Saturday, it was really Friday where it occured, so the indicator
// treats it as part of Friday. If the pivot day shift results in data
// appearing on Sunday, it was really Monday where it occured, so the
// indicator treats it as Monday.
//
// It uses an indicator buffer for each line, so pivot levels of
// previous days remain visible. (This has a negative consequence:
// it is not possible to use the same technique to draw intermediate
// levels (S0.5, S1.5, etc.) because of the limit of 8 buffers.)
//
// Labels are shown for the most recent day's levels.
// 
// This indicator can be applied to any chart period, although daily
// pivots on charts with long periods are meaningless.
//
// 2009.07.02
// There was an error in the calculation of R3 & S3,
// which is now corrected.
//
//--------------------------------------------------------------------
#property copyright "Copyright © 2009, SwingTree Ltd"
#define R3_NAME "Daily R3"
#define R2_NAME "Daily R2"
#define R1_NAME "Daily R1"
#define PIVOT_NAME "Daily PP"
#define S1_NAME "Daily S1"
#define S2_NAME "Daily S2"
#define S3_NAME "Daily S3"
#define FONT "Arial"
#define R3_COL Yellow
#define R2_COL Yellow
#define R1_COL Yellow
#define PIVOT_COL White
#define S1_COL Red
#define S2_COL Red
#define S3_COL Red
#property indicator_chart_window
#property indicator_buffers 7
#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
// Input(s)
extern int ShiftHrs = 5;   // Pivot day shift
                           // positive value moves pivot day earlier
// Buffers for levels
double Res3[], Res2[], Res1[], Pivot[], Sup1[], Sup2[], Sup3[];
double PDayHigh, PDayLow;
string ThisSymbol;
datetime BarTime, PivotDayStartTime;
int VisibleBars, DayStartBar, LeftMostBar, RightMostBar;
//--------------------------------------------------------------------
// Initialization
//--------------------------------------------------------------------
int init()
{
   // 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_DOT, 1);
   SetIndexStyle( 1, DRAW_LINE, STYLE_DOT, 1);
   SetIndexStyle( 2, DRAW_LINE, STYLE_DOT, 1);
   SetIndexStyle( 3, DRAW_LINE, STYLE_DOT, 1);
   SetIndexStyle( 4, DRAW_LINE, STYLE_DOT, 1);
   SetIndexStyle( 5, DRAW_LINE, STYLE_DOT, 1);
   SetIndexStyle( 6, DRAW_LINE, STYLE_DOT, 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 );
   // 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( 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 Range;
   i = Bars - IndicatorCounted() - 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;
         Res1[i] = 2 * Pivot[i] - PDayLow;                     // R1
         Res2[i] = Pivot[i] + Range;                           // R2
         Res3[i] = Pivot[i] + Range *2;                        // R3
         Sup1[i] = 2 * Pivot[i] - PDayHigh;                    // S1
         Sup2[i] = Pivot[i] - Range;                           // S2
         Sup3[i] = Pivot[i] - Range *2;                        // S3
         // 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 Day changed over
         PivotDayStartTime = 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];
      }
      // 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( 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 ( DayStartBar > LeftMostBar )     // label too close to the left
         {
            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, PivotDayStartTime, Res3[i] );
            ObjectMove( R2_NAME, 0, PivotDayStartTime, Res2[i] );
            ObjectMove( R1_NAME, 0, PivotDayStartTime, Res1[i] );
            ObjectMove( PIVOT_NAME, 0, PivotDayStartTime, Pivot[i] );
            ObjectMove( S1_NAME, 0, PivotDayStartTime, Sup1[i] );
            ObjectMove( S2_NAME, 0, PivotDayStartTime, Sup2[i] );
            ObjectMove( S3_NAME, 0, PivotDayStartTime, Sup3[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 );
}
//--------------------------------------------------------------------
// Pivot Points - Daily (Shifted) MIDPOINTS.mq4
// Copyright © 2009, SwingTree Ltd
// 
// This indicator plots horizontal lines at daily pivot levels R3, R2,
// R1, Pivot, S1, S2 & S3, using a day that is advanced (or retarded)
// from the server time (called Pivot Day).
// 
// The only input is the integer "ShiftHrs", which gives the number of
// hours to advance the pivot day. A negative value delays the day for
// pivot calculation. For example, if your server is on New York time
// (GMT-5) and you want pivot points in London time (GMT), then
// ShiftHrs is set to +5 (the default in the code).
//
// Saturday and Sunday trading is not ignored (after all it was real
// trading). If the pivot day shift results in data appearing on
// Saturday, it was really Friday where it occured, so the indicator
// treats it as part of Friday. If the pivot day shift results in data
// appearing on Sunday, it was really Monday where it occured, so the
// indicator treats it as Monday.
//
// It uses an indicator buffer for each line, so pivot levels of
// previous days remain visible. (This has a negative consequence:
// it is not possible to use the same technique to draw intermediate
// levels (S0.5, S1.5, etc.) because of the limit of 8 buffers.)
//
// Labels are shown for the most recent day's levels.
// 
// This indicator can be applied to any chart period, although daily
// pivots on charts with long periods are meaningless.
//
// 2009.07.02
// There was an error in the calculation of R3 & S3,
// which is now corrected.
//
//--------------------------------------------------------------------
#property copyright "Copyright © 2009, SwingTree Ltd"
#define RM3_NAME "Daily RM3"
#define RM2_NAME "Daily RM2"
#define RM1_NAME "Daily RM1"
#define PIVOT_NAME "Daily PP"
#define SM1_NAME "Daily SM1"
#define SM2_NAME "Daily SM2"
#define SM3_NAME "Daily SM3"
#define FONT "Arial"
#define RM3_COL DimGray
#define RM2_COL DimGray
#define RM1_COL DimGray
#define PIVOT_COL White
#define SM1_COL DimGray
#define SM2_COL DimGray
#define SM3_COL DimGray
#property indicator_chart_window
#property indicator_buffers 7
#property indicator_color1 RM3_COL
#property indicator_color2 RM2_COL
#property indicator_color3 RM1_COL
#property indicator_color4 PIVOT_COL
#property indicator_color5 SM1_COL
#property indicator_color6 SM2_COL
#property indicator_color7 SM3_COL
// Input(s)
extern int ShiftHrs = 5;   // Pivot day shift
                           // positive value moves pivot day earlier
// Buffers for levels
double ResM3[], ResM2[], ResM1[], Pivot[], SupM1[], SupM2[], SupM3[];
double PDayHigh, PDayLow;
string ThisSymbol;
datetime BarTime, PivotDayStartTime;
int VisibleBars, DayStartBar, LeftMostBar, RightMostBar;
//--------------------------------------------------------------------
// Initialization
//--------------------------------------------------------------------
int init()
{
   // Attach indicator arrays to buffers
   SetIndexBuffer( 0, ResM3);
   SetIndexBuffer( 1, ResM2);
   SetIndexBuffer( 2, ResM1);
   SetIndexBuffer( 3, Pivot);
   SetIndexBuffer( 4, SupM1);
   SetIndexBuffer( 5, SupM2);
   SetIndexBuffer( 6, SupM3);
   // Set styles
   SetIndexStyle( 0, DRAW_LINE, STYLE_DOT, 1);
   SetIndexStyle( 1, DRAW_LINE, STYLE_DOT, 1);
   SetIndexStyle( 2, DRAW_LINE, STYLE_DOT, 1);
   SetIndexStyle( 3, DRAW_LINE, STYLE_DOT, 1);
   SetIndexStyle( 4, DRAW_LINE, STYLE_DOT, 1);
   SetIndexStyle( 5, DRAW_LINE, STYLE_DOT, 1);
   SetIndexStyle( 6, DRAW_LINE, STYLE_DOT, 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, RM3_NAME );
   SetIndexLabel( 1, RM2_NAME );
   SetIndexLabel( 2, RM1_NAME );
   SetIndexLabel( 3, PIVOT_NAME );
   SetIndexLabel( 4, SM1_NAME );
   SetIndexLabel( 5, SM2_NAME );
   SetIndexLabel( 6, SM3_NAME );
   // Put text on the chart
   ObjectCreate( RM3_NAME, OBJ_TEXT, 0, 0, 0 );
   ObjectCreate( RM2_NAME, OBJ_TEXT, 0, 0, 0 );
   ObjectCreate( RM1_NAME, OBJ_TEXT, 0, 0, 0 );
   ObjectCreate( PIVOT_NAME, OBJ_TEXT, 0, 0, 0 );
   ObjectCreate( SM1_NAME, OBJ_TEXT, 0, 0, 0 );
   ObjectCreate( SM2_NAME, OBJ_TEXT, 0, 0, 0 );
   ObjectCreate( SM3_NAME, OBJ_TEXT, 0, 0, 0 );
   // Set the text characteristics
   ObjectSetText( RM3_NAME, RM3_NAME, 8, FONT, RM3_COL );
   ObjectSetText( RM2_NAME, RM2_NAME, 8, FONT, RM2_COL );
   ObjectSetText( RM1_NAME, RM1_NAME, 8, FONT, RM1_COL );
   ObjectSetText( PIVOT_NAME, PIVOT_NAME, 8, FONT, PIVOT_COL );
   ObjectSetText( SM1_NAME, SM1_NAME, 8, FONT, SM1_COL );
   ObjectSetText( SM2_NAME, SM2_NAME, 8, FONT, SM2_COL );
   ObjectSetText( SM3_NAME, SM3_NAME, 8, FONT, SM3_COL );
   // 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( RM3_NAME );
   ObjectDelete( RM2_NAME );
   ObjectDelete( RM1_NAME );
   ObjectDelete( PIVOT_NAME );
   ObjectDelete( SM1_NAME );
   ObjectDelete( SM2_NAME );
   ObjectDelete( SM3_NAME );
   return(0);
}
//--------------------------------------------------------------------
//| Main iteration                                                   |
//--------------------------------------------------------------------
int start()
{
   int i, Count;
   double Range;
   i = Bars - IndicatorCounted() - 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;                                                                                 // Range
         ResM1[i] = ((2 * Pivot[i] - PDayLow) - (Pivot[i])) /2 + Pivot[i];                                           // RM1
         ResM2[i] = ((Pivot[i] + Range) - (2 * Pivot[i] - PDayLow)) /2 + (2 * Pivot[i] - PDayLow);                   // RM2
         ResM3[i] = ((Pivot[i] + Range *2) - (Pivot[i] + Range)) /2 + (Pivot[i] + Range);                        // RM3
         SupM1[i] = Pivot[i] - ((Pivot[i]) -(2 * Pivot[i] - PDayHigh)) /2 ;                                          // SM1
         SupM2[i] =  ((2 * Pivot[i] - PDayHigh) - (Pivot[i] - Range)) /2 + (Pivot[i] - Range);                       // SM2
         SupM3[i] = ((Pivot[i] - Range) - (Pivot[i] - Range *2)) /2 + (Pivot[i] - Range *2);                         // SM3
         // Don't draw the transition between levels
         ResM3[i+1] = EMPTY_VALUE;
         ResM2[i+1] = EMPTY_VALUE;
         ResM1[i+1] = EMPTY_VALUE;
         Pivot[i+1] = EMPTY_VALUE;
         SupM1[i+1] = EMPTY_VALUE;
         SupM2[i+1] = EMPTY_VALUE;
         SupM3[i+1] = EMPTY_VALUE;
         
      // Remember when the Day changed over
         PivotDayStartTime = Time[i];
      }
      else     // no change to pivot levels
      {
         ResM3[i] = ResM3[i+1];
         ResM2[i] = ResM2[i+1];
         ResM1[i] = ResM1[i+1];
         Pivot[i] = Pivot[i+1];
         SupM1[i] = SupM1[i+1];
         SupM2[i] = SupM2[i+1];
         SupM3[i] = SupM3[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( RM3_NAME, 0, Time[RightMostBar], ResM3[i] );
            ObjectMove( RM2_NAME, 0, Time[RightMostBar], ResM2[i] );
            ObjectMove( RM1_NAME, 0, Time[RightMostBar], ResM1[i] );
            ObjectMove( PIVOT_NAME, 0, Time[RightMostBar], Pivot[i] );
            ObjectMove( SM1_NAME, 0, Time[RightMostBar], SupM1[i] );
            ObjectMove( SM2_NAME, 0, Time[RightMostBar], SupM2[i] );
            ObjectMove( SM3_NAME, 0, Time[RightMostBar], SupM3[i] );
         }
         else if ( DayStartBar > LeftMostBar )     // label too close to the left
         {
            ObjectMove( RM3_NAME, 0, Time[LeftMostBar], ResM3[i] );
            ObjectMove( RM2_NAME, 0, Time[LeftMostBar], ResM2[i] );
            ObjectMove( RM1_NAME, 0, Time[LeftMostBar], ResM1[i] );
            ObjectMove( PIVOT_NAME, 0, Time[LeftMostBar], Pivot[i] );
            ObjectMove( SM1_NAME, 0, Time[LeftMostBar], SupM1[i] );
            ObjectMove( SM2_NAME, 0, Time[LeftMostBar], SupM2[i] );
            ObjectMove( SM3_NAME, 0, Time[LeftMostBar], SupM3[i] );
         }
         else                                      // move it with the bars
         {
            ObjectMove( RM3_NAME, 0, PivotDayStartTime, ResM3[i] );
            ObjectMove( RM2_NAME, 0, PivotDayStartTime, ResM2[i] );
            ObjectMove( RM1_NAME, 0, PivotDayStartTime, ResM1[i] );
            ObjectMove( PIVOT_NAME, 0, PivotDayStartTime, Pivot[i] );
            ObjectMove( SM1_NAME, 0, PivotDayStartTime, SupM1[i] );
            ObjectMove( SM2_NAME, 0, PivotDayStartTime, SupM2[i] );
            ObjectMove( SM3_NAME, 0, PivotDayStartTime, SupM3[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 );
}


Sorry everybody, that was my first post im not sure why the indicators were posted in code like that, i was hoping they would be as a downloadable mq4 file.

The second indictor posted there is the midpoints indicator, as you can see in the name in the top.

MQL4 Comments
mql4_comments | 19 Jan 2012 at 11:20

hi your pivot works with my ea.

it is awsome

in the real test it's never get any problem

but in the back test when i pick

Pivot ===> double P = iCustom(NULL,0,"niamPivot",0,3,0);

R1 ===> double R1 = iCustom(NULL,0,"niamPivot",0,2,0);

S1 ===> double S1 = iCustom(NULL,0,"niamPivot",0,4,0);

it shown different value when i show in comment

Comment(

"\n R1="+R1,

"\n P="+Pivot,

"\n S1="+S1

);

any suggest for back test value....

thanks

MQL4 Comments
mql4_comments | 26 Feb 2012 at 16:17
Good work, thanks a lot.
MQL4 Comments
mql4_comments | 20 Mar 2012 at 09:21
jellybean thanks for the wonderful indicator. However I think there's an error when calculating pivots on mondays. At least it is an error I found yesterday: the pivots where different from the levels of other platforms while on the other days everything corresponds. I live in Italy but my broker is Uk.