Looking for Bressert's Double Smoothed Stochastic for MT4
Would you provide the formula/calculation/explanation for it?
Hello Tonyc2a,
Here is the eSignal version I got off of the www.tssupport.com website
Here is the eSignal version I got off of the www.tssupport.com website
/*******************************************************************
Description : This Indicator plots DSS Bressert
Provided By : Developed by TS Support, LLC for eSignal. (c) Copyright 2002
********************************************************************/
function preMain()
{
setStudyTitle("DSS Bressert");
setCursorLabelName("DSS", 0);
setCursorLabelName("Trigger", 1);
setCursorLabelName("Overbought", 2);
setCursorLabelName("Oversold", 3);
setDefaultBarFgColor(Color.blue, 0);
setDefaultBarFgColor(Color.red, 1);
setDefaultBarFgColor(Color.grey, 2);
setDefaultBarFgColor(Color.grey, 3);
}
var EMA_1 = 0;
var EMA1_1 = 0;
var EMA2_1 = 0;
vAA = new Array();
function main(pds,slw,triggerLen,overbought,oversold,emalen){
if (pds == null)
pds = 10;
if (slw == null)
slw = 3;
if (triggerLen == null)
triggerLen = 5;
if (overbought == null)
overbought = 80;
if (oversold == null)
oversold = 20;
if (emalen == null)
emalen = 9;
var vHigh = getValue("High",0,-pds);
var vLow = getValue("Low",0,-pds);
var dClose = getValue("Close");
var K = 2 / (emalen + 1);
var K2 = 2 / (triggerLen + 1);
var aa = 0;
var dss = 0;
var High = 0;
var Low = getValue("Low");
var aHigh = 0;
var aLow = 10000000;
var EMA1 = 0;
var EMA = 0;
for (i = 0; i < pds; i++){
if (High < vHigh[i])
High = vHigh[i];
if (Low > vLow[i])
Low = vLow[i];
}
if((High - Low) != 0)
EMA = K * ( (dClose - Low) / (High - Low) ) + (1 - K) * EMA_1;
else
EMA = EMA_1;
if (getBarState() == BARSTATE_NEWBAR)
EMA_1 = EMA;
aa = EMA * 100;
for(i = pds - 1; i > 0; i--)
vAA[i] = vAA[i - 1];
vAA[0] = aa;
for (i = 0; i < pds; i++){
if (aHigh < vAA[i])
aHigh = vAA[i];
if (aLow > vAA[i])
aLow = vAA[i];
}
if (aHigh - aLow != 0)
EMA1 = K * ( (aa - aLow) / (aHigh - aLow) ) + (1 - K) * EMA1_1;
else
EMA1 = EMA1_1;
if (getBarState() == BARSTATE_NEWBAR)
EMA1_1 = EMA1;
dss = EMA1 * 100;
var EMA2 = K2 * dss + (1 - K) * EMA2_1;
if (getBarState() == BARSTATE_NEWBAR)
EMA2_1 = EMA2;
return new Array(dss,EMA2,overbought,oversold);
}
/*******************************************************************/
and here is my attempt to convert it over the MT4
I am having problems coming to terms with how to construct an indicator in MT4, so maybe someone can see what I am doing wrong.
//+------------------------------------------------------------------+
//| Test.mq4 |
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Yellow
#property indicator_color2 Red
//---- input parameters
extern int Periods=5;
extern int Trigger_Length=3;
extern int EMA_Length=3;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
// Globals
double vHigh = 0;
double vLow = 0;
double vClose = 0;
double Max_High = 0;
double Min_Low = 0;
double EMA = 0;
double Old_EMA = 0;
double K_Val = 0;
double K2_Val = 0;
double EMA1 = 0;
double Old_EMA1 = 0;
double EMA2[];
double Old_EMA2 = 0;
double AA = 0;
double vAA[];
double AA_Low = 0;
double AA_High = 0;
double DSS[];
int CompletedBar = 0;
int CurrentBar = 0;
int Counter = 0;
int Limit = 0;
int i = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,ExtMapBuffer2);
IndicatorShortName("DSS("+Periods+","+Trigger_Length+","+EMA_Length+")");
SetIndexLabel(0,"DSS");
SetIndexLabel(1,"EMA");
ArrayResize(vAA, Periods);
if ( EMA_Length <= 2 )
EMA_Length = 3.0;
if ( Trigger_Length <= 2 )
Trigger_Length = 3.0;
if( Periods <= 5 )
Periods = 5;
K_Val = ( 2 / ( EMA_Length + 1 ));
K2_Val = ( 2 / ( Trigger_Length + 1));
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- TODO: add your code here
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int Limit = 0;
int i = 0;
int Counted_Bars=IndicatorCounted();
K_Val = 0.5;
K2_Val = 0.5;
if ( Bars <= Periods )
return(0);
if ( Counted_Bars < 1 )
{
ArrayResize(DSS, Periods);
ArrayResize(EMA2, Periods);
for( i=1; i<Periods;i++ )
{
DSS[i] = 0.0;
EMA2[i] = 0.0;
}
}
i = Bars - Periods - 1;
//Limit = Bars - Counted_Bars - Periods;
if ( Counted_Bars >= Periods )
i = Bars - Counted_Bars - 1;
while( i >= 0 )
{
vHigh = High[Periods];
vLow = Low[Periods];
vClose = Close[i];
if ( vHigh == 0 || vLow == 0 || vClose == 0 )
return(0);
Old_EMA = EMA;
Old_EMA1 = EMA1;
Old_EMA2 = EMA2[0];
//Max_High = Highest(NULL, 0, MODE_HIGH, Periods, 0);
//Min_Low = Lowest(NULL, 0, MODE_LOW, Periods, 0);
Max_High = ArrayMaximum(High, Periods, 0);
Min_Low = ArrayMinimum(Low, Periods, 0);
if (( Max_High - Min_Low ) != 0 )
EMA = K_Val * (( vClose - Min_Low ) / ( Max_High - Min_Low)) + ( 1 - K_Val ) * Old_EMA;
else
EMA = Old_EMA;
AA = EMA * 100;
for ( Counter = Periods - 1; Counter > 0; Counter-- )
{
vAA[Counter] = vAA[Counter-1];
}
vAA[0] = AA;
for ( Counter = 0; Counter < Periods; Counter++ )
{
if ( Counter == 0 )
AA_Low = vAA[0];
if ( AA_High < vAA[Counter] )
AA_High = vAA[Counter];
if ( AA_Low > vAA[Counter] )
AA_Low = vAA[Counter];
}
if (( AA_High - AA_Low ) != 0 )
EMA1 = K_Val * (( AA - AA_Low ) / ( AA_High - AA_Low )) + ( 1 - K_Val ) * Old_EMA1;
else
EMA1 = Old_EMA1;
DSS[0] = EMA1 * 100;
EMA2[0] = K2_Val * DSS[0] + ( 1 - K2_Val ) * Old_EMA;
ExtMapBuffer1[i] = DSS[0];
ExtMapBuffer2[i] = EMA2[0];
i--;
}
return(0);
}
//+------------------------------------------------------------------+
It is just a Double Smoothed Stochastic
Thanks
EK
Does anyone have this Indicator coded in MT4?
Thanks for your Time
EK