How to run code with external data imported by FillSeriesFromFile in portfolio mode?
Author: llhk
Creation Date: 8/11/2015 5:40 AM
profile picture

llhk

#1
My problem is my strategy using external data by FillSeriesFromFile, synchronize them and plotting chart. All above are working fine, but it can only work by clicking "Run the strategy" in "Editor" tab every time for each symbol, but not workable on whole dataset.

Even clicking each symbol, it won't run automatically as usual, but need to click the above "Run the strategy" button.

Note: I use the symbol name as the file name for getting the external data.

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

Eugene

#2
Please show the complete code. Sounds like you mistakenly defined some DataSeries as a class level variable.
profile picture

llhk

#3
I put my DataSeries outside the if condition as it is not allowable.

Here you are:
CODE:
Please log in to see this code.

profile picture

Eugene

#4
These are class level variables and what you described distinguishes them from others defined in the "body" of Execute():

CODE:
Please log in to see this code.


This peculiarity of variables is not all 'bad' as it allows to create useful workarounds like...

WealthScript Techniques | Don't execute Strategy on open


So, move the definitions into the Execute() routine.
profile picture

llhk

#5
CODE:
Please log in to see this code.


it is correct? I still got exactly the same problem~

profile picture

Eugene

#6
Correct. You can not have exactly the same problem after Compile+Go or "Run Strategy". Works perfectly.
profile picture

llhk

#7
Nope, i couldn't do so after Compile. I need to click "Run Strategy" every time to get the results for single symbol, for another code, i can do so by just clicking the particular symbol under the left datasets panel, the strategy will run itself.

I should say that the code run but no result (only "Buy & Hold" has results in Performance Tab), but if i click the "Run Strategy", the result comes out.

For whole dataset, by clicking "Run Strategy" again, only 2 trades done. (The position size is fixed amount)
profile picture

Eugene

#8
What you are describing simply can not happen if you've re-implemented everything properly. I double checked that everything works with some dummy data from CSV file.

1. First of all, make sure the code is free from glaring errors like this one:

CODE:
Please log in to see this code.


i.e. starting the trading loop at bar 20 when using a 100-period SMA for making trades.

2. Your published code doesn't even compile. Although the fix is evident to me, the difference between what you post and what you actually run has great sense.

3. I'd suggest to copy the code into a brand new Strategy window.

4. Next, you don't really need hasData because it's superfluous. Being an integer, FillSeriesFromFile already returns the number of processing errors so your code may continue processing when it's 0 (no errors encountered).

5. Finally, mind the strategy message queue in the Editor -- there can be runtime error messages you're overlooking and that could explain the lack of results.

To stress my point, everything works here and if you want to prove otherwise, please debug your strategy first and then present a complete case that includes: actual code (that compiles), ASCII data (or symbol names if it could be replaced by some publicly accessible data e.g. Yahoo or Google), external data series, data loading settings, position sizing. Thanks.
profile picture

llhk

#9
Thank for your detailed reply, I will try to rewrite my code to test throughout.