#FloatFLLine - Updated P&L to include additional stats label.
#Original TD Ameritrade - FloatingPL
#Updated 2019.10.20 - diazlaz - Additional Stats Label
# - Incorporated Nube's and JQ's BnH Logic
#
declare lower;
input ProfileLine = 1200;
input TradeSize = 1000;
input TradeAmount = 100000;
input useTradeAmount = no;
input ProfileDesc = "T";
input ShowShareCount = No;
AddLabel(yes, ProfileDesc, COLOR.ORANGE);
def TradeSize2 = CompoundValue(1, Round(TradeAmount / close, 0), 0);
AddLabel(ShowShareCount, "Number Of Shares: " + if useTradeAmount then astext(TradeSize2) else astext(TradeSize) + " at " + AsText(close), Color.WHITE);
plot FPL = FPL();
plot ZeroLine = 0;
plot TargetLine = ProfileLine;
TargetLine.SetDefaultColor(Color.YELLOW);
TargetLine.SetLineWeight(3);
FPL.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
FPL.DefineColor("Positive and Up", Color.GREEN);
FPL.DefineColor("Positive and Down", Color.DARK_GREEN);
FPL.DefineColor("Negative and Down", Color.RED);
FPL.DefineColor("Negative and Up", Color.DARK_RED);
FPL.AssignValueColor(if FPL >= 0 then if FPL > FPL[1] then FPL.Color("Positive and Up") else FPL.Color("Positive and Down") else if FPL < FPL[1] then FPL.Color("Negative and Down") else FPL.Color("Negative and Up"));
ZeroLine.SetDefaultColor(Color.GRAY);
def ProfitState = CompoundValue(1, if FPL >= ProfileLine then 1 else ProfitState[1], 0);
def ProfitCount = CompoundValue(1, if FPL >= ProfileLine then ProfitCount[1] + 1 else ProfitCount[1], 0);
plot pLongBuy = (ProfitState[1] != ProfitState);
pLongBuy.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
pLongBuy.SetDefaultColor(Color.WHITE);
pLongBuy.SetLineWeight(5);
def BnH = close - First(open);
def returnColor = if BnH crosses above BnH[1] then 1 else
if BnH crosses below BnH[1] then 0 else returnColor[1];
def BHPnL = TickValue() * (1 / TickSize()) * BnH;
AddLabel (yes, "Profit Touch: " + ProfitCount, Color.YELLOW);
AddLabel (yes, "P&L: " + AsDollars(FPL),
if FPL >= 0 then if FPL > FPL[1] then FPL.Color("Positive and Up") else FPL.Color("Positive and Down") else if FPL < FPL[1] then FPL.Color("Negative and Down") else FPL.Color("Negative and Up"));
AddLabel (yes, "%: " + AsPercent(FPL / TradeAmount), Color.CYAN);
AddLabel (yes, "Low: " + LowestAll(FPL), Color.Pink);
AddLabel (yes, "Max: " + HighestAll(FPL), Color.Lime);
AddLabel (yes, "Buy and Hold PL: " + AsDollars(BHPnL * TradeSize), Color.Gray);
AddLabel (yes, "BH%: " + AsPercent(BHPnL / TradeAmount), Color.Gray);
#end of FloatFLLine