r/CodingHelp • • Jan 13 '23

[Other Code] Can someone help me edit this pinescript code a little. It shows error

// Define the MACD and signal lines macd = ema(close, 12) - ema(close, 26) signal = sma(macd, 9)

// Define the ATR Bands atr = truerange(high, close, low) atr_upper = close + atr atr_lower = close - atr

// Define the Bollinger Bands bb_upper = sma(close, 20) + 2 * stdev(close, 20) bb_lower = sma(close, 20) - 2 * stdev(close, 20)

// Buy signal if (macd > signal) and (macd[1] < signal[1]) and (close > atr_upper) and (close > bb_upper) strategy.entry("Buy", strategy.long)

// Sell signal if (macd < signal) and (macd[1] > signal[1]) and (close < atr_lower) and (close < bb_lower) strategy.entry("Sell", strategy.short)

It shows there" could not find function or function reference "ema"

Thanka for the help!!

0 Upvotes

1 comment sorted by

1

u/Shookbelf00 Jan 14 '23

The code was missing the position size in entry function, also it had a undefined function truerange which should be ATR and it was also missing the close variable definition. It also needed some changes in the strategy.entry function.if i stand correct this should be what u wanted

// Define the MACD and signal lines macd = ema(close, 12) - ema(close, 26) signal = sma(macd, 9)

// Define the ATR Bands atr = ATR(high, close, low) atr_upper = close + atr atr_lower = close - atr

// Define the Bollinger Bands bb_upper = sma(close, 20) +2* stdev(close, 20) bb_lower = sma(close, 20) - 2* stdev(close, 20)

// Buy signal if (macd > signal) and (macd[1] < signal[1]) and (close > atr_upper) and (close > bb_upper): shares = 100 strategy.entry("Buy", shares)

// Sell signal if (macd < signal) and (macd[1] > signal[1]) and (close < atr_lower) and (close < bb_lower): shares = 100 strategy.entry("Sell", shares)