I tried to implement in code trade delays when a buying signal occurs but the result is a big different from
setting the delays options on the UI.
my code is
ChannelBreakUp= Close > Ref( HHV( High, period ), -1);
Buy = Ref(ChannelBreakUP,3);
that means buy 3 bars after the breakup signal occurs.
The result running by code generated more extra trades but some of the buying time is not match with the logic.
Wrong. That means buying 3 bars BEFORE the ChannelBreakUP signal occurs, ie it's looking into the future to find when channelBreakUp next happens, not when it last happened.
You need to use a negative value in Ref to look backwards.
Buy = Ref(ChannelBreakUP, -3);
will provide your buy signal 3 bars AFTER ChannelBreakUP.
References a previous or subsequent element in a ARRAY. A positive period references "n" periods in the future; a negative period references "n" periods ago.