Page 1 of 1

Else If Help

Posted: Tue Dec 14, 2021 11:16 pm
by jamesvv
Trying to figure out how to turn off the sell label when price is above the 200D MA
as well as turn off the buy label if price is below the 200D ma

indicator("Redlight-Greenlight", overlay=true)


GreenLightMA = ta.sma(close, 7)
RedLightEMA = ta.ema(close, 47)
BullMarket = ta.sma(close, 200)

plot(GreenLightMA, color = color.green)
plot(RedLightEMA, color = color.red)
plot(BullMarket, color = color.orange)


buy = ta.crossover(GreenLightMA, RedLightEMA)
sell = ta.crossover(RedLightEMA, GreenLightMA)

if (buy)
lbl = label.new(bar_index, low, "Buy")
label.set_color(lbl, color.green)
label.set_yloc(lbl, yloc.belowbar)
label.set_style(lbl, label.style_label_up)

if (sell)
lbl = label.new(bar_index, low, "Sell")
label.set_color(lbl, color.red)
label.set_yloc(lbl, yloc.abovebar)
label.set_style(lbl, label.style_label_down)

Re: Else If Help

Posted: Thu Dec 16, 2021 12:26 am
by dusktrader
Hi James, I think this is what you want here. Just add another condition to your IF statements:

Code: Select all

if buy and close > BullMarket
    lbl = label.new(bar_index, low, "Buy")
    label.set_color(lbl, color.green)
    label.set_yloc(lbl, yloc.belowbar)
    label.set_style(lbl, label.style_label_up)

if sell and close < BullMarket
    lbl = label.new(bar_index, low, "Sell")
    label.set_color(lbl, color.red)
    label.set_yloc(lbl, yloc.abovebar)
    label.set_style(lbl, label.style_label_down)