TradingView
ugurvu
Mar 10, 2021 1:16 PM

Linear Regression Candles 

EUR/USDOANDA

Description

There are many linear regression indicators out there, most of them draw lines or channels, but this one actually draws a chart.
Comments
jeffreyl166
I think its a great tool but i got one request though.. i would like to set an alert if the candle color changes. can you add that please?
MaximusGains
@jeffreyl166, Use this:
// Define a variable to store the previous candle color
prev_color = color.red

// Check if current candle color is green
r = bopen < bclose
if r
// Check if previous candle color was red
if prev_color == color.red
// Trigger an alert
alertcondition(title = "Candle color changed", message = "Candle color changed from red to green")
// Update previous candle color variable
prev_color := color.green
else
// Check if previous candle color was green
if prev_color == color.green
// Trigger an alert
alertcondition(title = "Candle color changed", message = "Candle color changed from green to red")
// Update previous candle color variable
prev_color := color.red

// Plot candles
plotcandle(r ? bopen : na, r ? bhigh : na, r ? blow: na, r ? bclose : na, title="LinReg Candles", color= color.green, wickcolor=color.green, bordercolor=color.green, editable= true)
plotcandle(r ? na : bopen, r ? na : bhigh, r ? na : blow, r ? na : bclose, title="LinReg Candles", color=color.red, wickcolor=color.red, bordercolor=color.red, editable= true)
saKe_Bosna
@MaximusGains, where can i dm you?
popularPerson397610
@MaximumGains, I also really want to talk with you please via dm 🙏
ItsmeWahchek
@MaximusGains, I am just learning PineScript, I am using the linear regression candles, I tried to implement the candle color change alerts script but it rejected with the following errors, "r is already assigned" and "no alert condition assigned"
Please offer suggestions on how to properly implement this candle color change into the linear regression candle indicator.
Thank you.
apbreaux
@MaximusGains, I am unable to get this alert to work. Has anyone figured this out? Many thanks.
apbreaux
@apbreaux, To anyone interested, the closest thing I've gotten to work for alerts for this indicator:
- get Chandelier Exit by everget, labeled as CE on chart
- change: ATR Period: 1, ATR Multiplier: 0.9
- Create an Alert: CE (1, 0.9), CE Direction Change
It's not perfect, but pretty close. Will update if anything more accurate is discovered/created.
Gabbus
@apbreaux, Good evening and thank you for the CE alert. I appreciate !!
MaximusGains
@apbreaux, yes it's working
More