EveryDayBetter
Pine Script Master
Pine Script Master
Posts: 27
Joined: February 16th, 2022

How is it possible to upgrade this script to version 5?

The indicator the the Elder Impulse System. The version it is not known.

Code: Select all

study(title="Elder Impulse System", shorttitle="Elder Impulse", overlay=true)

source = close

// MACD Options
macd_length_fast   = input(defval=12, minval=1, title="MACD Fast Length")
macd_length_slow   = input(defval=26, minval=1, title="MACD Slow Length")
macd_length_signal = input(defval=9,  minval=1, title="MACD Signal Length")
// Calculate MACD
macd_ma_fast       = ema(source, macd_length_fast)
macd_ma_slow       = ema(source, macd_length_slow)
macd               = macd_ma_fast - macd_ma_slow
macd_signal        = ema(macd, macd_length_signal)
macd_histogram     = macd - macd_signal

// EMA Option
ema_length         = input(defval=13, minval=1, title="EMA Length")
// Calculate EMA
ema                = ema(source, ema_length)

// Calculate Elder Impulse
elder_bulls        = (ema[0] > ema[1]) and (macd_histogram[0] > macd_histogram[1])
elder_bears        = (ema[0] < ema[1]) and (macd_histogram[0] < macd_histogram[1])
elder_color        = elder_bulls
                     ? green //  If Bulls Control Trend and Momentum
                     : elder_bears
                       ? red //  If Bears Control Trend and Mementum
                       : blue // If Neither Bulls or Bears Control the Market

barcolor(elder_color)
I have done some changes, the new version:

Code: Select all

//@version=5
indicator(title="Elder Impulse System", shorttitle="Elder Impulse", overlay=true)

source = close

// MACD Options
macd_length_fast   = input(defval=12, minval=1, title="MACD Fast Length")
macd_length_slow   = input(defval=26, minval=1, title="MACD Slow Length")
macd_length_signal = input(defval=9,  minval=1, title="MACD Signal Length")
// Calculate MACD
macd_ma_fast       = ta.ema(source, macd_length_fast)
macd_ma_slow       = ta.ema(source, macd_length_slow)
macd               = macd_ma_fast - macd_ma_slow
macd_signal        = ta.ema(macd, macd_length_signal)
macd_histogram     = macd - macd_signal

// EMA Option
ema_length         = input(defval=13, minval=1, title="EMA Length")
// Calculate EMA
ema                = ta.ema(source, ema_length)

// Calculate Elder Impulse
elder_bulls        = (ema[0] > ema[1]) and (macd_histogram[0] > macd_histogram[1])
elder_bears        = (ema[0] < ema[1]) and (macd_histogram[0] < macd_histogram[1])
elder_color        = elder_bulls
                     ? green //  If Bulls Control Trend and Momentum
                     : elder_bears
                       ? red //  If Bears Control Trend and Mementum
                       : blue // If Neither Bulls or Bears Control the Market

barcolor(elder_color)
But it comes the warning:

line 25: Mismatched input 'end of line without line continuation' expecting ':'.

I don't know how to handle this.
How is it possible to upgrade this script to version 5?

processingclouds
Pine Script Master
Pine Script Master
Posts: 115
Joined: January 30th, 2022

Re: How is it possible to upgrade this script to version 5?

Here is the corrected working conversion to v5:

Code: Select all

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © processingclouds

//@version=5
indicator("Elder Impulse System", "Elder Impulse", overlay=true)

source = close

// MACD Options
macd_length_fast   = input.int(defval=12, minval=1, title="MACD Fast Length")
macd_length_slow   = input.int(defval=26, minval=1, title="MACD Slow Length")
macd_length_signal = input.int(defval=9,  minval=1, title="MACD Signal Length")
// Calculate MACD
macd_ma_fast       = ta.ema(source, macd_length_fast)
macd_ma_slow       = ta.ema(source, macd_length_slow)
macd               = macd_ma_fast - macd_ma_slow
macd_signal        = ta.ema(macd, macd_length_signal)
macd_histogram     = macd - macd_signal

// EMA Option
ema_length         = input.int(defval=13, minval=1, title="EMA Length")
// Calculate EMA
ema                = ta.ema(source, ema_length)

// Calculate Elder Impulse
elder_bulls        = (ema[0] > ema[1]) and (macd_histogram[0] > macd_histogram[1])
elder_bears        = (ema[0] < ema[1]) and (macd_histogram[0] < macd_histogram[1])
// Green = Bulls Control Trend and Momentum
// Red   = Bears Control Trend and Mementum
// Blue  = Neither Bulls or Bears Control the Market
elder_color        = elder_bulls ? color.green 
                         : elder_bears ? color.red 
                             : color.blue 

barcolor(elder_color)

EveryDayBetter
Pine Script Master
Pine Script Master
Posts: 27
Joined: February 16th, 2022

Re: How is it possible to upgrade this script to version 5?

Many thanks to you.

Return to “Pine Script Q&A”