amibroker

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.


Solution

  • The error message you get is quite self-explanatory. If you look at the definition of ApplyStop you'll see that the parameter ActivationFloor needs to be an number (either an amount or a percentage) which determines when stop is activated.

    Now, the piece of code you are sharing might be taken out of context. It would be helpful to see more to determine how one could help you further.