# Rounding to uniform integers

I would like to ask how can I round the close prices to nearest tens. For example suppose the closing prices are

100.2, 99.8, 95, 101, 104.9

I want to round the prices as
100,100,100,100,100

That is any price above 5 will rounded to the next 10s.

Another example
94.9,92.1,93,91.2,94.....

Required result would b
90,90,90,90,90

How can I achieve this, anybody know?

AFL provides standard rounding functions:

ALL kind of rounding can be done using these functions. If you want to round to 10, divide and multiply:

``````roundtoten = 10 * round( value / 10 );
``````

Also it is very easy to find existing answers using SEARCH function: https://forum.amibroker.com/search?q=rounding

8 Likes

Thank you very much for the solution. Could you please tell how I can find the same High or low price candle. For example suppose in the chart there are candles with same high prices ie 90,89,88,90,87.8,90,91,90
among the above high prices I would like to pick up the rate with more than 3 occurrence with same rate. That is, in this case candle with high price 90 is the answer.

After doing a scan I would prefer the "BuyOffer Column" to round up - help in doing this would be appreciated (I'm at a loss where to place the code referenced below)
ceil() - http://www.amibroker.com/f?ceil (rounding up)

Searched REFERENCES
http://www.amibroker.com/guide/afl/ceil.html
ceil( number )
ceil()

Tomasz reference post - But I'm at a loss where to place this rounding function

Also searched - https://forum.amibroker.com/search?q=rounding (I'm Stumped)

WHAT I'm trying to achieve

1. The buy price to round up to two decimal places in the BuyOffer Column

WHAT I want to avoid

1. Displaying the buy price to 3 decimal places than manually rounding this buy price up to two decimal places

MY current CODE

Skate

@skate, you can use a code similar to this one:

``````BuyOffer = Close * 1.03;
``````

4 Likes

Hi Milosz

Thank you for the fixing my code.

Sometimes you forget how wonderful it feels when others help.

Your quick fix solved many days of frustration for me (it was more like weeks of frustration to be honest - I was going in circles)

Thanks again
Skate

1 Like

Phil, I'm glad that it worked for you, but it is not my fix. I only implemented the ideas provided by Tomasz (in this thread) and Fxshrat in the thread I have referenced in my reply

Regards

2 Likes

Hi Milosz

WHAT I'M TRYING TO ACHIEVE
I'm seeking to combine two columns into one column, but this is elusive for me to accomplish.

CODE USED

``````AddColumn(Close, "Close", 1.2, IIf(BuySetUp > 0, colorBlack, colorWhite));
PercentChg = ((C - Ref(C, -1))/Ref(C, -1))*100;
AddColumn(PercentChg, "Percent DN", 1.2,IIf(TrailStopEx==1 > 0,colorRed, colorwhite));
``````

I'm trying to eliminate one column - instead of having a [Percentage Up] column and a [Percentage DN] column I would rather have one column [Percentage Change] Column.

Iv'e written the code so only numbers appear when there is either a Buy or Sell in the adjacent [Buy] or [Sell] Columns otherwise the cell should appear blank (which it isn't - its just white number on a white background giving the appearance of an empty cell)

This is another annoying issue I can't solve to give the desired results. Two columns are quite ok, but it would be more desirable to have only one column.

The Red & Green cell entries will denote if the percentage change was up or down.

Hoping this can be done

Skate

``````AddColumn(PercentChg, "% Chg", 1.2,IIf(BuySetUp > 0, colorGreen, IIf(TrailStopEx==1 > 0, colorRed, colorwhite)));
``````
1 Like

Works perfectly, just what I wanted.

Thanks Fossil

Skate

1 Like

3 posts were split to a new topic: Computers work with binary numbers, not decimals