60 minute stochastics code
Creation Date: 7/3/2009 10:12 AM

#1
Does anyone know how to code a 60 minute stochastics indicator within a strategy that executes based on daily data? I am using RSI for daily signals but would like to add 60 minute stochastics to confirm the daily RSI. I appreciate any feedback.

#### Cone

#2
Normally, one starts with an intraday chart (the base time frame), create intraday and Daily indicators, and program it such that it trades EOD only. That's how I'd do it traditionally and probably still would.

Despite that opinion, this is an interesting proposition because there are more possibilities in Version 5 for accessing data for the same symbol in different scales, so it actually is possible (even though I may have said it wasn't earlier).

Right now, however, we have a few problems left with native synchronization that I'm confident we'll have resolved in the 5.5 release, and they affect solutions like this one. For your particular strategy, though, there's a workaround as identified in the code below.

Below is an example of how to calculate and access a 30-min StochD in a Daily chart. I'm using 30 for the example because it's the highest native intraday timeframe you can get with Fidelity data. 60-min charts are actually scaled from the 30-min data for WLP, so you won't be able to access 60-min bars from a Daily chart. Using another, more laborious method (exporting the intraday indicator data and then reading and synchronizing it manually by code into the Daily scale) you could in fact do this with 60-min bars... but we're not going there today.

CODE:

#3
Thanks very much for your reply. Is it also possible to use 60 minute bars under scale and work from there? For example:

DataSeries stochd = StochD.Series(Bars, 14, 3);
DataSeries stochk = StochK.Series(Bars, 14);
SetScaleDaily();
DataSeries ma = SMA.Series(Close, 200);
DataSeries RSISeries = RSI.Series(Close, 2);
DataSeries ma_1 = SMA.Series(Close, 5);

//Entry rules based on daily bars

I'm not sure if it would make a difference for the solution, but I don't need charts, only the data to perform backtests.

#### Cone

#4
QUOTE:
Is it also possible to use 60 minute bars under scale and work from there?
Nearly correct. As I said, that's the traditional and preferred solution. The thing you have to know is that you must create trades in the base (chart) time scale. So, once you SetScaleDaily() to create Daily indicators (in your case RSI), you must RestoreScale() for the trading. Finally, you need to restrict yourself to trading EOD. See Bars.IsLastBarOfDay in the QuickRef. Keep in mind that you'll need to process trade entries and exits on the first bar of the day too (i.e., Bars.IntradayBarNumber(bar) == 0)

#5
I tried using your advice, but seem to be stuck on the final details. Can anyone please let me know what I am doing wrong? There is also 1 error in the code that I'm not sure how to fix. I appreciate any feedback.

CODE:

#### Eugene

#6
After adding series synchronization and some code optimization:
CODE: