Cut/ round digits after comma

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #86713 quote
    YvesYves
    Participant
    Junior

    Hi guys, i hope somebody can help me with the following issue.

    I wrote a little lot size calculator for my chart. The problem is i just want to get 2 digits after comma instead of 4. I tried a lot of different workarounds like “a=round(mashort*100)/100” and other calculations but nothing works for me.

     

     

    thanks in advance!

     

    // Risk/Trade
    risk = 150
     
     
    // currval = Accountcurrency / Tradingcurrency -> Trade USDCAD -> EUR / CAD (*10 for standard Lot)
    Currval = 6.57
     
    value = 0
    atr = AverageTrueRange[5](close)*10000
    size = 0
     
     
    If atr > 100 then
    value = round(atr/100+0.5)
    else
    value = round(atr+0.5)
    endif
     
     
    // size =risk/(value*currval)
    size = round(risk/(value*currval)*100)/100
     
     
    return size as "LOT"
    
    Size-Calculator-1.jpg Size-Calculator-1.jpg
    #86722 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    PRT does not allow to set a custom number of digits, so the only available option is to round numbers like you did!

    #86731 quote
    VonasiVonasi
    Moderator
    Master

    You could do something like this and return the value as an text indicator of its own:

    defparam calculateonlastbars = 1
    
    // Risk/Trade
    risk = 150
     
     
    // currval = Accountcurrency / Tradingcurrency -> Trade USDCAD -> EUR / CAD (*10 for standard Lot)
    Currval = 6.57
     
    value = 0
    atr = AverageTrueRange[5](close)*10000
    size = 0
     
     
    If atr > 100 then
    value = round(atr/100+0.5)
    else
    value = round(atr+0.5)
    endif
     
     
    // size =risk/(value*currval)
    size = round(risk/(value*currval)*100)/100
     
    drawtext("#size#",barindex,0) coloured(0,0,0)
     
    return
    Yves thanked this post
    #86820 quote
    YvesYves
    Participant
    Junior

    good idea, i think that works! thx!

    #88209 quote
    FrankyboyFrankyboy
    Participant
    Average

    Question: Is it necessary to have PorOrder round calculated lot sizes or are they automatically adjusted/rounded upon position entry with IG? Does anybody know?

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Cut/ round digits after comma


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Yves @yves_emm Participant
Summary

This topic contains 4 replies,
has 4 voices, and was last updated by FrankyboyFrankyboy
7 years, 8 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 12/10/2018
Status: Active
Attachments: 1 files
ProRealCode ProRealCode
Loading...