I had initially posted my question at the below link and was rightfully asked to start another thread.

Since the topic of this post is wrt interval, I may have creatyed some confusion - just to clarify - I am trying to write a code which "automatically changes the values of stochastic ( "periods, Ksmooth, Dsmooth") based on the ATR volatility" .

I only come to the forum for help after trying with what little understanding I have, so I consider myself as a newbie ! Here is another cry for help--

I have been using an ATR based volatility (ribbon plotted below stochastic for visual look only) and then manually (param) change the values of "periods, Ksmooth, Dsmooth" for the stochastic indicator as the volatility changes.

I have tried to write a code to automatically change the values, with change in volatility, but still being relatively new have had no success.

First I will post the code "

```
t
// using ATR as a measure of volatility - hourly chart has 7 bars in a day, 14 bars = 2days and 35 bars = 1 week
X = (ATR(14)-LLV(ATR(14),35))*100/(HHV(ATR(14),35)-LLV(ATR(14),35)); //% position of current ATR(14) over last 35 bars
zonecolor = IIf(x > 70,colorRed, IIf( x > 40 AND x < 70, coloryellow, colorLime)); // below 40, color lime = low volatility
Plot(3," Zone",Zonecolor,styleOwnScale|styleArea|styleNoLabel|styleNoTitle,0, 100 );
///// Is there a way to automatically change the values of "periods, Ksmooth, Dsmooth" as the ATR volatility changes /////
_SECTION_BEGIN("Stochastic %D");
periods = Param( "Periods", 15, 1, 200, 1 ); // colorred = 5, coloryellow = 14, colorlime = 21
Ksmooth = Param( "%K avg", 3, 1, 200, 1 ); // colorred = 3, coloryellow = 5, colorlime = 8
Dsmooth = Param( "%D avg", 3, 1, 200, 1 ); //colorred = 3, coloryellow = 5, colorlime = 8
Plot( StochD( periods , Ksmooth, DSmooth ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();
_SECTION_BEGIN("Stochastic %K");
periods = Param( "Periods", 15, 1, 200, 1 ); // colorred = 3, coloryellow = 5, colorlime = 8
Ksmooth = Param( "%K avg", 3, 1, 200, 1 ); // colorred = 3, coloryellow = 5, colorlime = 8
Plot( StochK( periods , Ksmooth), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();
```

The values of the stoch. depend on the volatility as measeured by the ATR and required values are

mentioned after "//".

The basic concept is from the book "High Probability Trading Strategies " by Robert C. Miner

of DYNAMIC TRADER "https://www.dynamictraders.com/ ".

At the below link

@Tomasz has offered 2 suggestions for changing the values wrt the interval. I think some modification of the switch statement should work -- still trying with no success.

Any help will be much appreciated. Thanks.