TRICK: pass variables to custom formulas

Dear All,

With the latest upgrades to Custom Formulas (see here) you can now pass variables with SetVar. Here’s an example:

Create a custom formula like this

$return_var = @var // simply returns the value in @var

In the screener type these formulas

setvar(@var,5) and showvar(@a,$return_var)
setvar(@var,10) and showvar(@b,$return_var)

When you run this the custom formula $return_var will be executed twice for each stock and will set @a to 5 and @b to 10

Hope this helps

Sweet! Thanks!

Walter

Marco,

Will SetVar ever handle strings? This doesn’t work now;

ShowVar(@SYMBOL,“XLP”) & ShowVar(@SYM,$SYMBOL)

where $SYMBOL=@SYMBOL

Walter

Walter, Not supported. Maybe there are other ways. What are you trying to do ?

I’m good, Marco. There are other techniques I can use.

Thanks,

Walter

Just noticed some limitation on passing through values.

A variable set in a buy rule isn’t seen by a custom formula in a ranking rule. I’m guessing it an ‘order of evaluation’ thing i.e. the ranking module of run prior to the buy/sell module or scoping.

Just sayin’

Walter

Hi Marco,

This doesn’t seem to work;

$signal=LoopSum("Close(CTR)",@Bars)
SetVar(@Bars,10)
$signal

I get this as an error report;
Error in Buy Rule ‘Buy14’: In $signal: Invalid parameters for LoopSum

Walter

Just reading this now. So if I’m interpreting this feature right, it effectively allows users to reuse single parameter functions?

I don’t know if it’s limited to single parameter functions. I don’t think so, but I haven’t used this trick in a while.

Walter

Got Invalid Parameters for LoopMin message

This may be limited to the loop function. I am able to pass variables to custom formula successfully. Very handy…