Passing indicator/bar data between Streaming Strategies via files
Author: karla2010
Creation Date: 7/11/2012 8:53 AM
profile picture

karla2010

#1
I would like to output(write) an indicator value from a 5 min (realtime) script to a file and then input(read) that file into a 1 min realtime script.

I was thinking of something like treating the indicator name like price bar data and writing to some dummy symbol name and then using the dummy name to input to the faster time frame.

The integer divisibility of timeframes respected (like write from 20 min and read in 5 min).
profile picture

Eugene

#2
Why the trouble, if you can just do SetScaleCompressed()?
profile picture

karla2010

#3
the amount of computational time for the script and even the computational result are sensitive to sample rate. Lets say I need 3000 bars in th script to get a confident stable result. Then in the 1 min time frame I would have to extend the amount of sample bars to 15000 to compute a 5 min indicator. Also, as I said the result will be different because many indicators are sensitive to sample rate.

If the code takes 10 secs to run with 3000 bars then it will take 50 secs to run with 15000 points.

Hope this explains my motivation.
profile picture

Eugene

#4
Makes sense. How about passing the DataSeries using SetGlobal/GetGlobal?
profile picture

karla2010

#5
Thanks, I was not familiar with those commands. I read over the quickref and get the idea in general.

Just one question. If I SetGlobal in the 5 min time frame and then GetGlobal in the 1 min timeframe, do I have to use SetScaleCompressed(5), RestoreScale() and Synchronize around GetGlobal to chart the 5 min data in the 1 min timeframe?
profile picture

Cone

#6
Sorry, the response below was before I read your motivation.
----
You can use Set/GetGlobal anywhere in WealthScript to share memory between strategy runs or even across Workspaces.

If you want to access 5 minute data in a 1 minute chart, then you're correct about SetScaleCompressed, etc., but you don't need to use global memory if all the data you need is already available in the same script run.

Basically, the design you need can all be accomplished in the 1-minute chart:
1. SetScaleCompressed(5)
2. Create the indicator
3. RestoreScale();
4. Synchronize the indicator

Now you have the 5 minute indicator in the 1 minute chart.
profile picture

Eugene

#7
Robert, I'm under impression that topic starter is trying to avoid SetScaleCompressed?

Anyway, Synchronize is required I think.
profile picture

karla2010

#8
the following passed data perfectly from my 5m strategy code to 1m strategy code


5 min code

CODE:
Please log in to see this code.



1 min code

CODE:
Please log in to see this code.


compared chart values between 5m and 1m and they were the same.
Thanks for the help
profile picture

Eugene

#9
karla2010 asked:
QUOTE:
I've worked out how to pass a dataset from Strategy A to Strategy B using SetGlobal.

My question is what is the format to pass more than one dataset from the Strategy A to Strategy B.

I tried repeating the void etc line with another string name but that produces an error.

profile picture

Eugene

#10
You're not passing DataSets, you're passing DataSeries.

Here's how you can do it very simply:

CODE:
Please log in to see this code.
profile picture

Eugene

#11
Or a more finished example:
CODE:
Please log in to see this code.
profile picture

karla2010

#12
I tried the List concept of SetGlobal by passing from a Monthly strategy to a Weekly strategy and get an index out of range error.

The code is as follows:

In the Monthly strategy
CODE:
Please log in to see this code.


In the Weekly strategy
CODE:
Please log in to see this code.

profile picture

Eugene

#13
dsLM[2] you say? As you have added only two elements to the List, referring to 3rd one will positively trigger an IOOR error.
profile picture

karla2010

#14
My apologies for being so thick. Old habits die hard. I grew up in the days when arrays started from index 1.

Thanks for the help.
profile picture

Eugene

#15
Right, arrays are zero-based in C# so you should start from 0.
CODE:
Please log in to see this code.
profile picture

karla2010

#16
There seems to be some kind of bug in streaming mode when passing dataseries between different timeframes (like 5m to 1m) . DataSeries get displayed fine when in static mode but when in stream mode the dataseries are displayed as a constant for one full day until the next on intraday displays.

Also want to add that in streaming mode the problem is intermittent. Once in a while the display pops back to display the higher timeframe series ok but then goes flat again (displays a constant value for one day) on the next time change.
profile picture

karla2010

#17
so, is this something I should report as a bug or is something more needed in stream mode?
profile picture

Eugene

#18
Maybe neither one. If you could set up a reproducible test case that includes the symbol(s), data loading range, and exact code, one of us technicians can take a look when time permits.
profile picture

karla2010

#19
ok, here are a couple of simple strategies that illustrate the problem.

When I bring this simple test code up fresh(open the 5m strategy, tmp5m) and then open the 1m strategy, tmp1m, everything plots as expected and you can see the 5m rsi indicators, fast and slow(blue-aqua), plotted in the 1m strategy pane, along with the 1m rsi indicators, fast and slow(red-yellow).

However, when I hit compile(1m) and re-generate the 1m chart the blue-aqua curves go flat across each one-day period. This simulates what I see in stream mode.

To be clear, in editor mode on tmp1m, I hit the "compile" button and then hit the "run the strategy" button and the chart curves for the 5m data flatline across a daily period.

Maybe my Global setup code is wrong. Look forward to your feedback.

tmp5m code follows:

CODE:
Please log in to see this code.





tmp1m code follows:

CODE:
Please log in to see this code.
profile picture

karla2010

#20
I noticed you also asked for data ranges and symbol.

I've been using EEM for data and both tmp1m and tmp5m are loaded with a fixed 3500 bars in the Data Panel.
profile picture

Eugene

#21
I don't think there's any bug here. In tmp1m, You're modifying the DataSeries kept directly in Wealth-Lab's global memory without creating a local copy:
CODE:
Please log in to see this code.

On a related note, you don't need to do no SetScaleCompressed/RestoreScale here. Check out the fixed tmp1m below (the 1st code requires no modification):
CODE:
Please log in to see this code.
profile picture

karla2010

#22
The suggested revisions worked perfectly. I was stepping on my own data, great catch.

You guys have helped out enormously with this issue and you have my thanks.

This is a powerful tool for timeframe comparisons and avoids the computational overhead of the compressed data option.
profile picture

karla2010

#23
Here's a follow-up question.

The global sharing works as advertised with one small hitch. If there is a slight delay in execution times between timeframes, then the lower timeframe tries to get data in streaming mode from the upper timeframe before it is available, and a runtime out-of-range error occurs.

For example, say we are sharing data between 1m and 5m frames. The 5m strategy executes in 850ms. The 1m strategy executes in 840ms. So on a 5m mark, like 10:25, the 1m strategy is ready before the 5m strategy and cannot access the new 10:25 datpoint, resulting in a out-of-range error. Waiting a second and then hitting F5, refreshes the 1m strategy and it now finds the data.

The question is, is there someway to delay the lower frame strategy so that it only accesses the 5m frame when the new data is ready?
profile picture

Eugene

#24
Wrap the code in a try/catch block maybe?
profile picture

karla2010

#25
thanks for the suggestion. I looked into try/catch but was left with the same problem of what to do once the OutOfRangeException() was detected.

I know about how much to delay the code, so looked into Thread.Sleep. Will probably try to combine Thread.Sleep with try/catch and see if it works. Any comments?
profile picture

Eugene

#26
If that runtime error occurs due to zero bars, just add this extra rule to abort processing before an error occurs:
CODE:
Please log in to see this code.
profile picture

karla2010

#27
finally got around to a full streaming test of combining try/catch with Thread.Sleep.

Worked perfectly, no more IndexOutOfRangeException.

My intraday global series cover timeframes from 1m to 195m. The built in pauses using Thread.Sleep in the lower timeframes are just enough to make sure all global series are available before being accessed.

Thanks for the try/catch tip.