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

SveStochRsi Stochastic RSI indicator

Detect convergences and divergences between the stochastic RSI indicator and price data.


Stochastic RSI


Special offer: "Capturing Profit with technical Analysis"

//|                                                  SveStochRSI.mq4 |
//|                               Copyright © 2008, Sylvain Vervoort |
//|                                     |
#property copyright   "©2008-2018, Sylvain vervoort"
#property link        ""
#property description "Smoothed Stochastic calculated on RSI 2018 V2.1"
#property strict #property indicator_separate_window
#property indicator_level1  20
#property indicator_level2  80 #property indicator_buffers 1
#property indicator_color1  Blue
#property indicator_width1  1
#property indicator_style1  STYLE_SOLID //---- input parameters
extern int       RSIPeriod           = 21;    // RSI Period
extern int       StochLookbackPeriod =  5;    // Stochastic Lookback Bars
extern int       StochSummingAverage =  8;    // Stochastic SMA Smoothing //---- buffers
double SwingRSI_Buffer[];
double RSI_Buffer     [];
double HiRSI_Buffer   [];
double LowRSI_Buffer  [];
double RSILow_Buffer  [];
double HiLow_Buffer   [];
double ema_Buffer1    [];
double ema_Buffer2    [];

//| SveStochRSI indicator initialisation                             |
int OnInit(void)
//---- indicators
IndicatorBuffers (8);
SetIndexBuffer   (0,SwingRSI_Buffer);

SetIndexBuffer   (1,RSI_Buffer);
SetIndexBuffer   (2,HiRSI_Buffer);
SetIndexBuffer   (3,LowRSI_Buffer);
SetIndexBuffer   (4,RSILow_Buffer);
SetIndexBuffer   (5,HiLow_Buffer);
SetIndexBuffer   (6,ema_Buffer1);
SetIndexBuffer   (7,ema_Buffer2);

//---- name for data Window and indicator subwindow label  
string StrRsiPeriod           = IntegerToString(RSIPeriod);
string StrStochLookbackPeriod = IntegerToString(StochLookbackPeriod);
string StrStochSummingAverage = IntegerToString(StochSummingAverage);

IndicatorShortName("SveStochRSI ("+StrRsiPeriod+" "+StrStochLookbackPeriod+
" "+StrStochSummingAverage+")"+" - ");

// Check validity of the inputs
if(RSIPeriod<1 || StochLookbackPeriod<1 || StochSummingAverage<1)
Alert("All Inputs MUST be > 0!");
RSIPeriod = 21; StochLookbackPeriod = 5; StochSummingAverage = 8;
//---- Init done

//| SVESRSI Indicator                                                |
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[])
int i, limit;
if(prev_calculated<0) return(-1); // Return error No bars available
else limit = rates_total-1;       // -1 addressing counts to 0

// First we buffer the RSI indicator --------------------------------------------------
for(i=limit;i>=0 && !_StopFlag; i--) RSI_Buffer[i]= iRSI(NULL,0,RSIPeriod,PRICE_CLOSE,i);
// Buffering the Highest High and lowest low RSI during the Stochastic lookback //period
for(i=limit; i>=0 && !_StopFlag; i--)
HiRSI_Buffer[i]    = SI_Buffer[ArrayMaximum(RSI_Buffer,StochLookbackPeriod,i)];
LowRSI_Buffer[i]   = SI_Buffer[ArrayMinimum(RSI_Buffer,StochLookbackPeriod,i)];
// Now we buffer the RSI minus the Low RSI value of the lookback period
// Doing the same for the High minus Low RSI value of the lookback period. 
for(i=limit; i>=0 && !_StopFlag; i--)
RSILow_Buffer[i]   = (RSI_Buffer[i]  - LowRSI_Buffer[i]);
HiLow_Buffer[i]    = (HiRSI_Buffer[i]- LowRSI_Buffer[i]);
// Next action is creating the SMA of this 2 last values
for(i=limit; i>=0 && !_StopFlag; i--)
ema_Buffer1[i] = iMAOnArray(RSILow_Buffer,0,StochSummingAverage,0,MODE_SMA,i);
ema_Buffer2[i] = iMAOnArray(HiLow_Buffer, 0,StochSummingAverage,0,MODE_SMA,i);

// Finally the Stochastics formula is applied
// %K = (Current Close - Lowest Low)/(Highest High - Lowest Low) * 100
for(i=limit; i>=0 && !_StopFlag; i--) SwingRSI_Buffer[i]=ema_Buffer1[i]/(0.1 +
(ema_Buffer2[i]))*100;    //----


//+-------------------------------END OF PROGRAM----------------------------+



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.