Sync "Buy & Hold" with SMA(200) strategy
Author: Lieuallen
Creation Date: 11/30/2012 8:44 PM
profile picture

Lieuallen

#1
I'm writing a strategy that uses the SMA(200) as a signal to enter or exit a different sector rotation selection. I know this is a minor issue, but it's bugging me!

Because I'm using a 200-day SMA, I have to "skip" the first 200 bars (to provide 200 days worth of data). So, when I select a data range, I have to figure out what is 200 trading days before the time period I want to evaluate. This I can deal with.

My issue is that on the Equity Curve graph, the "Buy & Hold" benchmark starts on Bar 0, while my strategy starts on Bar 200. This makes it much more difficult to compare my equity curve with the benchmark (which has had a 200 day headstart!). See the image (if I've attached it correctly!).

I've tried accessing the SMA as both a DataSeries and a Value (both via GetExternalSymbol), and I've tried "shifting" the Bar with "<<200". I am syncronizing the External Symbol (which is VTSMX).

Is there any way for me to get the Buy & Hold benchmark to start at Bar 200?

Thanks!!
profile picture

Eugene

#2
No.

The ability to nullify the effect of the seed data period, known as Lead Bars, was a feature of legacy Wealth-Lab versions but was purposely left out of Version 5/6 for a number of reasons, the main issue is that it was a source of many bugs in Version 3/4.

Check out the Wealth-Lab User Guide, Strategy Window > Backtesting Strategies > Inside a Portfolio Simulation > Note on Lead Bars. Try focusing on performance metrics that are less sensitive to changes in start and stop dates.
profile picture

Lieuallen

#3
Thanks for the info, Eugene. I guess once I'm not such a newbie, I'll do better at finding the answers on my own in the User Guide. I'm still a bit confused at having the User Guide (F1), the Quick Ref (F11) and the on-line manual (as well as having to look-up online for C# help). But I will get better, I promise!

Anyway, I was able to improve the situation by using a DataSeries to hold the Close info the the 200-day SMA:
CODE:
Please log in to see this code.


That way, I only have to "offset" my start by 63 days (for my ROC evaluation). Much more palatable than the 200 day offset.

Again, thanks for your help!
profile picture

Eugene

#4
QUOTE:
That way, I only have to "offset" my start by 63 days (for my ROC evaluation). Much more palatable than the 200 day offset.

That's a misconception. You can not "improve" the situation by "using a DataSeries" or anything for that matter. You should use GetTradingLoopStartBar(200) to start the trading loop from. The 200-day SMA simply does not exist (is 0) before bar 199.
profile picture

Cone

#5
The only way to really get around this is to save your long moving average to disk or memory and load it by synching it to a new series in the trading script. Here's an example -

First run a script on "All Data" that only creates your indicator(s) and puts them in Global memory. Each key for each symbol/DataSeries must be unique.

CODE:
Please log in to see this code.


Now in the trading script (using a range that starts at least 200 bars later than the "All Data" case, retrieve it and synch:

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

Eugene

#6
Nice trick Cone!

There is a way to go with just a single Strategy window loaded with small number of bars (e.g. 200 bars), i.e. w/o using Set/GetGlobal and 2 chart windows. However, the code is longish (~160 lines) and unpretty (using Reflection), so I'm probably going to wrap it in a method like "Bars GetAllDataForBars(...)" and pack it with Community Components (in its upcoming update).
profile picture

Eugene

#7
Here we go: GetAllDataForSymbol
profile picture

Cone

#8
Nice. This is going to be very helpful!

Edit -
Now why didn't I think to use Synchronize?! Changing that now!
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).