Latest News

2022 Start working on a new website

BBS Trading Expert
Watch the Youtube BBS video and here is a crude oil trading example


Want to know more about:

NinjaTrader formulas.

MetaStock formulas.

MetaTrader formulas.

My YouTube videos.

AXIOM business books awards, bronze medal! Thank You!

No longer available!



Favorite articles in 2010, 11, 12, 14 and 2015 S&C Readers' Choice Awards.

readers choice awards

AXIOM Business Books Awards, bronze medal.

AXIOM award






MetaTrader Formulas

HOME   Back to MetaTrader Formulas Overview

SvePivots Intra day pivot levels

Daily pivot levels calculated on the previous day’s high, low, and close provide important intraday static support & resistance levels.



Special offer: "Capturing Profit with technical Analysis"


//|                               SvePivots.mq4 Version 3.3 |
//|                 Copyright © 2008-2017, Sylvain vervoort |
//|                            |
#property copyright   "©2008-2018, Sylvain vervoort"
#property link        ""
#property description "Pivot points calculated on previous day"
#property description "with Lowest low and Highest high price,"
#property description "Not on Daily, weekly or monthly! 2018 V3.3"
#property description " "
#property description "Make sure you have a clean correct database!"
#property strict

#property indicator_chart_window
#property indicator_buffers 15

#property indicator_color1  Blue
#property indicator_color2  Red
#property indicator_color3  SkyBlue
#property indicator_color4  Coral
#property indicator_color5  Aqua
#property indicator_color6  Pink
#property indicator_color7  LightBlue
#property indicator_color8  Magenta
#property indicator_color9  LightGray
#property indicator_color10 LightGray
#property indicator_color11 LightGray
#property indicator_color12 LightGray
#property indicator_color13 LightGray
#property indicator_color14 LightGray
#property indicator_color15 LightGreen

#property indicator_width1  1
#property indicator_width2  1
#property indicator_width3  1
#property indicator_width4  1
#property indicator_width5  1
#property indicator_width6  1
#property indicator_width7  1
#property indicator_width8  1
#property indicator_width9  1
#property indicator_width10 1
#property indicator_width11 1
#property indicator_width12 1
#property indicator_width13 1
#property indicator_width14 1
#property indicator_width15 1

#property indicator_style1  STYLE_DASH
#property indicator_style2  STYLE_DASH
#property indicator_style3  STYLE_DASH
#property indicator_style4  STYLE_DASH
#property indicator_style5  STYLE_DASH
#property indicator_style6  STYLE_DASH
#property indicator_style7  STYLE_DASH
#property indicator_style8  STYLE_SOLID
#property indicator_style9  STYLE_DASH
#property indicator_style10 STYLE_DASH
#property indicator_style11 STYLE_DASH
#property indicator_style12 STYLE_DASH
#property indicator_style13 STYLE_DASH
#property indicator_style14 STYLE_DASH
#property indicator_style15 STYLE_SOLID

//---- input parameters
extern int DiffLocMinServTme=0; // Difference Local Time Minus Server Time


//---- buffers and other Definitions
double PPBuffer[];  // Pivot Point
double S1Buffer[];  // Support 1
double R1Buffer[];  // Resistance 1
double S2Buffer[];  // Support 1
double R2Buffer[];  // Resistance 2
double S3Buffer[];  // Support 1
double R3Buffer[];  // Resistance 3
double PLBuffer[];  // Previous day low
double S1MBuffer[]; // Support 1 mean value
double R1MBuffer[]; // Resistance 1 mean value
double S2MBuffer[]; // Support 2 mean value
double R2MBuffer[]; // Resistance 2 mean value
double S3MBuffer[]; // Support 3 mean value
double R3MBuffer[]; // Resistance 3 mean value
double PHBuffer[];  // Previous day High
double PP, S1, S2, S3, R1, R2, R3, PL, LastHigh, LastLow;
double S1M, S2M, S3M, R1M, R2M, R3M, PH;
int    GMTDiff = 0, DstTime, DstCorrection, DifLocMinServ;
int    ThisDay, PrevDay;    
bool   SundayTrade = false;
//| SvePivots indicator initialisation function                      |
int OnInit()
// Check validity of the input: Local minus Server time
DifLocMinServ = DiffLocMinServTme;
if( MathAbs(DifLocMinServ) > 12 )
DifLocMinServ = 0;
Alert("Enter a valid difference for Local minus Server time!");
Alert("Invalid! Difference should be +-12, 0 used instead!");

// Buffer parameters  
SetIndexStyle(0,  DRAW_LINE, STYLE_DOT);
SetIndexStyle(1,  DRAW_LINE, STYLE_DOT);
SetIndexStyle(2,  DRAW_LINE, STYLE_DOT);
SetIndexStyle(3,  DRAW_LINE, STYLE_DOT);
SetIndexStyle(4,  DRAW_LINE, STYLE_DOT);
SetIndexStyle(5,  DRAW_LINE, STYLE_DOT);
SetIndexStyle(6,  DRAW_LINE, STYLE_DOT);
SetIndexStyle(7,  DRAW_LINE, STYLE_SOLID);

SetIndexStyle(8,  DRAW_LINE, STYLE_DOT);
SetIndexStyle(9,  DRAW_LINE, STYLE_DOT);
SetIndexStyle(10, DRAW_LINE, STYLE_DOT);
SetIndexStyle(11, DRAW_LINE, STYLE_DOT);
SetIndexStyle(12, DRAW_LINE, STYLE_DOT);
SetIndexStyle(13, DRAW_LINE, STYLE_DOT);
SetIndexStyle(14, DRAW_LINE, STYLE_SOLID);

SetIndexBuffer(0, PPBuffer);
SetIndexBuffer(1, S1Buffer);
SetIndexBuffer(2, R1Buffer);
SetIndexBuffer(3, S2Buffer);
SetIndexBuffer(4, R2Buffer);
SetIndexBuffer(5, S3Buffer);
SetIndexBuffer(6, R3Buffer);
SetIndexBuffer(7, PLBuffer);

SetIndexBuffer(8,  S1MBuffer);
SetIndexBuffer(9,  R1MBuffer);
SetIndexBuffer(10, S2MBuffer);
SetIndexBuffer(11, R2MBuffer);
SetIndexBuffer(12, S3MBuffer);
SetIndexBuffer(13, R3MBuffer);
SetIndexBuffer(14, PHBuffer);

// Daylight saving Time correction
DstTime = TimeDaylightSavings();
// wintertime DstTime == 0
// summertime DstTime == daylight saving time difference in
// seconds (+3600 seconds)
if (DstTime==0) DstCorrection = 3600; else DstCorrection = 0;

// Indicator name
string DiffLocServTime = IntegerToString(DifLocMinServ);

// GMT/UTC Difference Local minus Server time
GMTDiff = TimeHour(TimeGMT()) - TimeHour(TimeLocal()) + DifLocMinServ;

SundayTrade    = false;


//| SvePivots Indicator calculation function                         |
int OnCalculate (const int       rates_total,
const int       prev_calculated,
const datetime& time[],
const double&   open[],
const double&   high[],
const double&   low[],
const double&   close[],
const long&     tick_volume[],
const long&     volume[],
const int&      spread[])
// Do not show daily Pivots on Day, Week or Monthly charts
if(Period() == PERIOD_D1)  return(rates_total);
if(Period() == PERIOD_W1)  return(rates_total);
if(Period() == PERIOD_MN1) return(rates_total);

// How many bars in this chart?
int counted_bars = prev_calculated;    // How may bars in the chart?
if (counted_bars < 0) return(-1);      // No bars return error.
if (counted_bars > 0) counted_bars--;  // -1 to start count from index 0.
int limit=(MathMin(rates_total-counted_bars,rates_total-1));

for(int i=limit; i>=0 && !_StopFlag; i--)
// Handle the output for the first history bar
if(i == limit)
LastLow  = open[i];
LastHigh = open[i];

// Keep track of the highest and lowest price
// reached during the current day
if(high[i+1] > LastHigh) LastHigh = high[i+1];
if(low[i+1]  < LastLow)  LastLow  = low[i+1];

// What day of the week are we?
ThisDay = TimeDayOfWeek(Time[i]  +GMTDiff*3600+DstCorrection);
PrevDay = TimeDayOfWeek(Time[i+1]+GMTDiff*3600+DstCorrection);

// Is there data available starting on a Sunday (forex)?
// If yes, set SundayTrade TRUE.
if(ThisDay == 0) SundayTrade = true;

// If current bar and previous bar are within the same day,
// or current bar is a Saterday, just extend the current pivot level
if(ThisDay - PrevDay == 0 || ThisDay == 6) FunctionWriteCurrPivot(i);

// If current and previous day are different AND not a Saterday or
// not a Sunday trade then calculate and draw new pivots
else if(ThisDay != PrevDay && !SundayTrade && ThisDay != 6)
double PriceClose = close[i+1];
double PriceOpen  = open [i];
FunctionCalcNewPivots (i,PriceClose,PriceOpen);
// If there are Sunday Trading hours and this is a Monday,the new week is
// already started on the Sunday, we just extend the Sunday values
else if(SundayTrade && ThisDay == 1) FunctionWriteCurrPivot(i);
// If we have a day change AND trading on Sunday true, we handle it here
// calculating the new pivots and draw them on the chart
else if(ThisDay != PrevDay && SundayTrade)
double PriceClose = close[i+1];
double PriceOpen  = open [i];
FunctionCalcNewPivots (i,PriceClose,PriceOpen);

// +------------------------------------------------------------------+
// Function, store current pivot values for this new bar              |
// +------------------------------------------------------------------+

int FunctionWriteCurrPivot(int a)
PPBuffer[a]  = PP;
S1Buffer[a]  = S1;
R1Buffer[a]  = R1;
S2Buffer[a]  = S2;
R2Buffer[a]  = R2;
S3Buffer[a]  = S3;
R3Buffer[a]  = R3;
PLBuffer[a]  = PL;

S1MBuffer[a] = S1M;
R1MBuffer[a] = R1M;
S2MBuffer[a] = S2M;
R2MBuffer[a] = R2M;
S3MBuffer[a] = S3M;
R3MBuffer[a] = R3M;
PHBuffer [a] = PH;

// +-------------------------------------------------------------------+
// Function calculate new pivott values for this new bar               |
// +-------------------------------------------------------------------+

int FunctionCalcNewPivots(int a, double PrClose, double PrOpen)
PP =  (LastHigh + LastLow        + PrClose) / 3;
R1 =  (2*PP)    - LastLow;
S1 =  (2*PP)    - LastHigh;
R2 =  PP        + (LastHigh      - LastLow);
S2 =  PP        - (LastHigh      - LastLow);
R3 =  (2*PP)    + (LastHigh      - (2*LastLow));
S3 =  (2*PP)    - ((2* LastHigh) - LastLow);
PL              = LastLow;

R1M = (R1-PP)/2 + PP;
S1M = (PP-S1)/2 + S1;
R2M = (R2-R1)/2 + R1;
S2M = (S1-S2)/2 + S2;
R3M = (R3-R2)/2 + R2;
S3M = (S2-S3)/2 + S3;
PH  = LastHigh;

LastLow      = PrOpen;
LastHigh     = PrOpen;
PrevDay      = ThisDay;
// ------------------------------------------------------------------------

Search the Internet


HOME   Back to MetaTrader Formulas Overview


Risk Disclosure: Futures and forex trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones’ financial security or life style. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results.

Hypothetical Performance Disclosure: Hypothetical performance results have many inherent limitations, some of which are described below. no representation is being made that any account will or is likely to achieve profits or losses similar to those shown; in fact, there are frequently sharp differences between hypothetical performance results and the actual results subsequently achieved by any particular trading program. One of the limitations of hypothetical performance results is that they are generally prepared with the benefit of hindsight. In addition, hypothetical trading does not involve financial risk, and no hypothetical trading record can completely account for the impact of financial risk of actual trading. for example, the ability to withstand losses or to adhere to a particular trading program in spite of trading losses are material points which can also adversely affect actual trading results. There are numerous other factors related to the markets in general or to the implementation of any specific trading program which cannot be fully accounted for in the preparation of hypothetical performance results and all which can adversely affect trading results.

See more 'Legal Disclosures' in the bottom menu bar!

Copyright © 2007, All rights reserved.