Most of the trading systems I use are for long positions, and as a result they only work when the market is in a healthy state. However different systems require different conditions to be met. For example, most of my systems (long term or swing-trade) require that the S&P 500’s 40-day moving average be greater than the 120-day moving average. However, several systems I use require not only that condition, but also that the 120-day moving average be the highest of the last 50 periods. And at least one system requires that the S&P’s Close of the previous day be greater than the 120-day moving average.
So I’ve set up a handy indicator in ProRealTime (awesome free charting software) to give me an instant view of the current market’s health. Basically, if the black line is at the top (at 3) and the bar is light green, then all conditions are hit. If the black line is lower than 3, then I need to take a closer look to see what condition is not being met.
First, the code:
RETURN level1+level2+level3 AS “combined”, level1 AS “fma>sma”, level2 AS “sma highest”, level3 AS “close above”
In the upper right corner of the ProRealTime chart window you’ll see the little pop-up menu icon (circled below in green). Click on the arrow and select “indicators”.
Below you can see the coding section for indicators. Paste the code from the beginning of this blog post in here. Give it a catchy name at the top, like I did. Then click the big “Add indicator to chart” button in the lower right corner.
The indicator will initially be a bunch of angular black lines. Let’s go fix that! Your new indicator will be in a sub-window at the bottom. Click the wrench icon in that sub-window to edit the indicator.
Below you’ll see the indicator settings. The “combined” sub-indicator should be fine as a black line, but you can mess around with color and style if you’d like. But click on each of the other sub-indicators and turn their style setting to “histogram”. And pick colors for them. The lowest in the set will display in front, so I have set the “fma>sma” bar to dark green the “sma highest” bar to medium green, and “close above” to be light green.
I created a new template for this, so I can call everything up in one click. Select “SPY” as your ticker symbol, make sure your indicator is showing below, and then go up to the Templates menu and save a new template.
And then, very important, save your work! PRT has a funny way of not saving things before it quits on its own. Bad robot!
This is just a quick little code snippet and I might refine it later, but it’s useful to integrate into my pre-trade checklist. There’s nothing worse than committing money to a trade, only to realize you forgot to check something first. This helps me not screw it all up, and perhaps it will help you too.