how to efficiently iterate through monotonically decreasing fractals

muscleman

New member
I need to iterate through the chart from right to left and for each fractal (defined as two left and two right bar's lows are all >= this current bar's low), I want to make sure I only look at monotonically decreasing fractals and skip the ones that goes back up.
I have the leftOffset and RightOffset that defines where I start and stop this iteration. So I can do
fold index = RightOffset to leftOffset
If the fractals I encounter during fold is 70, 62, 66, 65, 60, 50., I want to skip that 66 and 65 fractal because they are both higher than 62.
If I write this in Java, it would be really simple. I could just have a variable called highWaterMark, and init to 70, and every time I see a fractal lower than highWaterMark, I know I should not skip it and I will lower highWaterMark to that value.
The problem with thinkscript is that if I def a variable, I cannot change its value once it is assigned. so I would not be able to do this efficiently. Could you give any suggestions?
 
I need to iterate through the chart from right to left and for each fractal (defined as two left and two right bar's lows are all >= this current bar's low), I want to make sure I only look at monotonically decreasing fractals and skip the ones that goes back up.
I have the leftOffset and RightOffset that defines where I start and stop this iteration. So I can do
fold index = RightOffset to leftOffset
If the fractals I encounter during fold is 70, 62, 66, 65, 60, 50., I want to skip that 66 and 65 fractal because they are both higher than 62.
If I write this in Java, it would be really simple. I could just have a variable called highWaterMark, and init to 70, and every time I see a fractal lower than highWaterMark, I know I should not skip it and I will lower highWaterMark to that value.
The problem with thinkscript is that if I def a variable, I cannot change its value once it is assigned. so I would not be able to do this efficiently. Could you give any suggestions?

can you explain some more on what you are trying to do?
i don't know what monotonically or fractals are.

i don't know what values these numbers represent,
If the fractals I encounter during fold is 70, 62, 66, 65, 60, 50., I want to skip that 66 and 65 fractal because they are both higher than 62.

where are these numbers coming from?
why ignore 70?
how do you determine 62 has value to compare to the others?

please try to write out simple, short rules, that describe what has to happen
( don't mention fractal, but describe what that is)
 
Thank you for trying to help. Let me explain a bit more. The numbers to visit are 70, 62, 60,50. The rule is that the first number is always visited, and we need to remember the lowest number visited so far. So that's 70 initially. then 62 should be visited because it is less than 70. And we adjust the watermark down to 62. Then 66 and 65 should be skipped because they are above the water mark. Then 60 should be visited and we adjust the watermark down to 60. Then 50 should be visited and we adjust the watermark down to 50.
The numbers are stock price values that comes from fractals. They are defined like this. For our purpose we only care about bottom fractals.
https://tlc.thinkorswim.com/center/...s-library/bearish-and-bullish/WilliamsFractal
It is easy to traverse the chart and find these fractals. But I want the above rules to decide which fractals to ignore. If variables are mutable, then it is really easy. I can just def watermark and adjust it alone the way, but variable is not mutable. I hate this language. Why does it put up so many restrictions....... :confused:
 
Thank you for trying to help. Let me explain a bit more. The numbers to visit are 70, 62, 60,50. The rule is that the first number is always visited, and we need to remember the lowest number visited so far. So that's 70 initially. then 62 should be visited because it is less than 70. And we adjust the watermark down to 62. Then 66 and 65 should be skipped because they are above the water mark. Then 60 should be visited and we adjust the watermark down to 60. Then 50 should be visited and we adjust the watermark down to 50.
The numbers are stock price values that comes from fractals. They are defined like this. For our purpose we only care about bottom fractals.
https://tlc.thinkorswim.com/center/...s-library/bearish-and-bullish/WilliamsFractal
It is easy to traverse the chart and find these fractals. But I want the above rules to decide which fractals to ignore. If variables are mutable, then it is really easy. I can just def watermark and adjust it alone the way, but variable is not mutable. I hate this language. Why does it put up so many restrictions....... :confused:

sorry, i have no idea what you are talking about. you have managed to describe something, without using any common chart terms.
you haven't explained what those numbers are or where they come from.

visit, numbers to visit , has no meaning.
watermark , has no meaning.


you made a common mistake. you jumped right into guessing at using a specific function (a loop) instead of describing what you want to see.
i'm guessing you are used to populating an array and want to do that. arrays don't exist in thinkscript. although each variable is a 1 dimension array, the indexing is relative, not absolute, which makes it near impossible to try to populate an array and later read back data.


start over and describe what you want to see on the chart.
then work backwards to add code to do each step.


thinkscript is a simple language. what can make it hard is, not thinking about things in the same units.
you are using words to describe things, which have no meaning, which makes it impossible to interpret.

a chart has candles.
candles have these parameters: open, high, low, close.
you can create variables equal to formulas.

70, 62, 60, 50
are those numbers the lows from candles?

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

here is a test code to find peaks and valleys with a fractal pattern.
it draws arrows on all the peaks or valleys
can pick how many bars on each side of the middle bar to define them.

Code:
# fractal_peaksvalleys_00

def na = double.nan;

input len = 2;
def fup = WilliamsFractal(len).UpFractal;
def fdwn = WilliamsFractal(len).downFractal;

def vert = 0.002;
plot zu = if fdwn then low*(1-vert) else na;
zu.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
zu.SetDefaultColor(Color.cyan);
zu.setlineweight(3);
zu.hidebubble();

plot zd = if fup then high*(1+vert) else na;
zd.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
zd.SetDefaultColor(Color.cyan);
zd.setlineweight(3);
zd.hidebubble();
 
Last edited:

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