Time Duration between Signals

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.
 

Attachments

  • ideal.png
    ideal.png
    276.2 KB · Views: 64
  • problem.png
    problem.png
    283.9 KB · Views: 65
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.

not quite sure what you are asking for
see if this is drawing yellow lines when you want ( skipping some arrows)


Code:
#minbarsbetweensignals

#httpsusethinkscript.comthreadstime-duration-between-signals.17418
#Time Duration between Signals

#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.


# 9ema crossover

# httpsusethinkscript.comthreads...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);
# =====================================


#----------------------------------------

#read chart time and convert to minutes

def chartagg = getaggregationperiod();
def chartmin = chartagg(100060);

input min_minutes_between = 15;
def barz = min_minutes_betweenchartmin;

#make a counter after the signal ( crossing)
def upcnt = if condition_up and upcnt[1] = barz then 1 else upcnt[1] + 1;
def dwncnt = if condition_dwn and dwncnt[1] = barz then 1 else dwncnt[1] + 1;

def condition_up2 = if condition_up and upcnt == 1 then 1 else 0;
def condition_dwn2 = if condition_dwn and dwncnt == 1 then 1 else 0;

#addverticalline(condition_up2 , up2, color.cyan);
addverticalline(condition_dwn2 , dwn2, color.yellow);


addchartbubble(0, low0.99,
upcnt +  upn +
dwncnt +  dwn
, color.yellow, no);
#
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
381 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top