Can anybody help me to fix the following code? I am NOT getting labels such as "Possible Short" and "Short Confirmed", The code is only showing "Bearish Engulfing", Shooting Star", and "Bullish Engulfing",
Here is the code:
Here is the code:
Code:
# Dynamic Short Trigger Strategy with Multi-Criteria Monitoring
#============================================================================
# USER INPUTS
#============================================================================
input atrLength = 14;
input vwapMultiplier = 1.5;
input macdNormLength = 20;
input macdDeltaThresholdUser = 0.5;
input rsiLength = 14;
input rsiOverbought = 70;
input showBearishPatterns = yes;
input showBullishPatterns = yes;
#============================================================================
# INDICATOR CALCULATIONS
#============================================================================
def atr = Average(TrueRange(high, close, low), atrLength);
def vwap = reference VWAP();
# Bollinger Bands
def bbLength = 20;
def bbMiddle = Average(close, bbLength);
def bbStdDev = StDev(close, bbLength);
def bbUpper = bbMiddle + bbStdDev * 2;
def bbLower = bbMiddle - bbStdDev * 2;
# RSI
def rsi = RSI("length"=14, "price"=close);
# MACD Normalization
def macdLine = MACD(12, 26, 9)."Value";
def signalLine = MACD(12, 26, 9)."Avg";
def macdDelta = macdLine - signalLine;
def stdevClose = StDev(close, macdNormLength);
def macdDeltaNormalized = if stdevClose == 0 then macdDelta else macdDelta / stdevClose;
# EMAs
def ema5 = ExpAverage(close, 5);
def ema9 = ExpAverage(close, 9);
def ema100 = ExpAverage(close, 100);
#============================================================================
# SHORT SIGNAL CONDITIONS
#============================================================================
def condition1Triggered = close > bbUpper and rsi > rsiOverbought and close > vwap * vwapMultiplier and macdDeltaNormalized > macdDeltaThresholdUser;
def priceBelowEma5Triggered = condition1Triggered and close < ema5;
def shortSignalConfirmed = priceBelowEma5Triggered and ema5 crosses below ema9;
#============================================================================
# CANDLESTICK PATTERNS
#============================================================================
def bodySize = AbsValue(close - open);
def upperShadow = high - Max(close, open);
def lowerShadow = Min(close, open) - low;
# Bearish Patterns
def bearishEngulfing = open[1] < close[1] and open > close and close < open[1] and open > close[1];
def shootingStar = bodySize <= (high - low) * 0.3 and upperShadow >= 2 * bodySize and lowerShadow <= bodySize;
# Bullish Patterns
def bullishEngulfing = open[1] > close[1] and close > open and close > open[1] and open < close[1];
#============================================================================
# PLOT INDICATORS
#============================================================================
plot UpperBB = bbUpper;
UpperBB.SetDefaultColor(Color.RED);
plot MiddleBB = bbMiddle;
MiddleBB.SetDefaultColor(Color.BLUE);
plot LowerBB = bbLower;
LowerBB.SetDefaultColor(Color.GREEN);
plot EMA51 = ema5;
EMA51.SetDefaultColor(Color.ORANGE);
plot EMA91 = ema9;
EMA91.SetDefaultColor(Color.YELLOW);
plot EMA1001 = ema100;
EMA1001.SetDefaultColor(Color.WHITE);
plot VWAPLine = vwap;
VWAPLine.SetDefaultColor(Color.CYAN);
#============================================================================
# STRATEGY ENTRY AND EXIT
#============================================================================
AddVerticalLine(condition1Triggered, "Possible Short", Color.ORANGE);
AddVerticalLine(priceBelowEma5Triggered, "Price < EMA5", Color.YELLOW);
AddVerticalLine(shortSignalConfirmed, "Short Confirmed", Color.RED);
# Highlight bearish patterns
AddVerticalLine(showBearishPatterns and bearishEngulfing, "Bearish Engulfing", Color.RED);
AddVerticalLine(showBearishPatterns and shootingStar, "Shooting Star", Color.RED);
# Highlight bullish patterns
AddVerticalLine(showBullishPatterns and bullishEngulfing, "Bullish Engulfing", Color.GREEN);
Last edited by a moderator: