I'm trying to buy using the open price and sell on the close price using rotational backtester. I have tried using BuyPrice = Open;
but that didn't do anything. I also tried to set the Buy prices: to 'Open' in the Trades tab in the Analysis settings. When I do this, the buy price and the open price is changed to open even though I left the Sell prices: to 'Close'.
Thanks in advance for any help.
The manual says clearly:
https://www.amibroker.com/guide/afl/enablerotationaltrading.html
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)
Rotation has to occur on one time per bar.
In Rotational mode there are no "buy" and no "sell" signals. It is only the rotation.
I have attached a screenshot of my settings. When I set Buy price: to "Open", and I check the trade log, both buy price and sell price is taken from the Open price. When I set Buy price: to "Close", both buy price and sell price is taken from the Close price.
Correct. Exactly as the documentation states, and exactly as @Tomasz explained to you in the previous reply. To achieve what you want, you cannot use rotational mode.
The documentation said to use the "buy price" from the Settings | Trade page. I am doing exactly that. I set the Buy price: to Open. When I set the Buy price: to Open and leaving the Sell price: to Close, the trade log shows that bought buy and sell price is Open. That seems like a bug to me. Why have the option to pick Buy price and Sell price if the backtester is not using it ?
There are no bugs.
Please read entire sentence not just the beginning. Let me quote again what documentation actually 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)
It works exactly as documented. And as I said before
Rotation has to occur on one time per bar (either open or close).
In Rotational mode there are no "buy" and no "sell" signals. It is only the rotation.
The Settings | Trade page is very misleading since it has both "Buy price:" and "Sell price:" options on it. If I can't use rotational system for this, are there sample code on how to do this in the regular backtester ? I tried using chatgpt but we get stuck on buy/sell the top 10 symbols each Monday. The code either buy and sell the same day or buy on Tuesday and sell next Monday. What I want to do is rotate each Monday. Here is what I got so far.
SetBacktestMode(backtestRegular); // Switch to regular backtester
SetOption("InitialEquity", 250000);
SetOption("MaxOpenPositions", 10);
SetPositionSize(25000, spsValue); // Equal allocation for 10 positions
SetTradeDelays(0, 0, 0, 0);
Weekly = DayOfWeek() == 1; // Monday rebalancing
MAPeriod = 15;
// Calculate momentum score
// Score = 100 - Ref(((Close - MA(Close, MAPeriod))/MA(Close, MAPeriod) * 100, -1);
// Ranking mechanism
PositionScore = 100 - (Close - MA(Close, MAPeriod))/MA(Close, MAPeriod) * 100; // Determines priority for stock selection
// Monday trading rules
Monday = DayOfWeek() == 1;
// Signal generation
BuySignal = Ref(Monday, -1); // Generate signal on FRIDAY
SellSignal = Monday; // Sell on MONDAY
// Trade rules
Buy = BuySignal;
Sell = SellSignal;
BuyPrice = Open; // Enter at Monday's open
SellPrice = Close; // Exit at Monday's close
Settings page does not "know" what formula would you use later and if you are going to use rotational or not rotational mode.
If you want to buy/sell every day you should just use:
buy=1;
sell=1;
BUT it is NOT rotational system. I told you already 2 times, that in rotational mode rotation (all tardes) occur once per bar. Not twice. Rotational mode is DIFFERENT than regular and the difference is that rotation is rotation, not individual buys and sells and as I wrote you twice already, it happens ONCE per bar.
If you don't like that you can use custom backtester and use EnterTrade/ExitTrade in whatever way you want and use whatever prices you want.
The correct answer usually lies in "The documentation". Be careful when declaring it's a bug.