Condition after a signal?

Antares66

Member
Is it possible to scan for conditions after a signal occured in a 2hour time frame?
For example: I want to find stocks which gain 3% on one of the next three 2hour bars
after a crossover occured.
"close crosses above expAverage(close,21)" would be the signal.
After this signal occured the stock should gain 3% on one of the next three 2hour bars.
Don´t know how to code this.
Thanks
 
Solution
Is it possible to scan for conditions after a signal occured in a 2hour time frame?
For example: I want to find stocks which gain 3% on one of the next three 2hour bars
after a crossover occured.
"close crosses above expAverage(close,21)" would be the signal.
After this signal occured the stock should gain 3% on one of the next three 2hour bars.
Don´t know how to code this.
Thanks


i made and tested the upper study. then copied it and removed the plots, to make the lower/scan study.

----------------------------------------
i didn't test the lower version in a scanner. (i don't use the scanner)
i made a lower study and compared it to the upper version. the pulses matched up to the green arrows.

lower/scan study

Ruby:
#...
Is it possible to scan for conditions after a signal occured in a 2hour time frame?
For example: I want to find stocks which gain 3% on one of the next three 2hour bars
after a crossover occured.
"close crosses above expAverage(close,21)" would be the signal.
After this signal occured the stock should gain 3% on one of the next three 2hour bars.
Don´t know how to code this.
Thanks


i made and tested the upper study. then copied it and removed the plots, to make the lower/scan study.

----------------------------------------
i didn't test the lower version in a scanner. (i don't use the scanner)
i made a lower study and compared it to the upper version. the pulses matched up to the green arrows.

lower/scan study

Ruby:
# lower_cross_gain3per_0

# look for an ema cross over,
# then a gain 3% on one of the next three bars

declare lower;
def na = double.nan;

input avg1len = 21;
input avg1type =  AverageType.EXPONENTIAL;
def avg1 = MovingAverage(avg1type, close, avg1len);

def up = close > open;

input gain_percent = 3.0;
input gain_bars_back = 3;
def iscross = if close crosses above avg1 then 1 else 0;

def diff = high - low;
#def gainper = if up then round(100*diff/low,1) else na;
# chg to 0 for lower/scanner
def gainper = if up then round(100*diff/low,1) else 0;

def isgain = if gainper >= gain_percent then 1 else 0;

def goff = GetMaxValueOffset(iscross, gain_bars_back + 1);
def gain_en = if goff > 0 and goff <= gain_bars_back then 1 else 0;

def iscross_gain = if sum(iscross[1],gain_bars_back) > 0 and isgain then 1 else 0;

# output for scanner
plot zcg = iscross_gain;
#


lower study, showing pulses when conditions are true
S1Vs4xY.jpg


---------------------------------------------

upper study
test with MRNA 2hr 90Day


Ruby:
# upper_cross_gain3per_0

# look for an ema cross over,
# then a gain 3% on one of the next three bars

def na = double.nan;

input avg1len = 21;
input avg1type =  AverageType.EXPONENTIAL;
def avg1 = MovingAverage(avg1type, close, avg1len);

def up = close > open;

input gain_percent = 3.0;
input gain_bars_back = 3;
def iscross = if close crosses above avg1 then 1 else 0;

def diff = high - low;
def gainper = if up then round(100*diff/low,1) else na;

def isgain = if gainper >= gain_percent then 1 else 0;

def goff = GetMaxValueOffset(iscross, gain_bars_back + 1);
def gain_en = if goff > 0 and goff <= gain_bars_back then 1 else 0;

def iscross_gain = if sum(iscross[1],gain_bars_back) > 0 and isgain then 1 else 0;

# output for scanner
#plot zcg = iscross_gain;


# ------------------------------------------
# upper chart code.  delete code below for a scanner

input show_average_line = yes;
plot za = if show_average_line then avg1 else na;
za.SetDefaultColor(Color.yellow);
za.hidebubble();

input show_wedge_on_cross_up = yes;
# wedge on crossup
plot zx = if show_wedge_on_cross_up and iscross then 1 else na;
zx.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_up);
zx.SetDefaultColor(Color.cyan);
# zx.setlineweight(1);
zx.hidebubble();

input show_arrow_on_gain = yes;
plot zg = if show_arrow_on_gain and iscross_gain then low*0.995 else na;
zg.SetPaintingStrategy(PaintingStrategy.arrow_up);
zg.SetDefaultColor(Color.green);
zg.setlineweight(3);
zg.hidebubble();

input show_percent_gain_on_all = no;
input show_percent_on_gain = yes;
plot zp = if (show_percent_on_gain and iscross_gain) or show_percent_gain_on_all then gainper else na;
zp.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
zp.AssignValueColor(if isgain then Color.green else Color.gray);
zp.hidebubble();

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

input test1_bubbles = no;
addchartbubble(test1_bubbles, low*0.98,
iscross + "\n" +
gainper + " %\n" +
isgain + " is\n" +
goff + " off\n" +
gain_en + " en\n"
, color.yellow, no);

#

cyan wedge shows a crossing
green arrows show that a minimum gain was met (3%), within 3 bars of the crossing.
numbers above the candles are the % gain, low to high.
3JQ9YKa.jpg
 
Solution

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
569 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