Search code examples
tradingback-testingamibroker

Scale in buying positions in Amibroker backtesting


I have a simple backtesting code in Amibroker. It looks something like this;

Buy = BuySignal();
Sell = SellSignal();

My equity is $10000. This code works but the limitation is that when it buys, the entire equity $10000 is sunk into the buy. What I want is something like this;

When BuySignal() is generated, buy $1000 or 10% of equity. Keep buying this amount whenever this BuySignal() is generated. If SellSignal() is generated, sell entire position.

How can I modify the code to do scaling-in of buying positions?

I am using Amibroker ver6.28.


Solution

  • Try this.

    PosQty = 10; 
    SetOption("MaxOpenPositions", PosQty );
    PositionSize = -100/PosQty;
    
    Buy = IIf(BuySignal(), sigScaleIn, 0);