Plotting Stochastic in same pane with price

That means there are 2 y-axis, one for price and another y-axis is 0 to 100.
I prefer the y-axis with 0 to 100 is shown, plus two horizontal lines with values 20 and 80.
Following code failed me, please help, thanks.

_SECTION_BEGIN("StochD");
SetChartOptions(0,chartShowArrows|chartShowDates);
periods = Param( "Periods", 60, 20, 500, 20 );
Ksmooth = Param( "%K avg", 3, 1, 200, 1 );
Dsmooth = Param( "%D avg", 3, 1, 200, 1 );
Plot( StochD( periods , Ksmooth, DSmooth ), _DEFAULT_NAME(), colorGreen,
styleLeftAxisScale |styleOwnScale );
PlotGrid( 80, colorRed, 10, 1, True );
PlotGrid( 20, colorLime, 10, 1, True );
_SECTION_END();

I tried it this way by using Plot() for everything on Left Axis. Dont use StyleOwnScale so everything on the Left is aligned correctly.

Left axis grid is not drawn but Tomasz did mention it as a future feature if i'm not wrong.
You can use GFX to draw your own though.

// Price section code here
_SECTION_BEGIN("StochD");
periods = Param( "Periods", 60, 20, 500, 20 );
Ksmooth = Param( "%K avg", 3, 1, 200, 1 );
Dsmooth = Param( "%D avg", 3, 1, 200, 1 );
Plot( StochD( periods , Ksmooth, DSmooth ), _DEFAULT_NAME(), colorGreen,styleLeftAxisScale );
Plot( 80, "", colorRed,styleLeftAxisScale );
Plot( 20, "", colorLime,styleLeftAxisScale );
_SECTION_END();

In that case you do not need styleownscale and styleleftaxisscale (besides in general you should use either one or the other but not both in same plot line).

Also you can keep PloGrid.

Simply add styleLeftAxisScale to Price plot.

_SECTION_BEGIN("StochD");
SetChartOptions(0,chartShowArrows|chartShowDates);
periods = Param( "Periods", 60, 20, 500, 20 );
Ksmooth = Param( "%K avg", 3, 1, 200, 1 );
Dsmooth = Param( "%D avg", 3, 1, 200, 1 );
Plot( StochD( periods , Ksmooth, DSmooth ), _DEFAULT_NAME(), colorGreen );
PlotGrid( 80, colorRed, 10, 1, True );
PlotGrid( 20, colorLime, 10, 1, True );
_SECTION_END();

_SECTION_BEGIN("Price");
SetChartOptions( 0, chartShowArrows | chartShowDates | chartWrapTitle);
_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} - {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%), Vol %g {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ), V ) );
Plot( C, "Close", ParamColor( "Color", colorDefault ), ParamStyle( "Style" ) | styleNoTitle | GetPriceStyle() | styleLeftAxisScale );
_SECTION_END();

// E.g.further indicator related to price plot
//_SECTION_BEGIN("SMA");
//Plot( MA(C, 50), "MA", ParamColor( "Color", colorDefault ), ParamStyle( "Style" ) | styleNoTitle | styleLeftAxisScale );
//_SECTION_END();

If you want to add e.g. MA() plot to Price then it should use styleLeftAxisScale also.


BTW, it is mandatory rule to use code tags for inserting code(s) to post. Please do not forget next time.

1 Like

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.