Limit Repainting using fold

BlueRaven

New member
I've found this forum and the onenote file to be a huge help while learning thinkscript over the last few months.

So far I've been able to do almost everything I want in thinkscript. However I'm running into a problem on longer studies/plots where it will start to repaint and kill the signal.
I believe fold is the answer to this but I can't get my head wrapped around it. I've done very very limited programming before TOS so I'm not familiar with loop functions and that might be the problem.

if I had a good example of it doing a similar function I'm sure I could modify it to my uses.

Here's the code I'm using currently.

L1 = bottomfractal and close < fastma and close < slowma;
L1C = if L1 then close[1] else if L1C[1] then L1C[1] else double.nan;

L1 plots an arrow below the fractal bottom that closes below the 20ma and 50ma
L1C draws a horizontal line from the close of the fractal.

Currently it draws the line but as soon as there is another bottom fractal it starts to repaint.

I would like to have it not plot L1 if the fractals are higher than the previous one and only plot a new L1 once the fractal closes below the L1C horizontal line or the previous fractal.
If price closes above the 50ma then it resets.

So basically it needs to look to see if the current L1/L1C is active.

I've tried other combos of if statements and trying to trick it by referencing plots instead of defs and it either partially works or breaks the whole study.

If there's another way besides fold I'd be open to that as well.
 

skynetgen

Well-known member
As far as i could understand you still want arrow even if there is another bottom fractaI. would just have LastBottomFractal variable (to track lastfractal before current one) and use this as condition
I dont know the fractal is determined but logic would be something like this:

Code:
rec lastfractal=if fractal then fractal[1] else lastfractal[1];
plot lastarrow=if fractal<>lastbottomfractal then arrowloc else double.nan;
 

BlueRaven

New member
Thanks, I'll give it a try. So instead of looking back 1 bar it's looking back 1 variable. I wasn't aware that was possible.

edit: I was aware that was possible, just didn't use it that way. Still testing it.
 
Last edited:

zeek

Active member
2019 Donor
Interesting! Please keep us updated with your results because if there is a way to limit or avoid repanting, that would be huge!
 

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.
Top