Hi, how do I use CBT to specify the entry and exit price of a trade, and ignore the built in buyprice/sellprice variables?
An example:
Buy = Sell = Short = Cover = 0;
BuyPrice = SellPrice = ShortPrice = CoverPrice = O;
// Only 1 trade for this symbol
Buy[BarCount-2] = 1;
Sell[BarCount-1] = 1;
// =============================================
SetCustomBacktestProc("");
if (Status("action") == actionPortfolio)
{
//trade entryprice = 100;
//trade exit price = 200;
//so trade profit would be 100%;
}
Tomasz
November 4, 2023, 8:15am
2
It was explained dozens of times already , that by default AmiBroker protects users from trading using abstract prices. All trade prices must be inside High-Low range of given bar.
This feature is called Price bound checking and it is turned ON by default.
To switch that off you have to use SetOption
https://www.amibroker.com/f?setoption
It is HIGHLY DISCOURAGED to do so because you would get non-sense results (not reproducible in real life)
Thank you, I understand all that - and know it will give non-real life results.
My question was is it possible to programmatically artificially set the entry and exit price via the CBT?
Tomasz
November 4, 2023, 10:55am
4
You just assign new prices to BuyPrice, SellPrice, ShortPrice, CoverPrice.
It works exactly the same regardless if you are using CBT or not.
If you want to set prices outside H-L range you have to call SetOption("PriceBoundChecking", False);
Thank you for that Tomasz
system
Closed
February 12, 2024, 1:55pm
6
This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.