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?

Postby oliveagle » 07 Sep 2011

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

Postby oliveagle » 07 Sep 2011

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

I don't know what to say about this ……

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

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

Postby bowlesj3 » 07 Sep 2011

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=understa ... barpersist


Return to “MultiCharts”