Bollinger Band buy/sell wrong signal due to decimals

Hello all!

I am working on a buy/sell system using BBands. However, I have an issue with some trade execution as the price of the BBand is slightly higher or lower than the price. For example, on a given day the Bottom Bollinger is 1.237027, while the price is 1.237030. Now since I have programmed lower or equal to, this trade does not execute as the price is not actually equal to the BBottom. My question is the following:

How can I make the bottom bollinger round up so it comes to 1.23703?
Alternatively, can I use the AlmostEqual function in some way or another function, which would give a small margin of error when it compares prices?

Cheers guys!

@Raychev_Rusl I think the AlmostEqual function will work for you. Also AmiBroker has many functions that you can use to help you round (up or down) to get the result you desire.

Some helpful forum posts with custom functions coded,


Hello again!

The RoundUp function worked like a charm! However, when I refresh the backtest, a deal still does not occur (even though now both the price and the lower/upper band are equal at least on the graph)

Any ideas on why this might be still happening?

The report charts link is quite useful but I am afraid it does not solve my issue as the only information that it gives me is that there is an open position (the strategy relies on always being invested in the market). The logic behind the strategy is pretty simple as it would execute only if the Open/Close/High/Low in a given bar is equal or bellow/above the Bband. Problem is that on a specific day that I am looking at, the price is equal to the Bband but instead executes it 30 minutes later when the price is bellow the Bband (in this case it enters at a better point but let's say that that's not the concern)

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