Is multiple timeframe stochastic calculation broken?

Posted By: mhson

Is multiple timeframe stochastic calculation broken? - 12/03/13 11:26

Hi,
I am trying to make a multiple timeframe system that includes the StochF/Stoch indicator. I am having a hard time to get it to calculate a higher time frame stochastic with the built in indicator.

I created my own version of StochF and that seems to work as expected.

Am I doing something wrong or did I stumble on a bug? It seems that StochF disregards the change of TimeFrame?

This is my script. It plots standard StochF for H1 and H4 (these are identical) and my version of StochF for H1 and H4 below.

Quote:

#define D1 (1440/BarPeriod)
#define H4 (240/BarPeriod)
#define H1 (60/BarPeriod)

function raw_stochF(var k_period, var d_period) {
var close = priceClose();
var highest = HH(k_period);
var lowest = LL(k_period);

return EMA(series(100*(close-lowest)/(highest-lowest)), d_period);
}

function run() {
set(PLOTNOW);
BarPeriod = 60;

StartDate = 20130501;
EndDate = 20130513;

TimeFrame = H4;

var stoch_H4= StochF(7,2, MAType_EMA);
var r_stF_H4 = raw_stochF(7, 2);

TimeFrame = H1;

var stoch_H1= StochF(7,2, MAType_EMA);
var r_stF_H1 = raw_stochF(7, 2);

plot("StochF_H1", stoch_H1, NEW, ORANGE);
plot("StochF_H4", stoch_H4, LINE, RED);
plot("80", 80, LINE, BLACK);
plot("20", 20, LINE, BLACK);

plot("raw_StochF_H1", r_stF_H1, NEW, ORANGE);
plot("raw_StochF_H4", r_stF_H4, LINE, RED);
plot("e80", 80, LINE, BLACK);
plot("e20", 20, LINE, BLACK);
}


Please advice.

Regards
Martin
Posted By: jcl

Re: Is multiple timeframe stochastic calculation broken? - 12/03/13 11:43

Setting TimeFrame affects the subsequent data series. But the StochF function does not take any data series as input. Thus TimeFrame will have no effect on that function.

For multiple timeframes better use the "Normalize" function instead of StochF - or use your own function.
Posted By: mhson

Re: Is multiple timeframe stochastic calculation broken? - 12/03/13 12:59

Ah, I see! Thanks for clearing that up.

Is there a reason why the internal price series used by indicators are not affected by the TimeFrame setting? To me it feels more logical that all indicators should conform to the current TimeFrame setting.

The behavior was just kind of unexpected for me.

/Martin
Posted By: jcl

Re: Is multiple timeframe stochastic calculation broken? - 12/03/13 13:05

Yes, that's understandable - I've just put an additional remark about that in the manual. The reason is that there are no internal price series. Those indicators directly access the raw prices that are unaffected by TimeFrame. Some indicators, such as ATR, come in two versions, one of them is for different time frames.
Posted By: mhson

Re: Is multiple timeframe stochastic calculation broken? - 12/03/13 13:21

Thats what I thought.

Not that I am affected, but does this mean that all the candle pattern detection functions (the CDLxxx() ) operates on the BarPeriod time frame and are more or less unusable in a multi timeframe system?

Thanks for the normalize tip.

/Martin
© 2024 lite-C Forums