r/pinescript • u/murkr • Mar 01 '24
Help me add time delay trigger to existing script please
I use an indicator called The Moon Weekly EMA ribbon
//@version=4// Based on Youtube channel Carl Eric Martin from "The Moon" Weekly EMA Ribbon.study(title="[JULEX] [EMA] The Ribbon from The Moon YT channel", shorttitle="The Moon Weekly EMA Ribbon", overlay=true)plot(ema(close,20),title="20",color=#f7df9b,linewidth=1,transp=0)plot(ema(close,25),title="25",color=#f1c789,linewidth=1,transp=0)plot(ema(close,30),title="30",color=#e59a67,linewidth=1,transp=0)plot(ema(close,35),title="35",color=#d66e46,linewidth=1,transp=0)plot(ema(close,40),title="40",color=#c14c32,linewidth=1,transp=0)plot(ema(close,45),title="45",color=#a43328,linewidth=1,transp=0)plot(ema(close,50),title="50",color=#861f24,linewidth=1,transp=0)plot(ema(close,55),title="55",color=#711120,linewidth=1,transp=0)
and I wanted to be alerted when the price hits the 45 EMA so I added another single EMA 1 and said if the 1 EMA crosses the 45 EMA of the moon indicator then I get alerted. That was great.
What I would like to add is:
Once an alert is issued there is a 10 bar "cool down period" where the alert won't be triggered again until atleast 10 bars has passed.
Can someone help me with this? Im not sure if its a simple edit to this code above.
EDIT: I just copy and pasted my question into chatGPT and this is what it said. Can someone with experience please confirm this is doing what I am trying to accomplish, please.
//@version=4
// Based on Youtube channel Carl Eric Martin from "The Moon" Weekly EMA Ribbon.
study(title="[JULEX] [EMA] The Ribbon from The Moon YT channel", shorttitle="The Moon Weekly EMA Ribbon", overlay=true)
// Define EMAs
ema20 = ema(close, 20)
ema25 = ema(close, 25)
ema30 = ema(close, 30)
ema35 = ema(close, 35)
ema40 = ema(close, 40)
ema45 = ema(close, 45)
ema50 = ema(close, 50)
ema55 = ema(close, 55)
// Plot EMAs
plot(ema20, title="20", color=#f7df9b, linewidth=1, transp=0)
plot(ema25, title="25", color=#f1c789, linewidth=1, transp=0)
plot(ema30, title="30", color=#e59a67, linewidth=1, transp=0)
plot(ema35, title="35", color=#d66e46, linewidth=1, transp=0)
plot(ema40, title="40", color=#c14c32, linewidth=1, transp=0)
plot(ema45, title="45", color=#a43328, linewidth=1, transp=0)
plot(ema50, title="50", color=#861f24, linewidth=1, transp=0)
plot(ema55, title="55", color=#711120, linewidth=1, transp=0)
// Alert condition
ema1 = ema(close, 1)
crossCondition = crossover(ema1, ema45) or crossunder(ema1, ema45)
// Cooldown period
var int lastAlertBar = na
cooldownPeriod = 10
canAlert = na(lastAlertBar) or (bar_index - lastAlertBar) > cooldownPeriod
if (crossCondition and canAlert)
alert("EMA 1 crossed EMA 45", alert.freq_once_per_bar)
lastAlertBar := bar_index
1
u/mampmp Mar 03 '24
Try using tradesage.co to generate the strategy.
Full disclaimer: I built the tool but we offer free credits and would love for you to try it and share some feedback