PnL label my attempt to create label from strategy report so far not successful
# Define the strategy
input length = 14;
def price = close;
def avg = Average(price, length);
# Buy signal
AddOrder(OrderType.BUY_AUTO, price crosses above avg, open[-1], 100, Color.GREEN, Color.GREEN);
# Sell signal
AddOrder(OrderType.SELL_AUTO, price crosses below avg, open[-1], 100, Color.RED, Color.RED);
# Calculate the PnL for each trade
def entryPrice = if !IsNaN(EntryPrice()) then EntryPrice() else entryPrice[1]repo;
def exitPrice = if !IsNaN(ExitPrice()) then ExitPrice() else exitPrice[1];
def tradePnL = if !IsNaN(exitPrice) then (exitPrice - entryPrice) * 100 else 0;
# Sum up the PnL for all trades
def totalPnL = TotalSum(tradePnL);
# Add a label to display the total PnL
AddLabel(yes, "Strategy PnL: $" + totalPnL, if totalPnL >= 0 then Color.GREEN else Color.RED);
I am wondering if a label can be coded from the strategy trading reports
# Define the strategy
input length = 14;
def price = close;
def avg = Average(price, length);
# Buy signal
AddOrder(OrderType.BUY_AUTO, price crosses above avg, open[-1], 100, Color.GREEN, Color.GREEN);
# Sell signal
AddOrder(OrderType.SELL_AUTO, price crosses below avg, open[-1], 100, Color.RED, Color.RED);
# Calculate the PnL for each trade
def entryPrice = if !IsNaN(EntryPrice()) then EntryPrice() else entryPrice[1]repo;
def exitPrice = if !IsNaN(ExitPrice()) then ExitPrice() else exitPrice[1];
def tradePnL = if !IsNaN(exitPrice) then (exitPrice - entryPrice) * 100 else 0;
# Sum up the PnL for all trades
def totalPnL = TotalSum(tradePnL);
# Add a label to display the total PnL
AddLabel(yes, "Strategy PnL: $" + totalPnL, if totalPnL >= 0 then Color.GREEN else Color.RED);
I am wondering if a label can be coded from the strategy trading reports
Last edited by a moderator: