Basic Next Day System Backtesting

Hello!

I would like to test a very basic system that:

  1. Places a BUY order for each of several limit prices I establish (calculated as of the prior day close). So for example, using daily data for Aug 18, 2022, calculate several limit prices, which are now valid for August 19, 2022. These orders should be filled if the low of Aug 19, 2022 is less than the limit price calculated on the close of Aug 18, 2022.

  2. Places a Short order for each of several limit prices I establish. These orders should be filled if the high price of the next day is higher than the limit prices I establish.

For example, I have BLP1 (Buylimitprice1) through BLPn and SLP1 through SLPn.

I would like to buy and short at every BLP1…BLPn and every SLP1…SLPn on the next bar. Even if I have 100 BLP triggered, I would want each signal to be filled.

For a basic test, I do NOT want to have sell or cover rules. Later I can add sell and cover rules.

In sum, how could I achieve this basic system in the backtester:

Buying/shorting at ALL predefined levels using limit prices if those limit prices are triggered on the next trading day.

IMPORTANT: Since I do not have sell or cover rules, I will need the AmiBroker report to show open trades with open profit and loss. How do I achieve this feature?

Thank you very much!

After consulting the Knowledge Base:

I attempted this code, but get no trades generated even when I know there should be.

/// I have these Buy and Sell signals, which I think are odd, because of AB’s requirement to have a Buy “rule”. I do not have a “rule” per se. What I have are levels where I would like to buy or sell. What is the AB recommended way to code a Buy or Sell “rule” for such a scenario, where the rule is merely buy/sell at **several** limit prices if triggered the next day?

//my hope is that this rule will allow the buy/sell orders to be filled on the next bar, if the next day’s low is below the buylimitprice (BLP1……..BLPn) or if the next day’s high is above the selllimitprice (SLP1…..SLPn)

//Below I show only three BLP and SLPs but I would like the formula to allow for as many BLPs or SLPS as I want.

.

BuySIGNAL1= IIf(Ref (L, 1) < BLP1,1,0);

ShortSIGNAL1 = IIf(Ref(H,1) > SLP1 > 0,1,0);

BuySIGNAL2= IIf(Ref (L, 1) < BLP2,1,0);

ShortSIGNAL2 = IIf(Ref(H,1) > SLP2 > 0,1,0);

BuySIGNAL3= IIf(Ref (L, 1) < BLP3, 1,0);

ShortSIGNAL3 = IIf(Ref(H,1) > SLP3 > 0,1,0);

// buy on the next bar

Buy = Ref(BUYSIGNAL1, -1);

BUYLIMITPRICE1 = Ref(BLP1,-1);

Buy = Ref(BUYSIGNAL,2 -1);

BUYLIMITPRICE2 = Ref(BLP2,-1);

//Can I have multiple buyprice and Buy values as below to match my multiple buy signals?

Buy = Buy AND L < BUYLIMITPRICE1;

BuyPrice = Min (Ref(Open,1), BUYLIMITPRICE1);

Buy = Buy AND L < BUYLIMITPRICE2;

BuyPrice = Min (Ref(Open,1), BUYLIMITPRICE2);

// SHORT on the next bar

Short = Ref(SHORTSIGNAL, -1);

SHORTLIMITPRICE = Ref(SLP1, -1);

SHORT = SHORT AND H > SHORTLIMITPRICE;

SHORTPrice = MAX (Ref(Open,1), SHORTLIMITPRICE);

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