I have been observing for a while, one of my short term strategies to identify possible good entries or eventually 'emergency exits'. In the past I already explained it quite deeper with a series where I also shared a quick code in order to obtain the strategy to work in full automation: you can find all explanation about strategy concepts, codes and backtests following this link.

However, this kind of strategy creates a large amount of losing trades when price is stuck in major resistances and supports, indeed all MA-based strategies has the same limitation.

With this article series, I'm going to show all steps I made in recent months (long time spent watching strategy behavior), taking the opportunity to share some quick ideas which can be interesting for other members.

The first element

I have some firm beliefs about trading and one of them is the simplest ever: when there is a clean direction, everything works fine. See this chart:

If market was everyday like this, trading would make us billionaires in few months! Situations like this however, happens few times during one month and so I started wondering "what makes that situation different from another?". First of all, there were strong fundamental reasons, allowing market to keep buying a currency against another one, no matter what. Second, price built a strong bullish setup in all timeframes.
Coding these 2 factors in one single strategy becomes really complex, because we have to basically build an Artificial Intelligence and since at the moment I have not such ability (lol) I tried to identify something simple but effective in telling me "we are going up" or "we are going down". At a certain point I came to the Linear Regression Slope indicator.

The indicator tells if price is rising or not, in the given time period. Here's a quick example:

When the indicator crosses the 0 line, means price is losing X% respectively the same price Y periods ago. In this case, the indicator was set 30periods, so when the cross happened, price was losing respectively to 30 periods before. Must not be confusing with some oscillators: if the indicator line is moving down, but still above 0, means price is still rising if compared with Xn periods ago. Indeed on the right side of the example chart, you see how price is substantially flat around the daily open, and the indicator indeed showing flat line near 0. A perfect short setup, with tight stop loss and eventually a buy stop order > daily opening price!

This becomes really interesting to be used in my strategy because most effective trades happen when there is a good daily trend or at least a daily candle in strong direction suggesting possible reversals or continuation in a trend. A day is composed by 96 m15 periods (15 minutes x 96 = 1440 minutes == 1 day) so my time period for the indicator will be 96. See this chart:

When the indicator breakes the 0 line of last 96 periods, most of times gives good representation of what is happening in price. In the example, the indicator became positive after a strong breakout of a previous resistance, which later became support twice. Later the regression slope came back in negative territory and after an attempt to hold bullish direction, finally price lost momentum and used the breakout level as resistance.

I don't certainly mean this is the best indicator ever, but for my particular purpose it's actually the best way I found to collect many aspects and levels and timeframes, in one single data. For what I actually learned about programming, rules have to be complex, but they have to be put down in the simplest way possible. In this case, just by knowing if the indicator output is positive or negative, I can avoid to make the strategy to watch for what is happening in daily timeframe, to detect supports and resistances, and to detect if a breakout happened or not or was the level used as support or resistance.

The code

First step I hade to made was to detect the indicator crossing the 0 line. Here the example code I used to draw a red "Time Marker" line when indicator breakes into negative territory, and of course a green line when into positive:

The strategy at this stage, draws a green timemarker when there is a bullish breakout , while if the opposite direction happens it automatically deletes previous timemarker and draws a new one colored in red (since both has the same key " "). In the following video you already see the outcome obtained running it on JForex platform, and of course the anticipation of something important which will be discussed later (maybe in last article of the series): knowing only what this indicator tells us, is definetly not enough to be profitable! See the video:


With this first article I'm showing the usage of a particular indicator which I found quite helpful once implemented in a whole short term strategy. At this stage I'm just sharing ideas so other people can eventually benefit from this quick work, going deeper in some or all of these aspects. For example, one could use this indicator later for a different strategy, so here immediatly there's the simplest way to code it in JForex platform (Java language).

Any comment is not just welcome but actually required since there's always something I could be wrong, or surely something to improve.

Thank you!
Translate to English Show original