简体   繁体   中英

Adding Alert to EMA Cloud Fill PineScript Code Based on Color Change

I am trying to add a code to a script I found to simply add alerts on the ema cloud based on color change. I tried to add.

This is part of the script:

///////////////plot MAs
plot_ma1 = plot(MA1, color= dynamic ?  dynColor: color.green , linewidth=1, title = 
"MA1")
plot_ma2 = plot(MA2, color= dynamic ?  dynColor: color.red , linewidth=1, title = 
"MA2")
plot_ma3 = plot(MA3, color= dynamic ?  dynColor: color.yellow, linewidth=1, title = 
"MA3")
plot_ma4 = plot(MA4, color= dynamic ?  dynColor: color.white, linewidth=1, title = 
"MA4")
// Trend Fill
rsi1 =ta.rsi(close,14)
smmaLen = 50
//input(50, minval=1, title="SMMA Length", group = "Smoothed MA")
smmaSrc = rsi1
smma = 0.0
smma := na(smma[1]) ? ta.sma(smmaSrc, smmaLen) : (smma[1] * (smmaLen - 1) + smmaSrc) / 
smmaLen


trendFill = input(title="Show Trend Fill",  defval=true, group = "Smoothed MA Inputs") 
transparencyValue= trendFill ? math.abs(rsi1-smma): na

bColor = if rsi1  > smma 
color.from_gradient(transparencyValue,0, 50, color.new(color.lime, 80), color.lime)
else 
color.from_gradient(transparencyValue,0, 50, color.new(color.red, 80),color.red)
fill(plot_ma1,plot_ma2,bColor,title="RSI Fill")



// End ###

Then I tried to add this to create the alert:

    // ### Cloud Color Change
longS = input.bool(title="Show Long Cloud Signal",  defval=true, group = "Plot Mas")
shorS = input.bool(title="Show Shor Cloud Signal",  defval=true, group = "Plot Mas")

longSig =  close[3] > open[3] and close[2] > open[2] and close[1] > open[1] and close 
< open[1]
shortSig =  close[3] < open[3] and close[2] < open[2] and close[1] < open[1] and close 
> open[1]

plotshape(bullS ? bullSig : na, style=shape.triangleup, color=color.green, 
location=location.belowbar, size = size.small,  title="Cloud Color Change Up")
plotshape(bearS ? bearSig : na, style=shape.triangledown, color=color.red, 
location=location.abovebar, size = size.small,   title="Cloud Color Change Down")


alertcondition(longSig, title="Cloud Long", message="[CurrencyPair] [TimeFrame], Plot 
Mas")
alertcondition(shorSig, title="Cloud Short", message="[CurrencyPair] [TimeFrame], 
PlotMas")

// End ###

This does not work because what I am trying to do is use the color change from the trendfill cloud to set the alert. What should I do in this instance?

Any help is greatly appreciated.

You're trying to get an alert whenever the color in that gradiant gets updated even slightly?

Below variable will become true whenever there will be a change in color

colorchange = bColor!=bColor[1]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM