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?



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



  • 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)
    


  • @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?



  • 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"]
    


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


Log in to reply
 

});