Scanning For Filter Between 30 and 300 bars ago

TosRox

New member
VIP
Hi ThinkScripters. Have a thinkscript question that maybe simple for somebody to respond to. In Stock Hacker I am looking for an event that occured "between a RANGE of bars" ago. In this case I don't want a moving average cross-over to have occured between 300 and 30 bars ago.
The thinkScript in stock hacker that I used which it will not accept is:

MovingAvgCrossover("length1" = 50, "length2" = 200) is false within between 300 and 30 bars.

So the question is what is the correct thinkscript for a within "RANGE of bars" ago.

Appreciate the assistance!
 
Solution
Hi ThinkScripters. Have a thinkscript question that maybe simple for somebody to respond to. In Stock Hacker I am looking for an event that occured "between a RANGE of bars" ago. In this case I don't want a moving average cross-over to have occured between 300 and 30 bars ago.
The thinkScript in stock hacker that I used which it will not accept is:

MovingAvgCrossover("length1" = 50, "length2" = 200) is false within between 300 and 30 bars.

So the question is what is the correct thinkscript for a within "RANGE of bars" ago.

Appreciate the assistance!


here is a lower study to experiment with
i disabled MovingAvgCrossover() as my signal didn't seem right.
i added MovingAverage()'s and looked for 'crosses' and...
Hi ThinkScripters. Have a thinkscript question that maybe simple for somebody to respond to. In Stock Hacker I am looking for an event that occured "between a RANGE of bars" ago. In this case I don't want a moving average cross-over to have occured between 300 and 30 bars ago.
The thinkScript in stock hacker that I used which it will not accept is:

MovingAvgCrossover("length1" = 50, "length2" = 200) is false within between 300 and 30 bars.

So the question is what is the correct thinkscript for a within "RANGE of bars" ago.

Appreciate the assistance!


here is a lower study to experiment with
i disabled MovingAvgCrossover() as my signal didn't seem right.
i added MovingAverage()'s and looked for 'crosses' and that worked.

this can take 10 seconds to draw the chart, so not sure if it will work in a scan.
not tested in a scan.

Code:
#crossover_in_past

#https://usethinkscript.com/threads/scanning-for-filter-between-30-and-300-bars-ago.16094/
#Scanning For Filter Between 30 and 300 bars ago
#TosRox  7/16

#Hi ThinkScripters. Have a thinkscript question that maybe simple for somebody to respond to. In Stock Hacker I am looking for an event that occured "between a RANGE of bars" ago. In this case I don't want a moving average cross-over to have occured between 300 and 30 bars ago.

#The thinkScript in stock hacker that I used which it will not accept is:

#MovingAvgCrossover("length1" = 50, "length2" = 200) is false within between 300 and 30 bars.

#So the question is what is the correct thinkscript for a within "RANGE of bars" ago.

declare lower;

def na = Double.NaN;
def bn = BarNumber();

def price = close;
input avg1_len = 50;
input avg1_type = AverageType.EXPONENTIAL;
def ma1 = MovingAverage(avg1_type, price, avg1_len);

input avg2_len = 200;
input avg2_type = AverageType.EXPONENTIAL;
def ma2 = MovingAverage(avg2_type, price, avg2_len);

#def x = MovingAvgCrossover(price = close, length1 = avg1_len, length2 = avg2_len);
def x2 = ma1 crosses ma2;

input bars_back_start = 30;
input bars_back_stop = 300;

def rng = bars_back_stop - bars_back_start;

#def xcnt = sum(x[bars_back_start], rng);
def xcnt = sum(x2[bars_back_start], rng);

plot z = if xcnt == 0 then 1 else 0;


#----------------------
#input show_lines = yes;
#plot z1 = if show_lines then ma1 else na;
#z1.SetDefaultColor(GetColor(1));
#z1.HideBubble();

#plot z2 = if show_lines then ma2 else na;
#z2.SetDefaultColor(GetColor(2));
#z2.HideBubble();

#

settings of 10 and 20 for bars back
vRmS2Yn.jpg


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


upper for testing


Code:
# ma12_cross

def na = double.nan;
def bn = barnumber();

def price = close;

input ma1_len = 50;
def len1 = if ma1_len == 0 then 1 else ma1_len;
input ma1_type =  AverageType.EXPONENTIAL;
def ma1 = MovingAverage(ma1_type, price, len1);

input ma2_len = 200;
def len2 = if ma2_len == 0 then 1 else ma2_len;
input ma2_type =  AverageType.EXPONENTIAL;
def ma2 = Movingaverage(ma2_type, price, len2);

input show_lines = yes;
plot z1 = if show_lines and len1 > 1 then ma1 else na;
z1.setdefaultcolor(getcolor(1));
#z1.setlineweight(1);
z1.hidebubble();

plot z2 = if show_lines and len2 > 1 then ma2 else na;
z2.setdefaultcolor(getcolor(2));
#z2.setlineweight(1);
z2.hidebubble();
#
 
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
524 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