Conditional limit order in backtest

I found this very helpful article which describes how to handle limit orders in the backtester.

https://www.amibroker.com/kb/2014/11/26/handling-limit-orders-in-the-backtester/

Here is the sample backtest code;

BuySignal = Cross( Close, MA(Close, 100 ) );

// buy on the next bar
Buy = Ref( BuySignal, -1);
BuyLimitPrice = ValueWhen(BuySignal, Close) * 0.99;

// now we check if limit was hit
Buy = Hold( Buy, 3 ) AND L < BuyLimitPrice;

// if Open price is below the limit, then we use Open for entry
BuyPrice = Min( Open, BuyLimitPrice )

The code works fine. I encountered an obstacle to create a conditional buy limit order. What I want is something like this;

Buy = IIf(BuyLimitCondition==False, BuySignal, BuyLimitConditionSignal  );

BuyPrice = IIf(BuyLimitCondition==False, BuyLimitPrice,  BuyLimitConditionPrice);

So, the problem is how to generate BuyLimitConditionSignal and BuyLimitConditionPrice.

Any hints on how to get started?