poStrategyLibrary
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © payam_omrani

//@version=5

// @description essential function for export
library("poStrategyLibrary")


export isFlat() =>
    strategy.position_size == 0
    
export isLongShort() =>
    strategy.position_size != 0

export pipProfit() =>
    entryPrice      = strategy.opentrades.entry_price(0)
    profitByUSD     = strategy.opentrades.profit(0)
    pipValue        = strategy.opentrades.size(0) * syminfo.mintick * 10
    if(strategy.position_size < 0)
        if(profitByUSD / pipValue < 0)
            math.abs(profitByUSD / pipValue)
    else
        profitByUSD / pipValue
    

export pipLoss() =>
    entryPrice      = strategy.opentrades.entry_price(0)
    profitByUSD     = strategy.opentrades.profit(0)
    pipValue        = strategy.opentrades.size(0) * syminfo.mintick * 10
    if(strategy.position_size > 0)
        if(profitByUSD / pipValue < 0)
            math.abs(profitByUSD / pipValue)
    else
        profitByUSD / pipValue
        
    
export usdProfit() =>
    profitByUSD     = strategy.opentrades.profit(0)


export usdLoss() =>
    profitByUSD     = strategy.opentrades.profit(0)
    if(strategy.position_size > 0)
        if(profitByUSD < 0)
            math.abs(profitByUSD)
    else
        profitByUSD


