No SMA in single year backtest?
Author: jahlbeck
Creation Date: 3/29/2010 11:14 AM
profile picture

jahlbeck

#1
Why am I not able to get a 200 day SMA to chart over a one year period?

I am backtesting a strategy based on trades around the 200 day SMA but when testing a single year the SMA will not cover the entire year and the backtest shows no trades.

If I change to two a 2 year timeframe it seems OK and records the trades in both years??
profile picture

Eugene

#2
Approx. 250 bars of data is perfectly enough to work with a 200-day SMA, but the real question here is how you're using that SMA in your Strategy code (missing), on which DataSet and symbol (unknown).

profile picture

jahlbeck

#3
Eugene,

Code below. Fidelity tells me that the old system would build the 200 SMA data using days not included in back-test Data Range but new system does not.

My goal is to look at performance in a data range that trades based on SMA data not included in the Data range.

I currently get no trades in the first 200 days of data range. Any suggested fix?

CODE:
Please log in to see this code.

profile picture

Cone

#4
QUOTE:
I currently get no trades in the first 200 days of data range. Any suggested fix?
Don't fix what's not broken. The Strategy cannot compute the 200-day average until the 200th day, so that's the point at which the trading starts.

See WealthScript Programming Guide: Programming Trading Strategies > Trading Loop


Edit:
Of course, if you want to see trades from say, March 2009, you need to make sure that you load at least 200 bars prior to March 2009. Selecting "Most Recent 2 Years" in the Data Loading control should do it.
profile picture

jahlbeck

#5
For me it is broke because the backtest peformance excludes the first 200 days of trades days.

I have read the guide regarding "loops" and although I am clueless regarding how to program the launguage, it seems to me the system should allow program language that captures previous bars to create an SMA that would trigger trades starting at the begining of the data range (i.e. giving performance results that are acurate and not excluding 200 days of trading.)


Your thoughts?
profile picture

Eugene

#6
QUOTE:
For me it is broke because the backtest peformance excludes the first 200 days of trades days.

Uber simple solution already suggested by Cone: load more data.

Until those 200 days aren't over, your 200-day SMA simply does not exist. In real life, how do you compute the difference between two values today and 200 days ago? By waiting 200 days. Is this clear?

For more info, see Strategy Window > Backtesting Strategies > Inside a Portfolio Simulation > Note on Lead Bars in the User Guide.
profile picture

jahlbeck

#7
I am likely missing something obvious, but I still do not get how I solve the problem by loading more data.

Although additional data creates a SMA that covers additional bars it also creates a new set of bars where no trades take place and includes those additional "no trade" bars in the peformance figures makeing the performance data inacurate.

My objective is not to view trades on specific dates but to have acurate performance data that includes the trades that would have taken place at every bar in the data set and not every bar minus the first 200 or so.

What am I missing?
profile picture

Eugene

#8
Not going to happen: see the Note on Lead Bars (above) in the User Guide. The first 200 bars for an indicator with the lookback of 200 bars will always be seed data.
profile picture

jahlbeck

#9
Ouch!
profile picture

Eugene

#10
However, as Cone suggested above, you can view trades on specific dates - if you load at least 200 bars prior to your specific date.
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).