Hello everyone, from Australia. Have really appreciated your responses over past few months.
I am backtesting a trading system. It is allowed to open max 6 positions. I am comfortable with the results, but my question is: in practice, using the backtester today, how do I know what trades to put on tomorrow? If I scan instead, using a virtual copy of the backtest formula, too many potential trades result - I'm unable to restrict this to a max open position of 6. So how do I plan for tomorrow's trades?
In backtest settings Portfolio tab check "Add artificial future bar".
Note: artificial future bar is added in backtest and optimization only.
Thank you
Have checked 'Add artificial future bar', but unable to find this extra information after doing backtest.
(also noticed I don't have the Monte Carlo tab like you)
Kind regards, Harry
@harryzehnwirth, we would probably need to know more about your entry conditions to suggest why you're not seeing any trades that are entered on the Artificial Future Bar. That bar will have OHLC prices that are all equal to the closing price of the last bar of actual data. If your strategy requires conditions to be met on the day of entry (for example, exceeding a limit price), then you will likely need to make some modifications to see those "virtual trades" that are to be entered tomorrow.
As for the missing Monte Carlo tab, that could be related to the version of AmiBroker that you're running.
An example formula below. Backtest certainly yields a list of trades, but I don't see any bar (s) for 'tomorrow's trades.
Buy = RSI( 2 ) < 5
AND Close > MA( Close , 200 )
AND Close > 1
AND Close < 8
AND ATR( 10 ) > Close/20
AND Volume > 400000;
Sell = Close > MA( Close , 5 );
PositionSize = -10;
Short = 0;
Cover = 0;
Thank you for your help.
Harry
Unfortunately, AmiBroker cannot yet predict the future. Therefore, the artificial future bar OHLC prices are populated with today's closing price. If tomorrow's closing price is the same as today's closing price, RSI(2) is not going to decline, and you will not get any new entries.
Typically you can use the Artificial Future Bar to handle two different cases:
- You're using trade delays. For example, all of your entry conditions are met today, but you want to actually enter the trade at tomorrow's open.
- You're entering with a limit order. For example, all of your Setup conditions are met today, and tomorrow you want to enter if the price falls below X.
The second case is the one that might require some modification to your logic, because of course AB can't predict if tomorrow's price will fall below X. So in the case of the final bar, you'll want to treat all Setups as Entries. Since that's not what you're trying to achieve, I won't go into a lengthy explanation of that here.
Here's another way to look at it. If you didn't have AmiBroker, how would you decide which orders to place for tomorrow? Based on your rules, it would appear that every stock in your trading universe is a valid candidate for entry tomorrow because you have no Setup (trade qualification) rules.
I think I belong in category 1.
Say my setup is scanned (yesterday) with the similar formula:
Buy = RSI( 2 ) < 2
AND Close > MA( Close , 200 )
AND Close > 1
AND Close < 10
AND Volume * Close > 6000000
AND Ref( MA( Volume , 21 ) , -21 ) > 600000
AND Volume > 600000;
Short = 0;
Cover = 0;
The scanner will yield more trade results (yesterday) than the backtester (today) because of it's portfolio-setting at max. open positions of, say, 6.
How can I similarly restrict the scan results to 6 in same way as backtester?
All the trades in backtester are executed at Open, buy (sell) delay 1 day
Thank you
Harry
If your Buy conditions are set as above, and entry delay is set to 1 bar, and you've ticked "Use artificial future bar", then when you run a back test today you should see entries for tomorrow, assuming there are symbols that meet your criteria and you have capacity to take more trades.
If you prefer to limit the number of trades shown by a Scan or Exploration, you can use StaticVarGenerateRanks() to rank all the symbols and add another condition to your Buy logic. However, using that approach will not take into account any other currently open positions.
Matt I must still be doing something wrong.
When I backtest this formula today, with checked artificial future bar, and 'trades' window showing "Buy price - Open" and "Buy delay 1", the result list shows just one trade ( P - Pandora Media), but it's for today. I can't see anything else a name I can trade tomorrow. So backtest even with artificial future, does not reveal potential trades for tomorrow. Scanning does, but I want it to be as 'selective' as backtester is (like max pos 6)
Buy = RSI( 2 ) < 2
AND Close > MA( Close , 200 )
AND Close > 1
AND Close < 10
AND Volume * Close > 6000000
AND Ref( MA( Volume , 21 ) , -21 ) > 600000
AND Volume > 600000;
Sell = Close > MA( Close , 4 );
PositionSize = -10;
Thanks for putting up with me
Harry
Between the requirement for an RSI(2) less than 2 and a price between 1 and 10, your Buy logic is quite restrictive. In order to get some trades using the current members of the S&P 500 index, I adjusted your code as below:
Buy = RSI( 2 ) < 5
AND Close > MA( Close , 200 )
AND Close > 1
AND Close < 100
AND Volume * Close > 6000000
AND Ref( MA( Volume , 21 ) , -21 ) > 600000
AND Volume > 600000;
Sell = Close > MA( Close , 4 );
PositionSize = -10;
I set my analysis settings as you described, and ran a back test from 1-July-2018 to present. The last day of data in my database is from 1-Aug-2018. Here are the trades that appear in my trade list since 31-July-2018:
Symbol | Trade | Date | Price | Ex. date | Ex. Price | % chg | Profit | % Profit | Shares | Position value | Cum. Profit | # bars | Profit/bar | MAE | MFE | Scale In/Out |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
GRMN | Long | 7/31/2018 | 62 | 8/1/2018 | 64.5 | 4.03% | 41.62 | 4.03% | 16.6472 | 1032.13 | 359.04 | 2 | 20.81 | -1.11% | 4.03% | 0/0 |
PYPL | Long | 7/31/2018 | 82.51 | 8/1/2018 | 83.45999 | 1.15% | 11.88 | 1.15% | 12.50911 | 1032.13 | 370.92 | 2 | 5.94 | -1.47% | 1.15% | 0/0 |
RJF | Long | 7/31/2018 | 91.45 | 8/2/2018 | 91.51 | 0.07% | 0.68 | 0.07% | 11.28624 | 1032.13 | 371.6 | 3 | 0.23 | -1.62% | 2.62% | 0/0 |
FOXA | Open Long | 7/25/2018 | 45.13 | 8/2/2018 | 45 | -0.29% | -2.94 | -0.29% | 22.61294 | 1020.52 | 368.66 | 8 | -0.37 | -1.20% | 1.11% | 0/0 |
ATVI | Open Long | 7/31/2018 | 72.91 | 8/2/2018 | 73.08 | 0.23% | 2.41 | 0.23% | 14.15617 | 1032.13 | 371.07 | 4 | 0.6 | -0.54% | 2.29% | 0/0 |
FISV | Open Long | 7/31/2018 | 75.06 | 8/2/2018 | 74.74 | -0.43% | -4.4 | -0.43% | 13.75069 | 1032.13 | 366.67 | 4 | -1.1 | -1.59% | 2.34% | 0/0 |
ICE | Open Long | 8/1/2018 | 74.05 | 8/2/2018 | 73.67 | -0.51% | -5.33 | -0.51% | 14.03105 | 1039 | 361.34 | 3 | -1.78 | -0.70% | 1.29% | 0/0 |
MMC | Open Long | 8/1/2018 | 83.38 | 8/2/2018 | 83.05 | -0.40% | -4.11 | -0.40% | 12.46101 | 1039 | 357.22 | 3 | -1.37 | -0.65% | 0.68% | 0/0 |
AKAM | Open Long | 8/2/2018 | 71.63 | 8/2/2018 | 71.63 | 0.00% | 0 | 0.00% | 14.45934 | 1035.72 | 357.22 | 2 | 0 | 0.00% | 0.00% | 0/0 |
Notice that the last trade in the list, AKAM, is for 2-Aug-2018, the day after my data ends.
Thanks again,
I understand what you've done, and I've been able to reproduce the Aug 2 AKAM trade,
but can't comprehend why making the conditions less restrictive brings out the Aug 2nd trade?
In order for a trade to show up "tomorrow" (now today), two conditions must be true:
- There must be symbols that meet your entry criteria today
- You must have capacity to take additional trades, in your case meaning less than 6 trades currently open
I don't know which watchlist you were testing against or what your trade list looked like, so it's a little hard to guess why you weren't seeing other Aug 2 trades.
Backtesting "Major Exchange Listed" which includes just about all US stocks - on NYSE, NASDAQ and AMEX
And using that watch list, do you have evidence that both of the above conditions exist, i.e.
- There are symbols that meet your entry criteria today
- You have capacity to take additional trades
An Exploration should answer the first question, and a trade list the second question.
Got it!!
So, followed your lead and loosened up backtest formula to 'allow' artificial future bars to be generated. And bingo!
Thank you
Harry
So, 'add artificial future bar' when back testing now works well for me using U.S. data. But oddly when I try same with Australian market, doesn't work.
Both my U.S. and Aust market data downloaded from 'premium data'
"Doesn't work" isn't much to go on. Could you be more specific about what you've verified (see my previous post), what you're expecting, and what's actually happening? I doubt very much that it's an issue with the Aussie data itself.
I noted a similar problem discussed here some weeks ago. Their problem was that it is often tomorrow in australia vs. the US due to the international date line. Take a look for that problem here for their discusssion vs. the date in the real world andbased on your data vendors dating.
Thanks. Agree. In Australia (and everywhere else really) backtest a period that ends tomorrow if choose and check 'add artificial future bar'