Buy on certain date in Rule-based strategy
Author: asudchiman
Creation Date: 10/1/2014 11:57 AM
profile picture

asudchiman

#1
Please help. I have been using the WL drag and drop system to build my backtest.
The issue I have is that I have a very slow monthly system and the data is already in buy territory when I want to start the strategy.

As a result, I am trying to find a way to specify using the drag and drop system to ID a specific "Buy" date "or" when my indicator signals in the future.

ex: buy on 1/1/1995 or when RSI (14) crosses above 30

I only know how to use the drag and drop tool and not code.

I would appreciate the assistance.

profile picture

Eugene

#2
For a buy on certain date, add a "Date is after a Calendar Date" condition from the Date/Time group, then click "Open code in new Strategy window" and edit the resulting code. For example, by default you're presented with this:
CODE:
Please log in to see this code.

Change it this way:
CODE:
Please log in to see this code.

Since it's impossible to turn this back into a Rule-based strategy, this edit is best approached when your system is complete.
profile picture

asudchiman

#3
Eugene,
thanks for the help. I was able to improve it, but it still creates a gap between the start of the test and when the signal occurs?

Here is what I want to backtest, maybe you have another idea.


I want to buy on the same day that I start the test. This way there isnt a gap in the benchmark and strategy.
Then I want the indicators to lead going forward.

Setup:
Monthly Data and Signals
100% of the Portfolio


Buy @ Close: RSI 14 Crosses above oversold level of 30
Sell @ Close: Fast Moving Avg (7M SMA) crosses below (20M SMA)

Any suggestions?

Thanks,
Kern


profile picture

Eugene

#4
Kern/Thomas,

QUOTE:
still creates a gap between the start of the test and when the signal occurs?

"Still"? You never mentioned that this shouldn't happen. Especially that this is by design. Indicators can not start at bar #0, it takes (period) bars to start returning values. Additionally, some like the RSI take 3-4 times more than that: for the whys and wherefores, see the WealthScript Guide > Indicators > Stability of Indicators.

QUOTE:
I want to buy on the same day that I start the test.

Not in rule-based strategies but when you switch to code, it's possible:
CODE:
Please log in to see this code.

Make sure to start the trading loop accordingly because by default it starts from bar #20.

QUOTE:
This way there isnt a gap in the benchmark and strategy.

Then you might find this function from Community Components library useful:

GetAllDataForSymbol

Using it you can adjust the code to actually start the trading loop from bar #1 instead of what's required to build e.g. 20-period SMA. But don't select "All data" to avoid the same pitfall.
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).