Checking for two conditions sequentially in the future

Howser

New member
Hi
I am writing an indicator that needs to:
  1. Look for condition 1 over the next 10 bars (Have set up working Fold to do this). This returns the bar number of where Condition 1 is met.
  2. I then want to look for Condition 2 (which my second fold works fine for). But I only want to start looking for Condition 2 after the bar where Condition 1 was met.
My first fold tells me the number of the bar where Condition 1 is met but it seems not to be an integer output from Fold 1 so Fold 2 rejects it as an indexing start point.(Folding:Integeer "to" is expected:NaN)

Any ideas please?
Is there a way to convert Fold 1 output to an integer?
Thanks a lot
 
Hi
I am writing an indicator that needs to:
  1. Look for condition 1 over the next 10 bars (Have set up working Fold to do this). This returns the bar number of where Condition 1 is met.
  2. I then want to look for Condition 2 (which my second fold works fine for). But I only want to start looking for Condition 2 after the bar where Condition 1 was met.
My first fold tells me the number of the bar where Condition 1 is met but it seems not to be an integer output from Fold 1 so Fold 2 rejects it as an indexing start point.(Folding:Integeer "to" is expected:NaN)

Any ideas please?
Is there a way to convert Fold 1 output to an integer?
Thanks a lot

hello and welcome,

post the code you have
we can't help fix, what we can't see.

you are asking the wrong question.
simplify your code and figure out what is happening in loop1

i would look for signal1 , then save the barnumber of that signal.
then for loop2, only look at bars bigger than signal1 barnumber
 

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

@Houser I would also like to see your code as it sounds like you are trying to overcomplicate a simple logic chain... The use of the if-then-else construct would accomplish the task you have described, along with the within x bars clause... You would initially test for the second criteria and then if true you would look for the first criteria within 10 bars... I think you'll find that this will work and will be processed much fast and with less overhead...

Essentially like below:

Ruby:
def trigger = if criteria2 then if criteria1 within 10 bars then 1 else Double.Nan else Double.Nan;

Hint: The use of within 10 bars does a lookback through the pervious 10 bars, no fold required...
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
211 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