How to make sure price has traded at the BuyPrice before taking the trade?


I am writing an end of day trading system to back test it.
I want to enter the trade, the next day - not at the open, but at 8% below the Open price. If the price has not traded below 8% of the Open, the next day, then the trade should not be taken.

Buy 					= Cond1 AND Cond2;
BuyPrice 				= C - (0.08 * C);

When I backtest the AFL, I see that the trades are entered at the BuyPrice, even though the price has not traded at that value.

How do I make sure that I only enter the trade if the price has traded at the BuyPrice?

Thanks for the help.


Look here

So something along these lines

/// modfied from
/// @link

pcnt = 8;// percent below price

BuySignal = Cond1 AND Cond2;

// buy on the next bar
Buy = Ref(BuySignal, -1);
BuyLimitPrice = Open * (1-pcnt/100);//Ref(Close, -1) * (1-pcnt/100);

Buy = Buy AND L < BuyLimitPrice;
BuyPrice = Min(Open, BuyLimitPrice);
1 Like

Thank you! Exactly what I was looking for.

This approach to using limit orders may produce unrealistic backtesting results depending on your strategy rules. Read through this entire thread to understand why: PositionScore / Ranking for trades taken “next day at limit” - #6 by mradtke

If your strategy has the potential to generate more Setup conditions than you have the capacity to enter, then you will need to use a CBT to properly model your system.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.