Discover more from All About Trading!
Coding the Brown Indicator in TradingView
Presenting and Coding the Brown Indicator
The Brown indicator is the third indicator in the collection of the colored technical indicators which will be presented in future articles. An indicator that can be used in trend following, the strategy will be presented in this article (as opposed to the contrarian strategy presented in previous articles).
I have released a new book called “Contrarian Trading Strategies in Python”. It features a lot of advanced contrarian indicators and strategies with a GitHub page dedicated to the continuously updated code. If you are interested, you could buy the PDF version directly through a PayPal payment of 9.99 EUR.
Please include your email in the note before paying so that you receive it on the right address. Also, once you receive it, make sure to download it through google drive.
Creating the Brown Indicator
Magnet indicators are the bridge between contrarian and regime-detection indicators. They serve to show you how far the current market price is from implied normality. In essence, they tell you than an expected reversal move should happen and gives you the expected target (which is the normality level).
To construct the Brown indicator, follow these steps:
Calculate the maximum of the highs for a 100-period (or 200-period) lookback.
Calculate the minimum of the lows for a 100-period (or 200-period) lookback.
Calculate the average between the two previous steps.
Calculate a 20-period moving average of the last step’s results.
The following snippet shows how to code the indicator in Pine Script.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © Sofien-Kaabar
//@version=5 indicator("Brown Indicator", overlay = true)
lookback = input(defval = 200, title = 'Lookback')
max = ta.highest(high, lookback) min = ta.lowest(low, lookback)
average = (max + min) / 2 brown_indicator = ta.sma(average, 20)
plot(brown_indicator, color = color.rgb(150, 75, 0))
Check out my weekly market sentiment report to understand the current positioning and to estimate the future direction of several major markets through complex and simple models working side by side. Find out more about the report through this link:
Using the Brown Indicator
Using the Brown indicator is rather simple. The trading conditions for a are as follows:
A long signal is generated whenever the market surpasses and pulls-back to the Brown indicator.
A short signal is generated whenever the market breaks and pulls-back to the Brown indicator.
To sum up, what I am trying to do is to simply contribute to the world of objective technical analysis which is promoting more transparent techniques and strategies that need to be back-tested before being implemented. This way, technical analysis will get rid of the bad reputation of being subjective and scientifically unfounded.
I recommend you always follow the the below steps whenever you come across a trading technique or strategy:
Have a critical mindset and get rid of any emotions.
Back-test it using real life simulation and conditions.
If you find potential, try optimizing it and running a forward test.
Always include transaction costs and any slippage simulation in your tests.
Always include risk management and position sizing in your tests.
Finally, even after making sure of the above, stay careful and monitor the strategy because market dynamics may shift and make the strategy unprofitable.
For the paperback link of the book, you may use the following link: