# How can I make sure some code only calculate once each bar?

Questions about MultiCharts and user contributed studies.
oliveagle
Posts: 20
Joined: 07 Jul 2011
Has thanked: 4 times
Been thanked: 4 times

### How can I make sure some code only calculate once each bar?

I thought it was simple...but I'm wrong....It drives me crazy...
take a look at this code.

Code: Select all

`variables:   abar(0);value1 = 0;if abar<> currentbar then begin   // why every time abar changes back  to the previous value?   print("1 ", abar,currentbar, value1);      abar = currentbar ;   value1 = 12;   print("2 ",abar,currentbar, value1);end;`

result:

1 106.00 107.00 0.00
2 107.00 107.00 12.00 <- now abar = 107. !!!!!!!!
1 106.00 107.00 0.00 <--- why? still 106???
2 107.00 107.00 12.00
1 106.00 107.00 0.00 <--- why? still 106???
2 107.00 107.00 12.00
1 106.00 107.00 0.00 <--- why? still 106???
2 107.00 107.00 12.00
...

Who can help me out? or Is this bug of MC ?

oliveagle
Posts: 20
Joined: 07 Jul 2011
Has thanked: 4 times
Been thanked: 4 times

### Re: How can I make sure some code only calculate once each b

e………… find out the solution..
IntraBarPersist abar(0);

bowlesj3
Posts: 2081
Joined: 21 Jul 2007
Has thanked: 195 times
Been thanked: 414 times

### Re: How can I make sure some code only calculate once each b

Try studying this thread to get a better handle on intrabarpersist (what MC is doing with it and without it)

viewtopic.php?f=5&t=6871&hilit=understanding+intrabarpersist
These users thanked the author bowlesj3 for the post:
oliveagle