I'm having an issue with a small portion of this script. Can anyone help me with it? Providing a snapshot of my screen as to what i'm being prompted with...
Code:
declare upper;
# Inputs
input fastSMA_length = 50; # Fast moving average (50-period)
input slowSMA_length = 200; # Slow moving average (200-period)
input rsi_length = 14; # RSI period (14-period)
input macd_shortLength = 12; # MACD short period (12) -- Updated to 12
input macd_longLength = 26; # MACD long period (26) -- Updated to 26
input macd_signalLength = 9; # MACD signal period (9) -- Updated to 9
input volumeLength = 20; # Volume average period (20)
input overbought = 70; # Overbought level for RSI (70)
input oversold = 30; # Oversold level for RSI (30)
input showSignals = yes; # Toggle to show signals
# Calculate Moving Averages
def fastSMA = Average(close, fastSMA_length); # Fast SMA (50-period)
def slowSMA = Average(close, slowSMA_length); # Slow SMA (200-period)
# Calculate RSI
def rsi = RSI(rsi_length);
# Calculate MACD
def macdValue = MACD(fastLength = macd_shortLength, slowLength = macd_longLength, MACDLength = macd_signalLength).MACD;
def signalLine = MACD(fastLength = macd_shortLength, slowLength = macd_longLength, MACDLength = macd_signalLength).Signal;
# Calculate Volume
def avgVolume = Average(volume, volumeLength);
def highVolume = volume > avgVolume; # High volume signal
# Bullish and Bearish Engulfing Candlestick Patterns (simplified)
def bullishEngulfing = close > open and close[1] < open[1] and close > open[1] and open < close[1];
def bearishEngulfing = open > close and open[1] < close[1] and open > close[1] and close < open[1];
# Buy Signal Logic
def buySignal = (fastSMA crosses above slowSMA) and (rsi < oversold) and (macdValue crosses above signalLine) and highVolume and bullishEngulfing;
# Sell Signal Logic
def sellSignal = (fastSMA crosses below slowSMA) and (rsi > overbought) and (macdValue crosses below signalLine) and highVolume and bearishEngulfing;
# Plot Buy and Sell Signals
plot BuySignalPlot = if showSignals and buySignal then low - 0.5 else Double.NaN;
BuySignalPlot.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
BuySignalPlot.SetDefaultColor(Color.GREEN);
BuySignalPlot.SetLineWeight(3);
plot SellSignalPlot = if showSignals and sellSignal then high + 0.5 else Double.NaN;
SellSignalPlot.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
SellSignalPlot.SetDefaultColor(Color.RED);
SellSignalPlot.SetLineWeight(3);
Last edited by a moderator: