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.