Counting Bars Back to the Most Recent Conditions

TNTrader5159

Active member
Is <fold> the function to use to calculate how many bars back the first fulfillment of a condition occurred? I want to make sure price dropped below a certain value more recently than it rose above another certain value. For instance...

Def A = Highest(High, BarsEngulfed)[1];

Def B = Lowest(Low, BarsEngulfed)[1];

I want to calculate the number of bars eclipsed by the current bar (if any) on both high and low ends with a minimum of 3 and a maximum of 55.

For a short trade, I must make sure the price broke below the lowest price of all bars eclipsed back to where both the highest and lowest points of all bars eclipsed occurred more recently than it broke above the highest price of all bars eclipsed back to where both the highest and lowest points of all bars eclipsed occurred. Here is some code I wrote:

ABCD Pattern Specifications



SHORT



Declare lower;



### Variable: BarsEngulfed = 3 to 55 recursive. The current bar must engulf any number of bars from and including 3 to 55 on both ends to satisfy this first requirement for a complete ABCD pattern. The pattern completes upon the first trade at or below the lowest price in the previous <BarsEngulfed> bars. The result defines how many bars are thereby engulfed from a minimum of 3 to a maximum of 55. ###



Def A = Highest(High, BarsEngulfed)[1];

Def B = Lowest(Low, BarsEngulfed)[1];

Def C = High;

Def D = B;



Def Cond1S = If Open > B then 1 else 0;

### Open must be higher than the lowest price of the previous <BarsEngulfed> bars ###



Def Cond2S = If High > A then 1 else 0;

### High must be higher than the highest price of the previous <BarsEngulfed> bars ###



Def Cond3S = If Low <= B then 1 else 0;

### Low must be less than or equal to the lowest price of the previous <BarsEngulfed> bars (this is the trigger point) ###

Def Cond4S = If Close < A then 1 else 0;

### Close must be lower than the highest prices of the previous <BarsEngulfed> bars ###

Def Cond5S = If High <= A + (A – B) then 1 else 0;

### High must be no higher than itself plus the difference between the highest price of the previous <BarsEngulfed> bars minus the lowest price of the previous <BarsEngulfed> bars ###

Def Cond6S = Fold CountEm = 3 to 55…?

### The most recent occurrence of a price prior to <BarsEngulfed> bars that is lower than the lowest price of the previous <BarsEngulfed> bars minus the distance from the current high to the lowest price of the previous <BarsEngulfed> bars must occur more recently than did any price higher than the highest price of the previous <BarsEngulfed> bars. This assures there has been upward movement in the price before the Short setup pattern develops. ###

Def ShortPattern = If Cond1s + Cond2S + Cond3S + Cond4S + Cond5S + Cond6S + Copnd7S == 7 then <PrelimSignal> else 0;

Please help with Cond6S. Thanks in advance!
 
Solution
Is <fold> the function to use to calculate how many bars back the first fulfillment of a condition occurred? I want to make sure price dropped below a certain value more recently than it rose above another certain value. For instance...

Def A = Highest(High, BarsEngulfed)[1];

Def B = Lowest(Low, BarsEngulfed)[1];

I want to calculate the number of bars eclipsed by the current bar (if any) on both high and low ends with a minimum of 3 and a maximum of 55.

For a short trade, I must make sure the price broke below the lowest price of all bars eclipsed back to where both the highest and lowest points of all bars eclipsed occurred more recently than it broke above the highest price of all bars eclipsed back to where both the highest...
Is <fold> the function to use to calculate how many bars back the first fulfillment of a condition occurred? I want to make sure price dropped below a certain value more recently than it rose above another certain value. For instance...

Def A = Highest(High, BarsEngulfed)[1];

Def B = Lowest(Low, BarsEngulfed)[1];

I want to calculate the number of bars eclipsed by the current bar (if any) on both high and low ends with a minimum of 3 and a maximum of 55.

For a short trade, I must make sure the price broke below the lowest price of all bars eclipsed back to where both the highest and lowest points of all bars eclipsed occurred more recently than it broke above the highest price of all bars eclipsed back to where both the highest and lowest points of all bars eclipsed occurred. Here is some code I wrote:

ABCD Pattern Specifications



SHORT



Declare lower;



### Variable: BarsEngulfed = 3 to 55 recursive. The current bar must engulf any number of bars from and including 3 to 55 on both ends to satisfy this first requirement for a complete ABCD pattern. The pattern completes upon the first trade at or below the lowest price in the previous <BarsEngulfed> bars. The result defines how many bars are thereby engulfed from a minimum of 3 to a maximum of 55. ###



Def A = Highest(High, BarsEngulfed)[1];

Def B = Lowest(Low, BarsEngulfed)[1];

Def C = High;

Def D = B;



Def Cond1S = If Open > B then 1 else 0;

### Open must be higher than the lowest price of the previous <BarsEngulfed> bars ###



Def Cond2S = If High > A then 1 else 0;

### High must be higher than the highest price of the previous <BarsEngulfed> bars ###



Def Cond3S = If Low <= B then 1 else 0;

### Low must be less than or equal to the lowest price of the previous <BarsEngulfed> bars (this is the trigger point) ###

Def Cond4S = If Close < A then 1 else 0;

### Close must be lower than the highest prices of the previous <BarsEngulfed> bars ###

Def Cond5S = If High <= A + (A – B) then 1 else 0;

### High must be no higher than itself plus the difference between the highest price of the previous <BarsEngulfed> bars minus the lowest price of the previous <BarsEngulfed> bars ###

Def Cond6S = Fold CountEm = 3 to 55…?

### The most recent occurrence of a price prior to <BarsEngulfed> bars that is lower than the lowest price of the previous <BarsEngulfed> bars minus the distance from the current high to the lowest price of the previous <BarsEngulfed> bars must occur more recently than did any price higher than the highest price of the previous <BarsEngulfed> bars. This assures there has been upward movement in the price before the Short setup pattern develops. ###

Def ShortPattern = If Cond1s + Cond2S + Cond3S + Cond4S + Cond5S + Cond6S + Copnd7S == 7 then <PrelimSignal> else 0;

Please help with Cond6S. Thanks in advance!

i haven't read all of your post yet (it's late), but i think you want to find engulfed bars.
maybe this will help get you started,
https://usethinkscript.com/threads/...st-65-most-recent-days.7483/page-2#post-72474
 
Last edited:
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
388 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