Use data prior to the start date?
Author: mezic11
Creation Date: 12/9/2016 8:14 PM
profile picture

mezic11

#1
Is there a way to have the backtester use data prior to the start date to set the values of indicators used in a given strategy? For example, if one of the indicators in a strategy is a 250 day moving average, the strategy test wont start for a year (250 days), even though prior data exists to set the value of the moving average at the start date. Currently, this lag in the start of a strategy distorts the performance data and the relative performance to buy & hold.
profile picture

Eugene

#2
You'll be amazed at how many times this question was asked. That's why it was added to the Wiki FAQ. Check it out for some background and a workaround:

How to start Buy&Hold from specific bar (not at bar #0)?
profile picture

mezic11

#3
I figured I wasn't the only one to have this issue. Thanks for your continued support. I'm still a newbie and likely to continue to ask stupid questions.
profile picture

mezic11

#4
OK next stupid question....Can I use a combination of drag & drop rules and code based rules in the same strategy? I assume I'll have to drop the "GetAllDataForSymbol" code into the Strategy code view, but not exactly sure how to do it and how it will impact my drag & drop rules. I'm hoping I can apply GetAllDataForSymbol globally to all indicators.
profile picture

Eugene

#5
It's good to be inquisitive, neither one of those questions is stupid. While one cannot combine Rules with code, it's possible to either "Convert to code" or "Open in new strategy window" where you'd install the GetAllDataForSymbol code. Once done there's no way back to Rules. Also it's impossible to apply GetAllDataForSymbol globally.
profile picture

mezic11

#6
Thank Eugene. So are the steps as follows?

1. Create primary strategy in rules
2. Convert rules to code
3. Insert the GetAllDataForSymlol code prior to each indicator

Assuming that is true, which rows from the GetAllDataForSymlol code do I insert? Can you show an example?
profile picture

Eugene

#7
Ralph, your understanding is correct. Here's an illustration of GetAllDataForSymbol (scroll down to "Example"). As always, you can find examples for additional methods in the Wealth-Lab Wiki while built-in functions are documented in the QuickRef (F11 key) and WealthScript Programming Guide.
profile picture

mezic11

#8
Where am I going wrong with this? I'm getting the attached error:

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

Eugene

#9
Install Community Components library and restart WLP.
profile picture

mezic11

#10
Thanks........it compiled successfully, but still doesn't appear to be working. Do i need to copy the code to precede each of the MA and Plot instructions as well?
profile picture

Eugene

#11
Yes, you have to apply GetAllDataForSymbol to each DataSeries that your script has created. Here's your script tweaked.

You'll notice how I've edited it to combine duplicating instructions created by the Rule Wizard (maFast_1 etc) and shared the DataSeries with the plot instructions to avoid having superfluous calls to GetAllDataForSymbol.

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

mezic11

#12
Thanks Eugene. That worked, but what did you do differently aside from cleaning up the code generated by the rule wizard? I noticed you removed the reference to "Dow 30" in the row below. Anything else?

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

Eugene

#13
There's nothing wrong with the "Dow 30" reference but it could generate an error if you don't have that DataSet. This is just an example. Feel free to tailor it to your taste.
profile picture

mezic11

#14
Then I'm not sure why your code worked and mine did not.
profile picture

Eugene

#15
It didn't work because you didn't apply GetAllDataForSymbol to any DataSeries. Just compare it line by line:

CODE:
Please log in to see this code.


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

mezic11

#16
Now i see it. "b."

Thanks.