I want to run various datasets against a rule that says
1. Buy/Maintain 10 stocks when the 10 week EMA on SPY crosses ABOVE the 40 week EMA on SPY.
- use a 18% stop on stocks in the portfolio
2. Sell all stocks when the 10 week EMA on SPY crosses BELOW the 40 week EMA on SPY.
Example chart attached of a crossover on 4/4 2016
Size:
Color:
Size:
Color:
I set up a rules-based Strategy using External .SPX
When I converted it to code it looks like the code below.
It doesn't look right (I haven't code in 6 years).
and it doesn't find any crossovers on .SPX
CODE:
Please log in to see this code.
Size:
Color:
Irrespective of what it looks, the code is correct and undoubtedly produces trades (on ^GSPC using Yahoo as I don't have access to Fidelity's .SPX data):
Size:
Color:
Thanks Eugene!
Size:
Color:
Is there a way to "lock in" weekly (instead of daily) or does it have to be reset every time?
Size:
Color:
What does "lock in" the bar scale mean? In this code or for all symbols?
Size:
Color:
see .png attached
the red box shows the "Scale". I assume (maybe incorrectly) this applies to the rules as well as graphs.
I want the 10-40 EMAs to be weekly averages.
Size:
Color:
Yes, this applies to
all DataSeries if you Execute the backtest again after changing Scale to Weekly. But if you want to limit it to just some rules that deal with external symbol's data, this can't be (easily) achieved using Rules (if possible). No obstacle for code-based strategies, though. Below please find some pointers and of course check out the WealthScript Programming Guide >
Multi-Time Frame Analysis.
SetScaleWeekly & GetExternalSeries?Adding a Weekly-bar overlay to a Daily-bar StrategyHere's how it can be applied to your strategy. Make sure to load enough data (at least 120 bars). The reason is described in the same Guide, Indicators >
Stability of Indicators chapter.
CODE:
Please log in to see this code.
Size:
Color:
I want to apply the 18% stop during the UP period, so I think it should look like this:
CODE:
Please log in to see this code.
Size:
Color:
CODE:
Please log in to see this code.
Size:
Color:
Referencing the Programming manual, "XU" must be a comment meaning cross under.
Size:
Color: