It doesn’t appear that you’re taking opening gaps into account. If the opening price is greater than your Buy Stop price, then you should set BuyPrice to Open. Specifically, I would change this:
BuyPrice = max( BuystopPrice,l );
To this:
BuyPrice = max( BuystopPrice,Open);
Worst case, however, it appears that your BuyPrice should have been equal to the low, not less than the low. Follow @HelixTrader’s advice on how to debug your formula.
I have now tried to develop it further, using a buy signal and no trading delays
I get no trades
when I remove the buy signal and add a trading delay I get trades and signals
is there something peculiar I am doing with the buy signal? do I need to move the cross to the buy signal?
Gapu = GapUp() AND C > O;
Gapd = GapDown() AND C < O;
Buysignal = gapu AND liquid AND inindex
AND strongbull
AND bullin AND NOT OnLastTwoBarsOfDelistedSecurity ;
// if Open price is above the stop, then Open for entry
BuyPrice = max( BuystopPrice,o);
Buy = (Ref(buysignal,-1)) AND Cross(H,buystopprice);
Have you tried using an Exploration to output all the variables that Buy and BuyPrice are dependent on? That will usually reveal where your assumptions differ from the actual data values.