Price and delay code that should NOT be used in rotational trading AFLs

Hello,

I learned something new with rotational trading. The following is from the documentation under EnableRotationalTrading.

“The rotational trading mode uses “buy price” and “buy delay” from the Settings | Trade page as trade price and delay for both entries and exits (long and short)”

This means that we should NOT have code like the following in the AFL or even in any INCLUDE files used by the AFL. Rather, the Trade prices and delays must be addressed in Settings only.

BuyPrice = SellPrice = ShortPrice = CoverPrice = Open;
SetTradeDelays( 0, 0, 0, 0 );

The lines of code (above) can ONLY be used in non-rotational AFLs.

So, I have learned something yet again.

1 Like

@bistrader On the documentation for rotational trading it says: “The rotational trading mode uses “buy price” and “buy delay” from the Settings | Trade page as trade price and delay for both entries and exits (long and short)”

In my rotational code I was working with, I had the lines:

SetTradeDelays( 0, 0, 0, 0 ); 
BuyPrice = Open;

I checked and found that my line for the BuyPrice had no effect, that was controlled by the settings. However, if I changed my code for the SetTradeDelays from 0 to 1, that would still override the trade delays in the settings. I’m not sure why.

First parameter for SetTradeDelays() (buy delay) writes data to "buy delay" field in the temporary settings table (created for currently running backtest) that gets used by the backtester, so it will change trade delay in rotational trading (it actually "delays" positionscore variable). BuyPrice is different story because it is not "selector". It is array and you can't change trade prices in rotational backtest on bar by bar basis.

So I’m experiencing the frustration of trying to get execution prices on the actual trade days (EOD—signal comes today, executed tomorrow).

It seems AB is (or perhaps it’s just my code) taking the entry price (set as Open and 1-day delay in Backtester Settings) as on the same day I’m generating the EOD signal (forward data leak).

SetBacktestMode(backtestRotational);

EnableRotationalTrading() ;
SetOption("PortfolioReportMode", 1);
SetOption("MaxOpenPositions", 5);
SetOption("WorstRankHeld", 4);
SetPositionSize( 20, spsPercentOfEquity);
SetTradeDelays(1,1,1,1);

PositionScore = 1000 - RSI(2);
AddColumn(PositionScore, "PositionScore");


I have all trade delays set to “1” in the code (SetTradeDelays(1,1,1,1) though I read this is ignored in rotational mode.
Is there code I can add to reflect the trades taking place the day following signal generation without doing so in Custom Backtester?

If it must be done in Custom Backtester, is their some reference for doing rotational strategies this way?

Is there a way use AddtoColumn in an Exploration to display any of the steps or process rotational mode is going through?

Please read what I already wrote earlier in this thread and what is written the official documentation
http://www.amibroker.com/f?enablerotationaltrading

Quote

Important:
The rotational trading mode uses "buy price" and "buy delay" from the Settings | Trade page as trade price and delay for both entries and exits (long and short)