Market Analysis Study: Reversal Bars Study Part 1 (incl. Free Indicator & Programming Tutorial)

Updated: Aug 24, 2019

Reversal bars earned their explicit name for their reputation to signal reversals in a market’s price. After some years in the financial markets, I am very aware of the value being wary of popularly accepted folk wisdom.

Fairly often, I find myself in positions that end the trading day with what is generally defined as one type of a reversal bar. Am I facing a higher likelihood of a price reversal? Should this influence my trade management?

The question of this study thus is: Do reversal bars indicate a statistically significant future direction of price?


"The trick, he said over and over again in any number of contexts, is to disregard what everybody tells you until you have thought it through for yourself." - Max Gunther in The Zurich Axioms

I did not find many edges in using candlestick patterns or other complex and precise analysis models of single price bars. For this study, I want to use a simple definition of what is identified as a reversal bar.


Reversal Bar

Definition of a bullish reversal bar

  1. True range > AverageTrueRange(10)

  2. Low is below prior bar's low

  3. Open and Close in the top 30% of bars true range

The symmetrical reverse is true for bearish reversal bars.

The parameters for the average true range function and the percent value are defined as user inputs.


PaintBar Study

For a first visual impression and easier validation of our study results, we begin with a PaintBar indicator that colors the reversal bars on our chart.

As usual, I am using the Tradestation platform and their EasyLanguage. I am applying my coding template. More about this is explained in the blog Free Indicator & Programming Tutorial: Trailing Percent Range.

Step 1: Code header, user inputs and variables

Being neat programmers, we want to add a header to the top of our coding.

In order to structure the coding, we make use of #region and #endRegion. These regions can be expanded/collapsed and help to keep an overview of the coding. They do also reflect in the Outline that you can open on the left side of the editor.

The following inputs are specified:

ATR Length: Number of recent bars to calculate the true ranges' average of.

Percent: The percent value of the bars true range top/bottom part to qualify as a reversal bar.

Color of the bullish/bearish reversal bars: Color to paint the bars with.


I usually have variables that represent the inputs. Although it is possible to work with the inputs, it saves processing load to work with variables.

The variables are declared with <type> <name> followed by their initial value in brackets.


Step 2: Methods to structure and encapsulate reusable code

The necessary preparation is finally done and we can go on with the programming of actions :)

We want to have two methods for the indicator:


Method void AnalysisTechnique_InitMain()

This method is called only once in the processing of the indicator. We use it to assign the user inputs to their fellow variables.

At times, it does also make sense to convert the user inputs in the initial assignment to their respective fellow variable. We are going to do this here with iPercent which we will divide by 100 (the actual operation is performed by multiplying with 0.01. Multiplication is to prefer computationally over division). By doing this calculation only once, we save the processing load when the code runs on all of the bars and in real-time, maybe even on every tick.

I always use this method in my coding to perform initial preparing tasks that need to be done only once.


Method isReversalBar()

The method isReversalBar returns an integer that is either 0 (no reversal bar), 1 (bullish reversal bar) or -1 (bearish reversal bar).

Pro tip: You can optimize performance by structuring your coding thoughtfully. Here, before we make further calculations and checks, we first check whether the bar is greater than the AvgTrueRange(x). By definition, most bars will not pass this check and we save resources to make any further processing. Also, If statements are executed from the left to the right. It makes sense to have to least likely and least computationally intensive conditions on the very left.


Step 3: Main Program

In the final step of this indicator development, we create the 'main program'. That is how I call the region that is processed on every bar's close or every tick.

As we have organized and encapsulated reusable parts of the coding already, this is a rather small part. Which in turn is a sign of proper code structuring.

First, we make sure our initial preparatory method AnalysisTechnique_InitMain() is run at first. This is important, as it is preparing for the remainder of the processing.

Without it running first, the variables giATRLength, giPercentMult, giColorBull, giColorBear are still in their initial values which would lead to false calculations.

Putting it within the once statement makes sure it is only executed once.


We use a switch statement to react on the three possible return values of the isReversalBar() method. Control passes to the matching case expression with the return of the method. The plotPB statement is where the painting of the bar happens. We provide the parameters high, low, open and close to specify which part of the bar is to be colored. The parameters in this code paint the entire bar. Following, we pass the plot name and the forecolor we have derived from the user inputs.

The parameter Default is not having any effect, it is simply a reserved parameter from TradeStation for future use. The last parameter defines the width of the painting. It is, in TradeStation version <10, not automatically the width of the bars on a chart. I use 3 as a constant as this fits my default width on my charts. You might want to adapt this. The possible values are 0-6, where 0 represents the thinnest width and 6 the thickest.

The last case expression Default: is executed when no other case expression matched. For this indicator, it would make no difference to use Case 0: instead, as we know isReversalBar() is always returning -1,0 or 1. We use the NoPlot() statement to unpaint the bar. This is only required when the indicator is calculating intrabar. Painting a bar is not reversed automatically. If a bar fulfills the criteria intrabar and is painted accordingly, the painting is not removed once the bar changes to not fit criteria any longer.

That is it. Press F3 to verify the code and let's see it working!


Applying the indicator to a chart

It is time now to visually inspect a fair number of charts with the indicator in order to form

hypotheses to be tested. Post yours in the comment section, too!

To get us started, here are a few examples of how the PaintBar study looks applied on a chart.



Outlook

For the coming parts of this study, we are going to look at the statistical evaluation by enhancing our coding. Certainly, it is also worth analyzing the impact of 'where' a reversal bar is occurring.


Download the complete free code from our member area here.


Feel free to post your thoughts, ideas, findings and questions in the comment section.


Don't want to miss future posts? Follow me on Twitter, Instagram or subscribe to blog notifications in "My Account" > "Settings".


Copyright © 2019 TRADEATOMY. All rights reserved.