How do I set my trendline color and plot based on an if statement i.e. if stock data is > 1 year then use trendline 1 else use trendline method 2:
trend_1 = sma(close, 15)
trend_2 = sma(close, 30)
bearish = true
for i = 0 to trendConfirmationLength - 1
bearish := bearish and (close[i] < trend[i])
bullish = not bearish
// Set the color of the plot based on whether we are bullish (green) or not (red)
c = bullish ? color.green : color.red
// Plot the trend line
trend =
if (len(close) > 252)
trend_1
if (len(close) < 252)
trend_2
trend_plot = plot(trend, title='Trend', color = c)
Thanks
Aucun commentaire:
Enregistrer un commentaire