Hello, How can I set AB so that in backtesting it does not reinvest profits, but can scale losses? For example initial capital $10,000, each trade $1,000, so if the trade gives me a profit of $50 the next trade will still be $1,000. If the trade goes into loss then the next trade will have to be $950.
Thanks 1000
Yes, just use
SetOption("AllowPositionShrinking", True );
PositionSize = 1000;
@tempera If you start with $10,000 and lose $50 on your first trade, you will still have $9,950 of equity. What is your logic for investing $950 (rather than 10% of $9,950 or $995) in the second trade?
@Tomasz, I don't believe your solution will result in smaller position sizes until equity falls below $1000. Am I missing something?
Hello Tomasz
I entered this condition in the analysis window of the setting / portfolio / custom backtest procedure path and I received an error window. I tried to put the formula in the head of a random system on a random stock but it does not work, in the attachment you can see that it reinvests the profits.
Hello Mradtke,
the meaning of my money management is to always invest the same amount on each operation, changing the entry lot so as to always invest $1000 per trade. When there are losses on a stock then the loss is scaled from $1000 and we continue like this until the stock "recovers" the losses of $1000. We will proceed by viewing the gains without reinvesting them.
:sis-hand-with-fingers?splayed:
If you are only trading one symbol, then the easiest way to achieve your goal is to set your initial equity to $1,000 instead of $10,000, and use the solution provided by @Tomasz. If you are trading multiple symbols and need to track the P/L per symbol, then you will need to use a CBT and track that information yourself so that you can determine the correct position sizing for the next trade.
If you are getting errors when modifying your code, then you need to post the code that produces the errors. Otherwise, no one will know how to help you.
I am testing on a group of stocks, I tried using the setting / portfolio / custom backtest procedure path function but I got 2 error windows, below:
As I mentioned previously, no one can help fix your code if you don't post it. Have you Googled the phrase "AmiBroker Custom Backtest" and reviewed the material provided in the AmiBroker Help files and from other sources?
Yes you are right. In that case you can use
PositionSize = -10; // 10% of equity
and limit max pos size to 1000.
The error you are getting is (probably) because you are backtesting on symbol that has %
sign in the name and this is interpreted as format specifier and you using some really old version.
You have to either use current version (6.90) or edit "3. Profit Table.afl" as explained here:
Tomasz, with limit max position to 1000 works, thanks!!
but trying to insert the rule you posted at the beginning as a basic condition does not work
here is the rule:
and here is analsys setting:
this error:
These errors happen on every tested system and every stocks, regardless of the %
I'm using the latest version 6.9:
The two lines of code you are using should be in your primary AFL file. You are not using a Custom Backtest (CBT), so unselect that option in the Analysis Settings. A CBT has a very specific structure, as described in the documentation and demonstrated by the code snippets available in the AFL Editor. By not adhering to that structure, your code is never running the second phase of the backtest.
understood, thanks