# Profit & Loss Label (on a cost adjusted basis)
# @merryday 2/2023
input PLMode = ProfitLossMode.COST_BASIS;
def PL = GetOpenPL(profitLossMode = PLMode) ;
def Entry = if GetAveragePrice() != 0 then GetAveragePrice() else Entry[1];
def GainLoss = if PL != 0 then PL else GainLoss[1];
def Qty = if GetQuantity() != 0 then GetQuantity() else Qty[1];
DefineGlobalColor("Gain", CreateColor(0, 165, 0)) ;
DefineGlobalColor("Loss", CreateColor(225, 0, 0)) ;
AddLabel(GainLoss,
"Qty: " + Qty + " Entry/shr $" + Entry + " Exit/shr $" + (Entry+GainLoss)
+ " | Total Purchase: " +Qty*Entry + " Total Sale: " +Qty*(Entry+GainLoss)
+" | P/L: " + AsDollars(GainLoss*Qty),
if GainLoss > 0 then GlobalColor("Gain") else GlobalColor("Loss"));