Can We Execute Multiple Strategies in Sequence?
Author: abr4321
Creation Date: 2/21/2015 2:15 AM
profile picture

abr4321

#1
Hi;

I am using Fidelity streaming 1 minute data and want to run three or more strategies in sequence order that the second one starts when the first one finishes; and the third one kicks in after the second is done executing - and so on.

The reason is that the first one creates files on the hard disk which are used by the second and third. If those strategies are all fired up at the top of the minute, they conflict with each other as the files are being used by the other strategy, thus being unavailable - gives Run Time Error.

The first one runs only 8 to 9 seconds and the rest about 5 to 6 seconds each.

Alternatively, if can I code something in the second and third strategy to wait (time out) for 10 and 20 seconds and then start the processing - that should work too like a charm.

The Wiki 'Time Out' topic deals with delay in terms of 'Bars' and not in time units (seconds or minutes).

Thanks.

profile picture

Eugene

#2
Hi,

For all practical purposes, it's best to merge the file writing code into the 2nd and 3rd strategies introduce a delay with Thread.Sleep after your time-consuming operation:
CODE:
Please log in to see this code.
profile picture

abr4321

#3
Thanks Eugene;

You are right that the best option is to integrate the primary and secondary program codes. We thought about it and also to give different names to files of different threads. But such technique may not work if we roll up the data into higher time periods with 'Setscale'. And we may go that route in near future.

But the 'Sleep Code' that you provided for 10 or more seconds delay - works like a charm. We tried it and it does produce delay. We would try it in streaming when market opens; but we do not expect any problems.

Thanks again. Much obliged ........
profile picture

Cone

#4
For better response and to avoid the possibility that a fixed value of Sleep will not always work, try this..

For the first Strategy in the sequence, write the DateTime of its last bar to global memory ....
CODE:
Please log in to see this code.


Add the WaitForIt() routine to StrategyNumber2, which picks up the DateTime from "StrategyNumber1". The script won't continue until the DateTimes of the last bar match.

CODE:
Please log in to see this code.


Similarly, add WaitForIt() to StrategyNumber3...
CODE:
Please log in to see this code.


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).