Code to implement trade delays


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.

Is that I misunderstood something?


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.



thanks a lot, though still not quite understand…

If you read the manual pointed to you by @HelixTrader you would see this:

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.

1 Like