kevinhng77
New member
Hello,
I've been trying to tweak this ema crossover signal so that there's a time duration in between each signal but I'm having a little bit of trouble. Ideally I'd want it to signal after a set x amount of time.
Original Code:
# 9ema crossover
# https://usethinkscript.com/threads/...andle-or-something-similar.13230/#post-111632
input ShowTodayOnly = yes;
def Today = if GetDay() == GetLastDay() then 1 else 0;
def marketHours = if SecondsTillTime(700) <= 0 and
SecondsTillTime(1100) > 0 then 1 else 0;
def na = double.nan;
input avg_type = AverageType.EXPONENTIAL;
input avg_len = 7;
input price = close;
input displace = 0;
def avg = MovingAverage(avg_type, price[-displace], avg_len);
plot zavg = avg;
#zavg.SetDefaultColor(GetColor(2));
input sequential_bars = 1;
#addlabel(1, " ", color.black);
#addlabel(1, "sequential bars " + sequential_bars, color.yellow);
def close_above = close > avg;
def condition_up = (getvalue(!close_above, sequential_bars) and sum(close_above, sequential_bars) == sequential_bars);
def close_below = close < avg;
def condition_dwn = (getvalue(!close_below, sequential_bars) and sum(close_below, sequential_bars) == sequential_bars);
def vert = 0.004;
#plot zup = if marketHours and condition_up then (low*(1-vert)) else na;
#zup.SetDefaultColor(Color.UPTICK);
#zup.SetDefaultColor(Color.cyan);
#zup.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
#zup.setlineweight(3);
#def lastcrossup = if lastcrossup[1] > 20 and condition_dwn[1] then 1 else lastcrossup[1] +1;
plot zdwn = if showtodayOnly and Today and marketHours
#and lastcrossup[1] > 20
and condition_dwn > condition_dwn[1] then (high*(1+vert)) else na;
zdwn.SetDefaultColor(Color.cyan);
#zdwn.SetDefaultColor(Color.yellow);
zdwn.SetPaintingStrategy(PaintingStrategy.Boolean_Arrow_up);
zdwn.setlineweight(3);
#assignpriceColor (if zdwn then color.red else color.current);
#plot closebelow = if close is less than low then 1 else na;
#closebelow.setPaintingStrategy(paintingStrategy.ARROW_UP);
# =====================================
# alerts , sounds
# alert(condition, text, alert type, sound);
# Sound.Ding, higher , up sound
# Sound.Bell, lower , down sound
#def a = no;
alert(zdwn, "ema crossover" ,alert.BAR, sound.DING);
#alert(condition_dwn, "crossed down" ,alert.BAR, sound.bell);
# =====================================
TOS Sharable Links
Here is the shareable link to the original ema crossover script.
http://tos.mx/!CianoLdj
Here is the shareable link to the tweak that I tried. The problem is that it skips over signals if it's too early and the counter hasn't reached 15 minutes yet.
Ideally I'd want it to only start AFTER the first signal has triggered.
http://tos.mx/!0fWc0XAq
The first picture attached is the regular ema crossover script with the ideal time delays in between each signal that I would like. The second picture is the current tweak that I've tried. The problem is that it skips over the first signal and consequently skips over some signals that I would like. For reference, the ticker below is $AWIN 10/02/23 during pre-market.
I've been trying to tweak this ema crossover signal so that there's a time duration in between each signal but I'm having a little bit of trouble. Ideally I'd want it to signal after a set x amount of time.
Original Code:
# 9ema crossover
# https://usethinkscript.com/threads/...andle-or-something-similar.13230/#post-111632
input ShowTodayOnly = yes;
def Today = if GetDay() == GetLastDay() then 1 else 0;
def marketHours = if SecondsTillTime(700) <= 0 and
SecondsTillTime(1100) > 0 then 1 else 0;
def na = double.nan;
input avg_type = AverageType.EXPONENTIAL;
input avg_len = 7;
input price = close;
input displace = 0;
def avg = MovingAverage(avg_type, price[-displace], avg_len);
plot zavg = avg;
#zavg.SetDefaultColor(GetColor(2));
input sequential_bars = 1;
#addlabel(1, " ", color.black);
#addlabel(1, "sequential bars " + sequential_bars, color.yellow);
def close_above = close > avg;
def condition_up = (getvalue(!close_above, sequential_bars) and sum(close_above, sequential_bars) == sequential_bars);
def close_below = close < avg;
def condition_dwn = (getvalue(!close_below, sequential_bars) and sum(close_below, sequential_bars) == sequential_bars);
def vert = 0.004;
#plot zup = if marketHours and condition_up then (low*(1-vert)) else na;
#zup.SetDefaultColor(Color.UPTICK);
#zup.SetDefaultColor(Color.cyan);
#zup.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
#zup.setlineweight(3);
#def lastcrossup = if lastcrossup[1] > 20 and condition_dwn[1] then 1 else lastcrossup[1] +1;
plot zdwn = if showtodayOnly and Today and marketHours
#and lastcrossup[1] > 20
and condition_dwn > condition_dwn[1] then (high*(1+vert)) else na;
zdwn.SetDefaultColor(Color.cyan);
#zdwn.SetDefaultColor(Color.yellow);
zdwn.SetPaintingStrategy(PaintingStrategy.Boolean_Arrow_up);
zdwn.setlineweight(3);
#assignpriceColor (if zdwn then color.red else color.current);
#plot closebelow = if close is less than low then 1 else na;
#closebelow.setPaintingStrategy(paintingStrategy.ARROW_UP);
# =====================================
# alerts , sounds
# alert(condition, text, alert type, sound);
# Sound.Ding, higher , up sound
# Sound.Bell, lower , down sound
#def a = no;
alert(zdwn, "ema crossover" ,alert.BAR, sound.DING);
#alert(condition_dwn, "crossed down" ,alert.BAR, sound.bell);
# =====================================
TOS Sharable Links
Here is the shareable link to the original ema crossover script.
http://tos.mx/!CianoLdj
Here is the shareable link to the tweak that I tried. The problem is that it skips over signals if it's too early and the counter hasn't reached 15 minutes yet.
Ideally I'd want it to only start AFTER the first signal has triggered.
http://tos.mx/!0fWc0XAq
The first picture attached is the regular ema crossover script with the ideal time delays in between each signal that I would like. The second picture is the current tweak that I've tried. The problem is that it skips over the first signal and consequently skips over some signals that I would like. For reference, the ticker below is $AWIN 10/02/23 during pre-market.