Limit Repainting using fold

B

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

skynetgen

Active member
Warehouse
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;
 
B

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:
Z

zeek

Member
VIP
Interesting! Please keep us updated with your results because if there is a way to limit or avoid repanting, that would be huge!
 
Thread starter Similar threads Forum Replies Date
CHOZEN Questions 3
Similar threads
Time limit code

Top