TradableUtilities
@objc public class TradableUtilities: NSObject
A helper class providing methods for easy price/pip conversion and more.
-
Converts a price distance to a pip distance.
Throws
TradableUtilitiesError.unsupportedInstrument if there is no possibility of making conversion for specified instrument.
Declaration
Swift
public static func convertToPipDistance(_ priceDistance: Double, for instrument: TradableInstrument) throws -> DoubleParameters
priceDistanceThe price distance to be converted.
instrumentThe instrument for which the conversion should be made.
Return Value
A distance in pips.
-
Converts a difference between two prices to a pip distance.
Throws
TradableUtilitiesError.unsupportedInstrument if there is no possibility of making conversion for specified instrument.
Declaration
Swift
public static func getPipDistance(between lowerPrice: Double, and higherPrice: Double, for instrument: TradableInstrument) throws -> DoubleParameters
lowerPriceThe lower price to be used in conversion.
higherPriceThe higher price to be used in conversion.
instrumentThe instrument for which the conversion should be made.
Return Value
A distance in pips.
-
Converts a pip distance to a price distance.
Throws
TradableUtilitiesError.unsupportedInstrument if there is no possibility of making conversion for specified instrument.
Declaration
Swift
public static func convertToPriceDistance(_ pipDistance: Double, for instrument: TradableInstrument) throws -> DoubleParameters
pipDistanceThe pip distance to be converted.
instrumentThe instrument for which the conversion should be made.
Return Value
A price distance.
-
Calculates a price from a price given a pip distance.
Throws
TradableUtilitiesError.unsupportedInstrument if there is no possibility of making conversion for specified instrument.
Declaration
Swift
public static func getPrice(with distance: Double, from price: Double, for instrument: TradableInstrument) throws -> DoubleParameters
distanceThe pip distance to be added.
priceThe price to which the pip distance should be added.
instrumentThe instrument for which the conversion should be made.
Return Value
A price.
-
Calculates a profit or loss in whole pips.
Throws
TradableUtilitiesError.unsupportedInstrument if there is no possibility of making conversion for specified instrument.
Declaration
Swift
public static func getProfitLossInPips(between openPrice: Double, and currentPrice: Double, for instrument: TradableInstrument) throws -> IntParameters
openPriceThe price from which the PnL in pips should be calculated.
currentPriceThe price for which the PnL in pips should be calculated.
instrumentThe instrument for which the conversion should be made.
Return Value
A PnL value in whole pips.
View on GitHub
TradableUtilities Class Reference