Functions
strategy.opentrades_profit()
For the open trade number `trade_num`, returns the current, unrealised profit of the trade, in the account currency; a loss is negative. Trades are numbered from 0 in the order they were opened, so the most recent is `strategy.opentrades - 1`.
Syntax
strategy.opentrades_profit(series int trade_num) → series float
Arguments
trade_num required series int Return Type
series float Example
//@lipi=2
strategy("strategy.opentrades_profit Example", overlay=true, initial_capital=10000, default_qty_type=strategy.fixed, default_qty_value=1)
if talib.crossover(close, talib.sma(close, 20)) {
strategy.entry("Long", strategy.long)
}
if talib.crossunder(close, talib.sma(close, 20)) {
strategy.close("Long")
}
value = strategy.opentrades > 0 ? strategy.opentrades_profit(strategy.opentrades - 1) : na
plot(value, title="Profit", color=color.blue)