Rounding to nearest 5  [SOLVED]

Questions about MultiCharts and user contributed studies.
creditrust
Posts: 1
Joined: 25 Jun 2010
Location: Seattle, Washington

Rounding to nearest 5  [SOLVED]

Postby creditrust » 01 Sep 2013

I am trying to round the close to the nearest 5. For example if the close was 834.25 the formula should return 835, if the close is 42.12 the return should be 40. I have tried the GenerateStrike function but it does not seem to work or I am not using it properly and the Round function only rounds to the nearest 1. This should be simple but I am having a hard time with this, any help is appreciated.

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Rounding to nearest 5

Postby TJ » 01 Sep 2013

I am trying to round the close to the nearest 5. For example if the close was 834.25 the formula should return 835, if the close is 42.12 the return should be 40. I have tried the GenerateStrike function but it does not seem to work or I am not using it properly and the Round function only rounds to the nearest 1. This should be simple but I am having a hard time with this, any help is appreciated.
Are you trading options?
What are the rules for rounding up or down?

Xyzzy
Posts: 162
Joined: 19 Mar 2011
Has thanked: 43 times
Been thanked: 79 times

Re: Rounding to nearest 5

Postby Xyzzy » 01 Sep 2013

Try this:

Code: Select all

Value1 = Round(Close / 5, 0) * 5;
Print (Close:10:2, Value1:10:2);
It returned the following values for a sample symbol:
465.25 465.00
464.98 465.00
461.01 460.00
454.45 455.00
467.36 465.00
489.57 490.00
498.50 500.00
497.91 500.00
502.33 500.00
507.74 510.00
501.07 500.00
502.36 500.00
502.96 505.00
501.02 500.00
502.97 505.00
488.59 490.00
490.90 490.00
491.70 490.00
487.22 485.00


Return to “MultiCharts”