BreezeTrades808

Two MAs (nextSignals)

Hi folks, just some quick work inspired by ThinkScript code from @stephenharlinmd (the Doc).

This indicator seems to be intended for lower timeframes (3 min was used for example), and indicates long and short opportunities based on crossovers of the two lines.

The slow reference line is an EMA20. The fast line is referred to as an "Instantaneous Moving Average", which attempts to use OHLC4 values to create a realtime reference line for price instead of a lagging average. Its calculation is as follows:

1. The OHLC4 value is calculated by taking the average of the open, high, low, and close prices for each bar.

2. The ta.highest function is used to find the highest value of OHLC4 over the last 5 bars, and this value is stored in the ON variable.

3. The ta.lowest function is used to find the lowest value of ON over the last 5 bars, and this value is stored in the O1 variable.

4. The for loop is used to find the index of O1 in the P data series, which represents the OHLC4 values over the last 6 bars. If the value at the current index is equal to O1, and O1Loc has not already been set, then O1Loc is set to the current index.

5. The O2 variable is initialized to ON, and another for loop is used to find the index of the second lowest value of OHLC4 over the last 6 bars, which is not at the same index as O1. If the value at the current index is equal to O2, and O2Loc has not already been set, and the current index is not equal to O1Loc, then O2Loc is set to the current index.

6. The O3 variable is initialized to ON, and another for loop is used to find the minimum value of OHLC4 over the last 6 bars, excluding the values at the indices of O1 and O2. If the current index is not equal to O1Loc or O2Loc, then the minimum of the current value of O3 and the value at the current index of P is stored in O3.

7. Finally, the "IMA" variable is set to the value of O3, which represents the "IMA" over the last 6 bars.

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?