60 minute stochastics code
Author: trader rog
Creation Date: 7/3/2009 10:12 AM
profile picture

trader rog

#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.
profile picture

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:
Please log in to see this code.
profile picture

trader rog

#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.
profile picture

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)
profile picture

trader rog

#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:
Please log in to see this code.
profile picture

Eugene

#6
After adding series synchronization and some code optimization:
CODE:
Please log in to see this code.
profile picture

trader rog

#7
Thanks so much for your help Eugene! Everything works great. I can't tell you how much time and frustration you saved me. I really appreciate it!
profile picture

Eugene

#8
You're welcome.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).