Reply To: Using a dynamic POWER function calculation

Optuma Forums Optuma Scripting Using a dynamic POWER function calculation Reply To: Using a dynamic POWER function calculation

  • Topics: 40
  • Replies: 2,011
  • Posts: 2,051

Hi Dean,

The way we set up variables was to treat them as single numbers (not an array of numbers). Because of that the prior values are ignored and it will only show as the last value.

Something to keep in mind with Optuma is that we do not run each line in the script for each bar but we fully calculate each line. So this line

$months = FLOOR((BARDATE() – startDate) / daysPerMonth) + 1;

is fully calculated before the final line is calculated.

The use of the variables was so we can have $a = 50 and that would allow me to have bars=$a through my code.

Side note: if you make it #$a = 50; then the “a” will show up in the properties panel.

So what is the solution?

Have a running total of the number of months:
M1 = FLOOR((BARDATE() – startDate) / daysPerMonth) + 1;
This is an array instead of a single value.

Use an IF to compound when the month changes
CMGRTotal = If(M1 <> M1[1], CMGRTotal[1] * CMGR, CMGRTotal[1]);

What that is saying is if M1 is different from the previous value (M1<>M1[1])
then multiply our previous value by the CMGR (CMGRTotal[1] * CMGR)
else Set the value to the same value as last time (CMGRTotal[1]).

Then you can multiply that by the start value.

All of this is untested but it should set you in the right direction.

All the best


Pin It on Pinterest