Problem with nesting a custom formula within a custom formula

Here are two custom formulas:

$turnbar15min

LoopMax("Eval(MACDD(12,26,1,CTR)<MACDD(12,26,1,CTR+1) AND MACDD(12,26,1,CTR)<MACDD(12,26,1,CTR-1),CTR,0)",15,1)

$turnbarPREVmin

LoopMax("Eval(MACDD(12,26,1,CTR)<MACDD(12,26,1,CTR+1) AND MACDD(12,26,1,CTR)<MACDD(12,26,1,CTR-1),CTR,0)",126,$turnbar15min+1)

In the second formula the loop needs to start one day before the number resulting from the first formula; hence I nested the first formula into the second formula and this should pose no problem because below the custom formula field the following is written [quote]
You can reference custom formulas inside a custom formula.
[/quote]

However, when I call the two formulas in a screen, I get an error in the rule which uses the second formula (see attached).

So is nesting possible or not and - if not - what would be a possible workaround?


Currently, parameters to cross-sectional functions must be constant or literal values.
This is the easiest for us to implement because argument values can’t change between stocks.

I would recommend using a custom variable in $turnbarPREVmin in combination with the ‘break’ parameter (6th parameter) to accomplish the task.
Here’s something like what I’m talking about. I’m almost sure I have an off-by-one error in ‘CTR<@turnbar15min+126’, so double-check that.

LoopMax("Eval(CTR>@turnbar15min,Eval(CTR<@turnbar15min+126,Eval(MACDD(12,26,1,CTR)<MACDD(12,26,1,CTR+1)&MACDD(12,26,1,CTR)<MACDD(12,26,1,CTR-1),CTR,0),NA),0)",141,1,1,0,1)

Thanks Aaron!

From what I understand the referencing with another custom formula works as long as that formula is part of the condition statement.

The formula nesting wasn’t the problem in this case, though the unclear error message doesn’t help.
In this case, the error was because you were using an argument to the LoopMax function which was not a constant or literal.