How to get this breakeven formula working?

I have this formula used in backtesting for break-even trades.

activation_floor_array = 1.02*EMA(Close, 50);
ApplyStop( stopTypeLoss, stopModePercent, 0, True, False, 0, 0, -1, ActivationFloor=activation_floor_array );

When I run it, I get an error saying that Activation Floor argument requires a number, not an array. I tried SelectedValue(activation_floor_array) but realized it returns the wrong number. The right number is the number in activation_floor_array that coincides with the trade entry bar. SelectedValue() returns the last bar of the range.

Can someone help or provide some hint on how to move forward?

Thank you.

First as you have realized ActivationFloor needs scalar, I would remove '_array' from your 'activation_floor' variable as this could be misleading for you (and others) in future references.

You could use ValueWhen() wrapped inside LastValue() if your condition in ValueWhen doesn’t hit true again while in the current trade.

Or you could use Lookup() with dt to anchor your MA value at trade entry bar.

See Lookup(), LastValue(), ValueWhen().


This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.