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).
If you are interested by trend following indicators and strategies then my book could interest you. It features advanced trend-following indicators and strategies with a GitHub page dedicated to the continuously updated code. Also, this book features the original colors after having optimized for printing costs. If you feel that this interests you, feel free to visit the below Amazon link, or if you prefer to buy the PDF version, you could contact me on LinkedIn.
Trend Following Strategies in Python: How to Use Indicators to Follow the Trend.
Amazon.com: Trend Following Strategies in Python: How to Use Indicators to Follow the Trend.: 9798756939620: Kaabar…www.amazon.com
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))
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.
If you want to see how to create all sorts of algorithms yourself, feel free to check out Lumiwealth. From algorithmic trading to blockchain and machine learning, they have hands-on detailed courses that I highly recommend.
Learn Algorithmic Trading with Python Lumiwealth
Learn how to create your own trading algorithms for stocks, options, crypto and more from the experts at Lumiwealth. Click to learn more
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.