How can I let buy/sell price to be any number?

Hi

I read that if you do not explicitly disable AmiBroker's price bound checking, then AmiBroker will force the BuyPrice to be within the High-Low range of the entry bar.

I am testing for option volatility, so I want the sell price to be

sell = sellcondition;
SellPrice = IIF(sell and c < BuyPrice, BuyPrice + BuyPrice - C, C);

At the moment, sellprice is defaulting to just close value of the bar. How can I disable the price bound checking?

Thank you

AFL Function Reference - SETOPTION (amibroker.com)

PriceBoundChecking

2 Likes

Thank you

Now when I do a simple test like

SetOption("PriceBoundChecking",False);

buy = cross(ma(c, 4),ma(c,5);
sell = cross(ma(c, 5),ma(c,4);
sellprice = buyprice;

All trades should have 0% pnl but this doesnt seem to be working. I just get normal close as sellprice. But when I put some value for sellprice it works.

How can I pass a formula for sellrpice?

Thank you

Did you actually assign the prices for entering and exiting the trade to the BuyPrice and SellPrice arrays?

Not sure what you mean?

For this example, I wanted the sellprice to equal the buyprice to see if it works. Or should I have set up as valuewhen(buy, buyprice) ?

You alway should assign values to the price arrays when running any backtest.
Plesase refer to this part of the manual:
Back testing your trading ideas

1 Like

@trunda - It is simple. You assignment does nothing. Both buy price and sell price would be equal to close, but close ON DIFFERENT BARS. Close in Monday (say entry) is not the same as say on Friday (exit). So your assumption that you are going to get zero profit is just nonsensical.

To have same price assign a number, not array with different values every bar.

To get better understanding of what is happening in your code and how functions work, use advice given here: How do I debug my formula?

For what it is worth currently your understanding of backtesting is zero, and you would do yourself a favour if you did NOT disable price bound checking as it is here to protect you from shooting yourself in a foot.

Trying to use prices outside H-L range in backtest is totally unrealistic.
image

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.