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

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

Another example

Required result would b

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:


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() - (rounding up)

ceil( number )

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

Also searched - (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
BuyOffer = (Close+Close*0.03);
AddColumn(BuyOffer,"BUYOffer..",1.3,IIf(Buy,colorWhite,colorWhite),IIf(BuySetUp > 0,colorGreen,colordefault));



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

BuyOffer = Close * 1.03;
//AddColumn( BuyOffer, "Buy Offer 1 ", 1.3, colorWhite, colorGreen );
AddColumn( ceil( BuyOffer * 100 ) / 100, "Buy Offer 2", 1.2, colorWhite, colorGreen );



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

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 :slight_smile:



Hi Milosz

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


AddColumn(Close, "Close", 1.2, IIf(BuySetUp > 0, colorBlack, colorWhite));
PercentChg = ((C - Ref(C, -1))/Ref(C, -1))*100; 
AddColumn(PercentChg, "Percent UP", 1.2,IIf(BuySetUp > 0, colorGreen, colorWhite)); 
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


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


1 Like

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