Hi. The following code DOES work using MINUTE bars, but doesn’t come up with the right values using RANGE bars. I am not sure what I am doing incorrectly - can someone please have a look and advise. ?

Thanks

```
_SECTION_BEGIN("MJF_DS");
{ // parameters Param( ''name'', defaultval, min, max, step, sincr = 0 )
// grab the interval from the screen
if( Interval() == 86400 ) {
STFTypeDefault = 1;
STFInputValDefault = 1;
} else {
STFTypeDefault = 0;
STFInputValDefault = Interval() / 60;
}
DSperiods = Param( "DSPeriods", 10, 2, 200, 1 ); // Double Stochastic periods
DSKSmoothing = Param( "K Smoothing", 3, 2, 20, 1 ); // Double Stochastic K Smoothing
DSDSmoothing = Param( "D Smoothing", 3, 2, 20, 1 ); // Double Stochastic D Smoothing
DSOb = Param( "DS OverBought", 85, 2, 100, 1 ); // Double Stochastic OverBought line
DSOs = Param( "DS OverSold", 15, 2, 100, 1 ); // Double Stochastic OverSold line
STFType = ParamList("Short TF Type", "MIN|DAILY|WEEKLY|RANGE", STFTypeDefault );
STFInputVal = Param("ShortTF Value",STFInputValDefault,1,60,1);
}
{ // Setup the Short Time Frame
{ // parse the input parameters
switch(STFType)
{
case("MIN"):
STFMode=0;
STF=in1Minute*STFInputVal;
break;
case("DAILY"):
STFMode=0;
STF=inDaily;
break;
case("WEEKLY"):
STFMode=0;
STF=inWeekly;
break;
case("RANGE"):
STFMode=4;
STF=STFInputVal;
break;
}
}
{ // Set the short time frame and calculate the indicators
TimeFrameMode( STFMode );
TimeFrameSet( STF );
div = HHV(H, DSperiods)-LLV(L, DSperiods);
// replace zero values with 0.0001
div = IIf( div == 0, 0.0001, div );
FSK = 100*(C-LLV(L, DSperiods))/(div); // FASTSTOCHK
FLSK = EMA( FSK, DSKSmoothing ); // FULLSTOCHK
div = HHV(FLSK, DSperiods)-LLV(FLSK, DSperiods);
// replace zero values with 0.0001
div = IIf( div == 0, 0.0001, div );
DSK = ((FLSK-LLV(FLSK, DSperiods))/(div)) * 100;
KArray = EMA( DSK, DSDSmoothing );
DArray = MA( KArray, 3);
}
TimeFrameRestore(); // restore time frame to original for plotting
}
tempk = TimeFrameExpand(KArray, STF, mode=expandFirst);
tempd = TimeFrameExpand(DArray, STF, mode=expandFirst);
Plot( tempk, "DSK", ParamColor( "ColorK", colorRed ),styleLine);
Plot( tempd, "DSD", ParamColor( "ColorD", colorBlue ), StyleLine);
Plot(DSOb,"Overbought Level",colorGrey40, styleNoTitle |styleDashed );
Plot(DSOs,"Oversold Level",colorGrey40, styleNoTitle |styleDashed );
_SECTION_END();
```