Adding a Weekly-bar overlay to a Daily-bar Strategy
Author: topcat77
Creation Date: 12/14/2009 9:35 AM
profile picture

topcat77

#1
The following strategy seeks to identify and capture uptrends using daily bars. However entries are permitted only when a TREND-SWITCH is turned ON. The TREND-SWITCH uses a technical reading of Weekly Bars for the Index representing the data-set that the strategy points to (eg SPY for the dataset S&P100). So far I have been turning the TREND-SWITCH on and off manually (same with backtesting). I would like to code this into the strategy and have been puzzling how to use the examples in the five Wiki entries for Multi-Time frame but cannot work out a solution. I realize, too, that this will involve importing an external symbol which is an added complication. Please could I get some help ?

The TREND-Switch is defined as follows:
TREND-SWITCH is ON: when MACD histogram for weekly bars crosses over a specified reading, say 5. Entries can begin at the start of the following week.
TREND-SWITCH is OFF: when MACD histogram for weekly bars crosses under a specified reading, say -5. Entries halt from the start of the following week.
(So, to clarify : if the TREND-Switch is ON and the weekly MACD turns negative but does not breach the OFF threshold – a reading of -5 in my example – and turns back up, it has remained in the ON position throughout).

(incidentally, when the TREND-SWITCH is OFF, the direction of entries is reversed because theoretically a Bull-trap is in progress, but this is represented in a different strategy whose coding will also benefit from being able to access the weekly data)
Additionally, all long positions will exit if the Weekly bar closes under its 10sma

As always help or direction is much appreciated

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

Eugene

#2
Here's something for you to start integrating the other rules with the weekly/external series concepts:
CODE:
Please log in to see this code.
profile picture

topcat77

#3

Fantastic, thanks
but I haven't managed to get it to work.
I've inserted the Trendswitch code, as above, into the rest of the script,
the compiler is ok with the effort but I get no trades
and this error message shows for each security in the dataset:


"Error processing symbol AAPL
Object reference not set to an instance of an object."

which I have not come across before

Obviously I have done something incorrect in the integration
Please could you set me right?

CODE:
Please log in to see this code.


please excuse how untidy the code has become

Thank You

profile picture

Eugene

#4
At first glance, I see no errors. You've done a good job integrating the concepts into a Strategy. First thing to check that "SPY" is actually in "SP100", and the data is up to date. For me, it runs fine on an up-to-date DataSet of daily data with on demand update turned off. If this isn't helpful, we'll need the DataSet, the provider, what time frame etc.

Here's some more insight on Object reference not set to an instance of an object in the Wealth-Lab 5 Wiki.
profile picture

topcat77

#5
QUOTE:
First thing to check that "SPY" is actually in "SP100",


This was exactly the problem : I pointed the code to the Dataset that
contained SPY and the strategy ran. Except that performance results for the
strategy with the filter are exactly the same as performance results
for the strategy without the filter. So the TrendSwitch doesn't seem to kick ON
or OFF

I noticed that the script did not contain an MACD DataSeries so I added that. I then
commented out the additional stop that triggers on the External symbol's weekly bar
to see whether any of that was making a difference.I also set the MACD level at a very low
value (0.10) to see whether there was an issue with how the weekly indicator was calculated
but none of this has made a difference. To run a sanity check on the trigger I created a weekly strategy
for SPY and found the instances of MACD levels the TrendSwitch should have
triggered

What can I do next?

Thank You

profile picture

Eugene

#6
I've got nothing but to repeat: just double checked and the code ran fine in WLD 5.6, producing dozens of trades. This exact error can be caused by "SPY" missing in "SP100".
profile picture

topcat77

#7
Eugene
I get dozens of trades too
The problem, though, is that these are exactly the same dozens of trades
that show when I run the original script without the TrendSwitch. So the script
is working, but the TrendSwitch is not. If it were, then the script with the TrendSwitch
would show different results, and fewer trades
Dinsa
profile picture

Eugene

#8
QUOTE:
The problem, though, is that these are exactly the same dozens of trades
that show when I run the original script without the TrendSwitch.

Excuse me, but how do you plan on putting the TrendSwitchOn to work if you make absolutely no use of this boolean variable in your Strategy? ;)
profile picture

topcat77

#9
oops
how? where? help :(
profile picture

topcat77

#10
like this ?
CODE:
Please log in to see this code.
profile picture

Eugene

#11
Yes, like this.
profile picture

topcat77

#12
Brilliant, that worked. Thank You

I'm trying to identify the points at which the (Weekly)TrendSwitch turns the (daily) strategy ON and OFF
without having to go to a different Strategy that holds Weekly charts. How can I draw a Weekly Macd histogram in a separate pane on the Chart Page for this strategy when all the other panes on the page are for Daily data?
profile picture

Eugene

#13
Please see Multi-Time Frame Analysis > Daily/Weekly in the WealthScript Programming Guide. An example there just is what the doctor ordered: it plots weekly MACD on a separate pane.
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).