Stochastic %D%K

#1
nice one on my disk; enjoy

_SECTION_BEGIN("Stochastic %D%K");

//indicator criteria
periods = Param( "Periods", 15, 1, 200, 1 );
Ksmooth = Param( "%K avg", 3, 1, 200, 1 );
Dsmooth = Param( "%D avg", 3, 1, 200, 1 );
KsDs = StochD( periods , Ksmooth, DSmooth );
Plot( KsDs , _DEFAULT_NAME(), colorRed , ParamStyle("Style") );

periods = Param( "Periods", 15, 1, 200, 1 );
Ksmooth = Param( "%K avg", 3, 1, 200, 1 );
Ks = StochK( periods , Ksmooth);
Plot( Ks , _DEFAULT_NAME(), colorBlue, ParamStyle("Style") );

// criteria buy/short
up = Cross(Ks,KsDs);
down = Cross(KsDs,Ks);

Buy = Cover = up;
Short = Sell = down;
_SECTION_END();

// change the questionmarks the the value which is used to plot the indicator
base_array= ks ;

PlotOHLC (ks ,ks ,KsDs ,KsDs ,"Cloud",IIf(ks >KsDs ,ParamColor("Span1 Color", ColorRGB(0,255,0)),ParamColor("Span2 Color",ColorRGB(255,104,32))),styleCloud);

ExRem(Buy,Sell);
ExRem(Short,Cover);

PlotShapes( Buy * shapeUpTriangle, colorBrightGreen, 0);
PlotShapes( Short * shapeDownTriangle, colorOrange, 0);
PlotShapes( Sell * shapeSmallCircle, colorRed, 0,base_array,Offset=25);
PlotShapes( Cover * shapeSmallCircle, colorDarkGreen, 0,base_array,Offset=-25);

ApplyStop(stopTypeLoss, stopModePercent, Optimize( "stopTypeLoss", 2.5, 2.5, 2.5, 0.5 ) ,2, True );
ApplyStop(stopTypeProfit , stopModePercent, Optimize( "stopTypeProfit ", 2.5, 2.5, 2.5, 0.1 ) ,2, True );


////////////////////////////// HIGHLY IMPORTANT ////////////////////

//ACTIVATE STOPS IN SETTINGS
e = Equity(1,0); /* Highly Important!!. "Removes all extra signals, evaluates
stops AND writes BACK signals to Sell/Cover arrays". As it should be!!*/

PlotShapes( Buy* shapeUpArrow , colorBlack, 0);
PlotShapes( Short* shapeDownArrow , colorBlack, 0);

/*
1 - regular exit
2 - Max. loss
3 - profit target
4 - trailing
5 - ruin stop
6 - n-bar stop
*/

PlotShapes(IIf(Cover==2, shapeCircle, shapeNone),colorRed,0,base_array,0); //stoploss
PlotShapes(IIf(Cover==3, shapeCircle, shapeNone),colorGreen,0,base_array,0); //profit target

PlotShapes(IIf(Sell==2, shapeCircle, shapeNone),colorRed,0,base_array,0); //stoploss
PlotShapes(IIf(Sell==3, shapeCircle, shapeNone),colorGreen,0,base_array,0); //profit target

////////////////////////////////////////////////////////////////////////////////
OffsetBuy = Param("Offset_Buy (green)", -9, -25, 25, 1 );
OffsetSell = Param("Offset_Sell (blue)", 2, -25, 25, 1 );
OffsetShort = Param("Offset_Short (red)", 7, -25, 25, 1 );
OffsetCover = Param("Offset_Cover (orange)", -4, -25, 25, 1 );

OND=Ref(O,1); //OPEN NEXT DAY
base_arrayBUY=base_array+OffsetBuy ; //just for offset
base_arraySELL=base_array+OffsetSell ; //just for offset
base_arraySHORT=base_array+OffsetShort ; //just for offset
base_arrayCOVER=base_array+OffsetCover ; //just for offset

for( i = 0; i < BarCount; i++ )
{
if( Buy ) PlotText( "EL " + OND[ i ], i, base_arrayBUY[ i ], colorGreen );
if( Sell AND NOT Short ) PlotText( "LE " + OND[ i ], i, base_arraySELL[ i ], colorBlue);
if( Short ) PlotText( "ES " + OND[ i ], i, base_arraySHORT[ i ], colorRed);
if( Cover AND NOT Buy ) PlotText( "SE " + OND[ i ], i, base_arrayCOVER[ i ], colorOrange);
}

////////////////////////////////////////////////////////////////////////////////

_SECTION_BEGIN("trending ribbon");
GraphXSpace=15;
uptrend=Buy;
downtrend=Short;
Plot( 2, "ribbon",IIf( uptrend, colorGreen, IIf( downtrend, colorRed, colorLavender )), styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );
_SECTION_END();

////////////////////////////////////////////////////////////////////////////////

_SECTION_BEGIN("_BollingerLine Indicator");

GraphXSpace=7;


periods = Optimize("periods ",Param("periods ",20,1,48,1),1,48,1);
width = Optimize("width ",Param("width ",2,0.1,10,0.1),2,2,0.1);

C1 = C - BBandBot( Close, periods, width) ;
C2 = BBandTop (Close,periods,width) - BBandBot( Close, periods, width);

R = (C1 / C2)*100;
RS = (AMA( C1, 0.5 ) / AMA( C2, 0.5 ))*100; //smooth

uptrend = r > Ref(r,-1);
downtrend = r < Ref(r,-1);

uptrendS = rs > Ref(rs,-1);
downtrendS = rs < Ref(rs,-1);

BS = ParamToggle("smooth","No|Yes",0);
BN = ParamToggle("normal","No|Yes",0);

if (BS) Plot( RS , " smooth ", IIf(( uptrendS ), colorBlack, colorRed ));
if (BS) Plot ( 2, "", IIf( uptrendS , colorBlack, IIf( downtrendS , colorRed, colorPink )), styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );

if (BN) Plot( R , " normal ", IIf(( uptrend ), colorBlack, colorRed ));
if (BN) Plot ( 4, "", IIf( uptrend, colorBlack, IIf( downtrend, colorRed, colorPink )), styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );

_SECTION_END();

_SECTION_BEGIN("Bollinger Bands");
P = rs ;//ParamField("Price field",-1);
//Periods = Param("Periods", 15, 2, 100, 1 );
//Width = Param("Width", 2, 0, 10, 0.05 );
Color = ParamColor("Color", colorLightGrey );
Style = ParamStyle("Style", styleLine | styleNoLabel ) | styleNoLabel;
bbt = BBandTop( P, Periods, Width );
bbb = BBandBot( P, Periods, Width );
Plot( bbt , "BBTop" + _PARAM_VALUES(), colorBlack, Style );
Plot( bbb , "BBBot" + _PARAM_VALUES(), colorBlack, Style );
PlotOHLC( bbt, bbt, bbb, bbb, "", ColorBlend( Color, colorWhite, 0.9 ), styleNoLabel | styleCloud | styleNoRescale, Null, Null, Null, -1 );
_SECTION_END();

bbm = (bbb + bbt) / 2; // middle bollingerbands
f= Optimize("colored bandsize factor",Param("colored bandsize factor",2,1,21,1),1,21,1);

bbmf = (bbm / 100) * f;

bwup = (bbt - bbmf);
bwlo = (bbb + bbmf);

PlotOHLC (bbb ,bbb ,bwlo ,bwlo ,"lowercloud",colorPink,styleCloud,0,0,0);
PlotOHLC (bbt ,bbt ,bwup ,bwup ,"uppercloud",colorBrightGreen,styleCloud,0,0,0);
Plot( bbm , "BBMiddle" + _PARAM_VALUES(), colorPink, styleDashed );

_SECTION_END();
 

KelvinHand

Well-Known Member
#2
nice one on my disk; enjoy

_SECTION_BEGIN("Stochastic %D%K");

//indicator criteria

periods = Param( "Periods", 15, 1, 200, 1 );
Ksmooth = Param( "%K avg", 3, 1, 200, 1 );

Dsmooth = Param( "%D avg", 3, 1, 200, 1 );
KsDs = StochD( periods , Ksmooth, DSmooth );
Plot( KsDs , _DEFAULT_NAME(), colorRed , ParamStyle("Style") );

periods = Param( "Periods", 15, 1, 200, 1 );
Ksmooth = Param( "%K avg", 3, 1, 200, 1 );

Ks = StochK( periods , Ksmooth);
Plot( Ks , _DEFAULT_NAME(), colorBlue, ParamStyle("Style") );

// criteria buy/short
up = Cross(Ks,KsDs);
down = Cross(KsDs,Ks);

Buy = Cover = up;
Short = Sell = down;
_SECTION_END();


// change the questionmarks the the value which is used to plot the indicator
base_array= ks ;

PlotOHLC (ks ,ks ,KsDs ,KsDs ,"Cloud",IIf(ks >KsDs ,ParamColor("Span1 Color", ColorRGB(0,255,0)),ParamColor("Span2 Color",ColorRGB(255,104,32))),styleCloud);

ExRem(Buy,Sell);
ExRem(Short,Cover);

PlotShapes( Buy * shapeUpTriangle, colorBrightGreen, 0);
PlotShapes( Short * shapeDownTriangle, colorOrange, 0);
PlotShapes( Sell * shapeSmallCircle, colorRed, 0,base_array,Offset=25);
PlotShapes( Cover * shapeSmallCircle, colorDarkGreen, 0,base_array,Offset=-25);

ApplyStop(stopTypeLoss, stopModePercent, Optimize( "stopTypeLoss", 2.5, 2.5, 2.5, 0.5 ) ,2, True );
ApplyStop(stopTypeProfit , stopModePercent, Optimize( "stopTypeProfit ", 2.5, 2.5, 2.5, 0.1 ) ,2, True );


////////////////////////////// HIGHLY IMPORTANT ////////////////////

//ACTIVATE STOPS IN SETTINGS
e = Equity(1,0); /* Highly Important!!. "Removes all extra signals, evaluates
stops AND writes BACK signals to Sell/Cover arrays". As it should be!!*/

PlotShapes( Buy* shapeUpArrow , colorBlack, 0);
PlotShapes( Short* shapeDownArrow , colorBlack, 0);

/*
1 - regular exit
2 - Max. loss
3 - profit target
4 - trailing
5 - ruin stop
6 - n-bar stop
*/

PlotShapes(IIf(Cover==2, shapeCircle, shapeNone),colorRed,0,base_array,0); //stoploss
PlotShapes(IIf(Cover==3, shapeCircle, shapeNone),colorGreen,0,base_array,0); //profit target

PlotShapes(IIf(Sell==2, shapeCircle, shapeNone),colorRed,0,base_array,0); //stoploss
PlotShapes(IIf(Sell==3, shapeCircle, shapeNone),colorGreen,0,base_array,0); //profit target

////////////////////////////////////////////////////////////////////////////////
OffsetBuy = Param("Offset_Buy (green)", -9, -25, 25, 1 );
OffsetSell = Param("Offset_Sell (blue)", 2, -25, 25, 1 );
OffsetShort = Param("Offset_Short (red)", 7, -25, 25, 1 );
OffsetCover = Param("Offset_Cover (orange)", -4, -25, 25, 1 );

OND=Ref(O,1); //OPEN NEXT DAY
base_arrayBUY=base_array+OffsetBuy ; //just for offset
base_arraySELL=base_array+OffsetSell ; //just for offset
base_arraySHORT=base_array+OffsetShort ; //just for offset
base_arrayCOVER=base_array+OffsetCover ; //just for offset

for( i = 0; i < BarCount; i++ )
{
if( Buy ) PlotText( "EL " + OND[ i ], i, base_arrayBUY[ i ], colorGreen );
if( Sell AND NOT Short ) PlotText( "LE " + OND[ i ], i, base_arraySELL[ i ], colorBlue);
if( Short ) PlotText( "ES " + OND[ i ], i, base_arraySHORT[ i ], colorRed);
if( Cover AND NOT Buy ) PlotText( "SE " + OND[ i ], i, base_arrayCOVER[ i ], colorOrange);
}

////////////////////////////////////////////////////////////////////////////////

_SECTION_BEGIN("trending ribbon");
GraphXSpace=15;
uptrend=Buy;
downtrend=Short;
Plot( 2, "ribbon",IIf( uptrend, colorGreen, IIf( downtrend, colorRed, colorLavender )), styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );
_SECTION_END();

////////////////////////////////////////////////////////////////////////////////

_SECTION_BEGIN("_BollingerLine Indicator");

GraphXSpace=7;


periods = Optimize("periods ",Param("periods ",20,1,48,1),1,48,1);
width = Optimize("width ",Param("width ",2,0.1,10,0.1),2,2,0.1);

C1 = C - BBandBot( Close, periods, width) ;
C2 = BBandTop (Close,periods,width) - BBandBot( Close, periods, width);

R = (C1 / C2)*100;
RS = (AMA( C1, 0.5 ) / AMA( C2, 0.5 ))*100; //smooth

uptrend = r > Ref(r,-1);
downtrend = r < Ref(r,-1);

uptrendS = rs > Ref(rs,-1);
downtrendS = rs < Ref(rs,-1);

BS = ParamToggle("smooth","No|Yes",0);
BN = ParamToggle("normal","No|Yes",0);

if (BS) Plot( RS , " smooth ", IIf(( uptrendS ), colorBlack, colorRed ));
if (BS) Plot ( 2, "", IIf( uptrendS , colorBlack, IIf( downtrendS , colorRed, colorPink )), styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );

if (BN) Plot( R , " normal ", IIf(( uptrend ), colorBlack, colorRed ));
if (BN) Plot ( 4, "", IIf( uptrend, colorBlack, IIf( downtrend, colorRed, colorPink )), styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );

_SECTION_END();

_SECTION_BEGIN("Bollinger Bands");
P = rs ;//ParamField("Price field",-1);
//Periods = Param("Periods", 15, 2, 100, 1 );
//Width = Param("Width", 2, 0, 10, 0.05 );
Color = ParamColor("Color", colorLightGrey );
Style = ParamStyle("Style", styleLine | styleNoLabel ) | styleNoLabel;
bbt = BBandTop( P, Periods, Width );
bbb = BBandBot( P, Periods, Width );
Plot( bbt , "BBTop" + _PARAM_VALUES(), colorBlack, Style );
Plot( bbb , "BBBot" + _PARAM_VALUES(), colorBlack, Style );
PlotOHLC( bbt, bbt, bbb, bbb, "", ColorBlend( Color, colorWhite, 0.9 ), styleNoLabel | styleCloud | styleNoRescale, Null, Null, Null, -1 );
_SECTION_END();

bbm = (bbb + bbt) / 2; // middle bollingerbands
f= Optimize("colored bandsize factor",Param("colored bandsize factor",2,1,21,1),1,21,1);

bbmf = (bbm / 100) * f;

bwup = (bbt - bbmf);
bwlo = (bbb + bbmf);

PlotOHLC (bbb ,bbb ,bwlo ,bwlo ,"lowercloud",colorPink,styleCloud,0,0,0);
PlotOHLC (bbt ,bbt ,bwup ,bwup ,"uppercloud",colorBrightGreen,styleCloud,0,0,0);
Plot( bbm , "BBMiddle" + _PARAM_VALUES(), colorPink, styleDashed );

_SECTION_END();


Repeated parameters. Replace below for above Grey Section

Code:
_SECTION_BEGIN("Stochastic %D%K");

//indicator criteria
periods = Param( "Periods", 15, 1, 200, 1 );
Ksmooth = Param( "%K avg", 3, 1, 200, 1 );
Dsmooth = Param( "%D avg", 3, 1, 200, 1 );
KsDs = StochD( periods , Ksmooth, DSmooth );
Ks = StochK( periods , Ksmooth);

Plot( KsDs , _DEFAULT_NAME(), colorRed , ParamStyle("Style") );
Plot( Ks , _DEFAULT_NAME(), colorBlue, ParamStyle("Style") );

// criteria buy/short
up = Cross(Ks,KsDs);
down = Cross(KsDs,Ks);

Buy = Cover = up;
Short = Sell = down;
_SECTION_END();
 
Last edited:

Similar threads

Intraday Higher Leverage

Save up to 90% in brokerage and get higher leverage for intraday trades.

Name:Phone:
Email:City:
State:
Are you a day trader?