NexusFi: Find Your Edge


Home Menu

 





math.rounding question


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one max-td with 3 posts (1 thanks)
    2. looks_two Velocity with 2 posts (0 thanks)
    3. looks_3 zeller4 with 1 posts (1 thanks)
    4. looks_4 TAJTrades with 1 posts (1 thanks)
      Best Posters
    1. looks_one bukkan with 2 thanks per post
    2. looks_two TAJTrades with 1 thanks per post
    3. looks_3 zeller4 with 1 thanks per post
    4. looks_4 max-td with 0.3 thanks per post
    1. trending_up 6,819 views
    2. thumb_up 5 thanks given
    3. group 2 followers
    1. forum 6 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
 
max-td's Avatar
 max-td 
Frankfurt
 
Experience: Intermediate
Platform: NinjaTrader
Trading: FGBL 6E B4
Posts: 1,752 since Jun 2009
Thanks Given: 2,309
Thanks Received: 927

hi,
who knows how i make a rounding of an EMA to a wished format ie :

121.25 instead of 121.2469857...

i want to use my EMA-value in an indicator but want it rounded to 2 numbers behind the point - like 121.25 instead of 121.2469857
if i use an EMA in my chart it is always set to the ticksize of the instrument - but if i use it in an indicator the value is given in a long number.
i dont wanna transform it in a string - i need a double value.
any ideas ?
Thanks in advance.


max-td
Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
[WTS] ATAS Lifetime ULTRA license – EU buyers only – …
Platforms and Indicators
No book, only a stair: journaling fills where price move …
Cryptocurrency
My Rant with AMP Futures
Trading Reviews and Vendors
Bitcoin’s 2022 low, 2025 high and 2026 low so far arou …
Cryptocurrency
What we know about Binances $6.3bn hack - BBC News
Cryptocurrency
 
  #2 (permalink)
 zeller4 
Orlando Florida
 
Experience: Intermediate
Platform: NT8
Trading: CL, NQ, ES, RTY
Posts: 478 since Jun 2009
Thanks Given: 1,419
Thanks Received: 404

max,I normally just do this - not very elegant but it works for me...

kz

Print(Math.Round(doublevalue*
100)/100);


Reply With Quote
Thanked by:
  #3 (permalink)
 
max-td's Avatar
 max-td 
Frankfurt
 
Experience: Intermediate
Platform: NinjaTrader
Trading: FGBL 6E B4
Posts: 1,752 since Jun 2009
Thanks Given: 2,309
Thanks Received: 927


well - found an interesting way to do this in NT-forum :

double EMArounded = Math.Round(valueEMA*100)/100;

Round an integer to nearest 10 - NinjaTrader Support Forum

and hey ... there is a guy involved called cunparis


max-td
Started this thread Reply With Quote
  #4 (permalink)
 
Velocity's Avatar
 Velocity 
Bloomfield Hills, MI
 
Experience: Master
Platform: NinjaTrader / Neoticker
Trading: ES
Posts: 16 since Jun 2009
Thanks Given: 0
Thanks Received: 7

Multiply it by four, then round it, then divide it by four.


Reply With Quote
  #5 (permalink)
 bukkan 
Calcutta, India
 
Experience: Intermediate
Platform: ArthaChitra
Posts: 279 since Jun 2009
Thanks Given: 161
Thanks Received: 272

math.round(value,2)

where 2 represents 2 decimal places


Reply With Quote
Thanked by:
  #6 (permalink)
 
max-td's Avatar
 max-td 
Frankfurt
 
Experience: Intermediate
Platform: NinjaTrader
Trading: FGBL 6E B4
Posts: 1,752 since Jun 2009
Thanks Given: 2,309
Thanks Received: 927

bukkan - great!
tested >> works too
and its the most elegant way i would say !

Very nice solution also for further codings.


max-td
Started this thread Reply With Quote
Thanked by:
  #7 (permalink)
TAJTrades
Here, GA
 
Posts: 158 since Jun 2009
Thanks Given: 1
Thanks Received: 87

You may want to consider using Round2TickSize. It can be used on more than just price. It will round any number to the nearest Instrument Tick Size. For example if the indicator is placed on an ES chart the ES Tick Size is .25. So using this example will round any number to the nearest .25. There may be some issues doing it this way but I have not found them.

Indicator.Set(Instrument.MasterInstrument.Round2TickSize(value to be rounded);


Reply With Quote
Thanked by:




Last Updated on July 29, 2009


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts