Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    How to convert pips to price?

    General Code/Help
    2
    5
    160
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T H
      T H last edited by

      Is it possible to convert pips to price in bt?
      Thanks.

      1 Reply Last reply Reply Quote 0
      • D
        dasch last edited by

        you need to know the pip location. the pip location says, where pips are after comma, for EUR_USD it would be 4. below you have two functions to calculate the price diff from pips and pips from a value.

            def get_pips_from_value(value, pip_location, precision=0):
                ''' Returns pips from a value '''
                div = float(10 ** pip_location)
                pips = value / div
                return round(pips, precision)
        
            def get_value_from_pips(pips, pip_location):
                ''' Returns price diff from pips '''
                mult = float(10 ** pip_location)
                return float(pips * mult)
        
        T H 1 Reply Last reply Reply Quote 2
        • T H
          T H @dasch last edited by

          @dasch Thanks for your reply!
          For example, in MQL (the language of MetaTrader), you can get the decimal point position for each currency.

          int digits = (int)MarketInfo(Symbol(), MODE_DIGITS);
          

          Are there any similar features in bt?

          1 Reply Last reply Reply Quote 0
          • D
            dasch last edited by

            this would be a broker specific functionality. for oanda, you can get the pip location by checking the contractdetails dict of the feed. backtrader itself will not have this information available. but you could extract that information by looking for digits after the comma.

            Example for Oanda:

            data.contractdetails["pipLocation"]
            
            T H 1 Reply Last reply Reply Quote 1
            • T H
              T H @dasch last edited by

              @dasch Awesome!This is exactly the thing I wanted!
              I can never thank you enough.

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors