Profit and Loss Labels

Platform
  1. Thinkorswim
i have a profit and loss labels , it is very helpful, but i will like to use on any system to see the if the system is good or not, but i dont know how to add it into a system, here i will leave the code for the profit and loss labels and also the system i will like to test it. thank you in advance!

here is the code for the profit and loss labels:

Code:
###------------------------------------------------------------------------------------------
# Profit and Loss Labels
#
# Fill in the 0>0 in the Create Signals section below to match your buy and sell signal conditions
#
# When using large amounts of hisorical data, P/L may take time to calculate
###------------------------------------------------------------------------------------------

input showSignals = yes; #hint showSignals: show buy and sell arrows
input LongTrades = yes; #hint LongTrades: perform long trades
input ShortTrades = yes; #hint ShortTrades: perform short trades
input LabelsOn = yes;
input showLabels  = yes; #hint showLabels: show PL labels at top
input showBubbles = yes; #hint showBubbles: show PL bubbles at close of trade
input useStops = no;     #hint useStops: use stop orders
input useAlerts = no;    #hint useAlerts: use alerts on signals
input tradeDaytimeOnly = no; #hint tradeDaytimeOnly: (IntraDay Only) Only perform trades during hours stated
input OpenTime = 0930; #hint OpenTime: Opening time of market
input CloseTime = 1600; #hint CloseTime: Closing time of market


def Begin = SecondsFromTime(OpenTime);
def End = SecondsTillTime(CloseTime);
# Only use market hours when using intraday timeframe
def isIntraDay = if GetAggregationPeriod() > 14400000 or GetAggregationPeriod() == 0 then 0 else 1;
def MarketOpen = if !tradeDaytimeOnly or !isIntraDay then 1 else if tradeDaytimeOnly and isIntraDay and Begin > 0 and End > 0 then 1 else 0;
###------------------------------------------------------------------------------------------

######################################################
##  Create Signals -
##  FILL IN THIS SECTION
##      replace 0>0 with your conditions for signals
######################################################

def PLBuySignal = if  MarketOpen and (upsignal) then 1 else 0 ; # insert condition to create long position in place of the 0>0
def PLSellSignal =  if MarketOpen and (downsignal) then 1 else 0; # insert condition to create short position in place of the 0>0

def PLBuyStop  = if !useStops then 0 else if  (0 > 0) then 1 else 0  ; # insert condition to stop in place of the 0<0
def PLSellStop = if !useStops then 0 else if (0 > 0) then 1 else 0  ; # insert condition to stop in place of the 0>0

def PLMktStop = if MarketOpen[-1] == 0 then 1 else 0; # If tradeDaytimeOnly is set, then stop at end of day


#######################################
##  Maintain the position of trades
#######################################

def CurrentPosition;  # holds whether flat = 0 long = 1 short = -1

if (BarNumber() == 1) or IsNaN(CurrentPosition[1]) {
    CurrentPosition = 0;
} else {
    if CurrentPosition[1] == 0 {            # FLAT
        if (PLBuySignal and LongTrades) {
            CurrentPosition = 1;
        } else if (PLSellSignal and ShortTrades) {
            CurrentPosition = -1;
        } else {
            CurrentPosition = CurrentPosition[1];
        }
    } else if CurrentPosition[1] == 1 {      # LONG
        if (PLSellSignal and ShortTrades) {
            CurrentPosition = -1;
        } else if ((PLBuyStop and useStops) or PLMktStop or (PLSellSignal and ShortTrades == 0)) {
            CurrentPosition = 0;
        } else {
            CurrentPosition = CurrentPosition[1];
        }
    } else if CurrentPosition[1] == -1 {     # SHORT
        if (PLBuySignal and LongTrades) {
            CurrentPosition = 1;
        } else if ((PLSellStop and useStops) or PLMktStop or (PLBuySignal and LongTrades == 0)) {
            CurrentPosition = 0;
        } else {
            CurrentPosition = CurrentPosition[1];
        }
    } else {
        CurrentPosition = CurrentPosition[1];
    }
}


def isLong  = if CurrentPosition == 1 then 1 else 0;
def isShort = if CurrentPosition == -1 then 1 else 0;
def isFlat  = if CurrentPosition == 0 then 1 else 0;

# If not already long and get a PLBuySignal
#Plot BuySig = if (!isLong[1] and PLBuySignal and showSignals and LongTrades) then 1 else 0;
plot BuySig = if (((isShort[1] and LongTrades) or (isFlat[1] and LongTrades)) and PLBuySignal and showSignals) then 1 else 0;
BuySig.AssignValueColor(Color.CYAN);
BuySig.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
BuySig.SetLineWeight(5);

#Alert(BuySig and useAlerts, "Buy Signal", Alert.BAR, Sound.Ding);
#Alert(BuySig and useAlerts, "Buy Signal", Alert.BAR, Sound.Ding);

# If not already short and get a PLSellSignal
plot SellSig = if (((isLong[1] and ShortTrades) or (isFlat[1] and ShortTrades)) and PLSellSignal and showSignals) then 1 else 0;
SellSig.AssignValueColor(Color.CYAN);
SellSig.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
SellSig.SetLineWeight(5);

#Alert(SellSig and useAlerts, "Sell Signal", Alert.BAR, Sound.Ding);
#Alert(SellSig and useAlerts, "Sell Signal", Alert.BAR, Sound.Ding);

# If long and get a PLBuyStop
plot BuyStpSig = if (PLBuyStop and isLong[1] and showSignals and useStops) or (isLong[1] and PLMktStop) or (isLong[1] and PLSellSignal and !ShortTrades) then 1 else 0;
BuyStpSig.AssignValueColor(Color.LIGHT_GRAY);
BuyStpSig.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
BuyStpSig.SetLineWeight(3);

#Alert(BuyStpSig and useAlerts, "Buy Stop Signal", Alert.BAR, Sound.Ding);
#Alert(BuyStpSig and useAlerts, "Buy Stop Signal", Alert.BAR, Sound.Ding);


# If short and get a PLSellStop
plot SellStpSig = if (PLSellStop and isShort[1] and showSignals and useStops) or (isShort[1] and PLMktStop) or (isShort[1] and PLBuySignal and !LongTrades) then 1 else 0;
SellStpSig.AssignValueColor(Color.LIGHT_GRAY);
SellStpSig.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
SellStpSig.SetLineWeight(3);

#Alert(SellStpSig and useAlerts, "Sell Stop Signal", Alert.BAR, Sound.Ding);
#Alert(SellStpSig and useAlerts, "Sell Stop Signal", Alert.BAR, Sound.Ding);


#######################################
##  Orders
#######################################

def isOrder = if ((isFlat[1] and (BuySig and LongTrades) or (SellSig and ShortTrades)) or (isLong[1] and BuyStpSig or (SellSig and ShortTrades)) or (isShort[1] and SellStpSig or (BuySig and LongTrades))) then 1 else 0 ;
# If there is an order, then the price is the next days close
def orderPrice = if (isOrder and ((BuySig and LongTrades) or (SellSig and ShortTrades))) then close else orderPrice[1];

def orderCount = CompoundValue(1, if IsNaN(isOrder) or BarNumber() == 1 then 0 else if (BuySig or SellSig) then orderCount[1] + 1 else orderCount[1], 0);


#######################################
##  Price and Profit
#######################################

def profitLoss;


if (!isOrder or orderPrice[1] == 0) {
    profitLoss = 0;
} else if ((isOrder and isLong[1]) and (SellSig or BuyStpSig)) {
    profitLoss = close - orderPrice[1];
} else if ((isOrder and isShort[1]) and (BuySig or SellStpSig)) {
    profitLoss = orderPrice[1] - close;
} else {
    profitLoss = 0;
}


# Total Profit or Loss
def profitLossSum = CompoundValue(1, if IsNaN(isOrder)  or BarNumber() == 1 then 0 else if isOrder then profitLossSum[1] + profitLoss else profitLossSum[1], 0);

# How many trades won or lost
def profitWinners = CompoundValue(1, if IsNaN(profitWinners[1]) or BarNumber() == 1 then 0 else if isOrder and profitLoss > 0 then profitWinners[1] + 1 else profitWinners[1], 0);
def profitLosers = CompoundValue(1, if IsNaN(profitLosers[1])  or BarNumber() == 1 then 0 else if isOrder and profitLoss < 0 then profitLosers[1] + 1 else profitLosers[1], 0);
def profitPush = CompoundValue(1, if IsNaN(profitPush[1])  or BarNumber() == 1 then 0 else if isOrder and profitLoss == 0 then profitPush[1] + 1 else profitPush[1], 0);

# Current Open Trade Profit or Loss
def TradePL = if isLong then Round(((close - orderPrice) / TickSize()) * TickValue()) else if isShort then Round(((orderPrice - close) / TickSize()) * TickValue()) else 0;

# Convert to actual dollars based on Tick Value for bubbles
def dollarProfitLoss = if orderPrice[1] == 0 or IsNaN(orderPrice[1]) then 0 else Round((profitLoss / TickSize()) * TickValue());

# Closed Orders dollar P/L
def dollarPLSum = Round((profitLossSum / TickSize()) * TickValue());


# Split profits or losses by long and short trades
def profitLong = CompoundValue(1, if IsNaN(profitLong[1])  or BarNumber() == 1 then 0 else if isOrder and isLong[1] then profitLong[1] + dollarProfitLoss else profitLong[1], 0);
def profitShort = CompoundValue(1, if IsNaN(profitShort[1])  or BarNumber() == 1 then 0 else if isOrder and isShort[1] then profitShort[1] + dollarProfitLoss else profitShort[1], 0);
def countLong = CompoundValue(1, if IsNaN(countLong[1])  or BarNumber() == 1 then 0 else if isOrder and isLong[1] then countLong[1] + 1 else countLong[1], 0);
def countShort = CompoundValue(1, if IsNaN(countShort[1])  or BarNumber() == 1 then 0 else if isOrder and isShort[1] then countShort[1] + 1 else countShort[1], 0);

# What was the biggest winning and losing trade
def biggestWin = CompoundValue(1, if IsNaN(biggestWin[1]) or BarNumber() == 1 then 0 else if isOrder and (dollarProfitLoss > 0) and (dollarProfitLoss > biggestWin[1]) then dollarProfitLoss else biggestWin[1], 0);
def biggestLoss = CompoundValue(1, if IsNaN(biggestLoss[1]) or BarNumber() == 1 then 0 else if isOrder and (dollarProfitLoss < 0) and (dollarProfitLoss < biggestLoss[1]) then dollarProfitLoss else biggestLoss[1], 0);

def ClosedTradeCount = if (isLong or isShort) then orderCount - 1 else orderCount;
def OpenTrades = if (isLong or isShort) then 1 else 0;


# What percent were winners
def PCTWin = if (OpenTrades and (TradePL < 0)) then Round((profitWinners / (ClosedTradeCount + 1)) * 100, 2)
else if (OpenTrades and (TradePL > 0)) then Round(((profitWinners + 1) / (ClosedTradeCount + 1)) * 100, 2) else Round(((profitWinners) / (ClosedTradeCount)) * 100, 2) ;

# Average trade
def avgTrade = if (OpenTrades and (TradePL < 0)) then Round(((dollarPLSum - TradePL) / (ClosedTradeCount + 1)), 2)
else if (OpenTrades and (TradePL > 0)) then Round(((dollarPLSum + TradePL) / (ClosedTradeCount + 1)), 2) else Round(((dollarPLSum) / (ClosedTradeCount)), 2) ;


#######################################
##  Create Labels
#######################################


#AddLabel(showLabels and isIntraDay, if MarketOpen then "Market Open" else "Market Closed", Color.WHITE);
#AddLabel(showLabels, GetSymbol() + " Tick Size: " + TickSize() + " Value: " + TickValue(), Color.WHITE);
#AddLabel(showLabels and (LongTrades and ShortTrades), "Long+Short Trades", Color.WHITE);
AddLabel(showLabels and (LongTrades and !ShortTrades), "Long Trades Only", Color.WHITE);
AddLabel(showLabels and (!LongTrades and ShortTrades), "Short Trades Only", Color.WHITE);
AddLabel(showLabels, "Closed Orders: " + ClosedTradeCount + " P/L: " + AsDollars(dollarPLSum), if dollarPLSum > 0 then Color.GREEN else if dollarPLSum < 0 then Color.RED else Color.GRAY);
AddLabel(if !IsNaN(orderPrice) and showLabels then 1 else 0, "Closed+Open P/L: " + AsDollars(TradePL + dollarPLSum), if ((TradePL + dollarPLSum) > 0) then Color.GREEN else if ((TradePL + dollarPLSum) < 0) then Color.RED else Color.GRAY);

AddLabel(showLabels, "Avg per Trade: " + AsDollars(avgTrade), if avgTrade > 0 then Color.GREEN else if avgTrade < 0 then Color.RED else Color.GRAY);
AddLabel(showLabels, "Winners: " + PCTWin + "%", if PCTWin > 50 then Color.GREEN else if PCTWin > 40 then Color.YELLOW else Color.GRAY);

AddLabel(showLabels, "MaxUp: " + AsDollars(biggestWin) + " MaxDown: " + AsDollars(biggestLoss), Color.WHITE);
AddLabel(showLabels, "Long Profit: " + AsDollars(profitLong), if profitLong > 0 then Color.GREEN else if profitLong < 0 then Color.RED else Color.GRAY);
AddLabel(showLabels, "Short Profit: " + AsDollars(profitShort), if profitShort > 0 then Color.GREEN else if profitShort < 0 then Color.RED else Color.GRAY);
AddLabel(if !IsNaN(CurrentPosition) and showLabels and OpenTrades then 1 else 0, "Open: " + (if isLong then "Bought" else "Sold") + " @ " + orderPrice, Color.WHITE);
AddLabel(if !IsNaN(orderPrice) and showLabels and OpenTrades then 1 else 0, "Open Trade P/L: " + AsDollars(TradePL), if (TradePL > 0) then Color.GREEN else if (TradePL < 0) then Color.RED else Color.GRAY);
AddLabel(showLabels, "Profit Percentile: " + aspercent(TradePL/BiggestWin), if (TradePL > 0) then Color.GREEN else if (TradePL < 0) then Color.RED else Color.GRAY);;
#######################################
##  Chart Bubbles for Profit/Loss
#######################################
AddChartBubble(showSignals and showBubbles and isOrder and isLong[1], low, "$" + dollarProfitLoss, if dollarProfitLoss == 0 then Color.LIGHT_GRAY else if dollarProfitLoss > 0 then Color.GREEN else Color.RED, 0);
AddChartBubble(showSignals and showBubbles and isOrder and isShort[1], high,  "$" + dollarProfitLoss, if dollarProfitLoss == 0 then Color.LIGHT_GRAY else if dollarProfitLoss > 0 then Color.GREEN else Color.RED, 1);

#######################################
#Assign Price Color
#######################################
def Ceiling = biggestWin;
def Floor = biggestLoss;
def MidCAT = (((biggestWin + avgTrade) / 2) + avgTrade) / 2;
def MidFAT = (((biggestLoss + avgTrade) / 2) + avgTrade) / 2;
def AvgProfitWinners = (((profitWinners) / (ClosedTradeCount + 1)));
input mult = 50;

########################################
##Long Stop
########################################
def LongStop = if (BuySig) then low else Double.NaN;
def LongStopext = if (IsNaN(LongStop) and isLong) then LongStopext[1] else LongStop;
plot LongStopextline = LongStopext;
LongStopextline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LongStopextline.SetDefaultColor(Color.ORANGE);
LongStopextline.SetLineWeight(2);

########################################
##Long Targets
########################################
plot LongEntry = if isLong then (orderPrice) else Double.NaN;
LongEntry.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LongEntry.SetDefaultColor(Color.GREEN);
LongEntry.SetLineWeight(2);

plot AvgProfitLL = if isLong then (orderPrice + ((dollarPLSum) / (ClosedTradeCount) / mult)) else Double.NaN;
AvgProfitLL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
AvgProfitLL.SetDefaultColor(Color.WHITE);
AvgProfitLL.SetLineWeight(1);

def LT1 = if isLong then (((biggestWin * .13) / mult) + orderPrice) else Double.NaN;
def LT1ext = if (IsNaN(LT1) and isLong) then LT1ext[1] else LT1;
plot LT1extline = LT1ext;
LT1extline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LT1extline.SetDefaultColor(Color.GRAY);
LT1extline.SetLineWeight(1);

def LT2 = if isLong then (((biggestWin * .236) / mult) + orderPrice) else Double.NaN;
def LT2ext = if (IsNaN(LT2) and isLong) then LT2ext[1] else LT2;
plot LT2extline = LT2ext;
LT2extline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LT2extline.SetDefaultColor(Color.GRAY);
LT2extline.SetLineWeight(1);

def LT3 = if isLong then (((biggestWin * .382) / mult) + orderPrice) else Double.NaN;
def LT3ext = if (IsNaN(LT3) and isLong) then LT3ext[1] else LT3;
plot LT3extline = LT3ext;
LT3extline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LT3extline.SetDefaultColor(Color.GRAY);
LT3extline.SetLineWeight(1);

def LT4 = if isLong then (((biggestWin * .5) / mult) + orderPrice) else Double.NaN;
def LT4ext = if (IsNaN(LT4) and isLong) then LT4ext[1] else LT4;
plot LT4extline = LT4ext;
LT4extline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LT4extline.SetDefaultColor(Color.GRAY);
LT4extline.SetLineWeight(1);

def LT5 = if isLong then (((biggestWin * .618) / mult) + orderPrice) else Double.NaN;
def LT5ext = if (IsNaN(LT5) and isLong) then LT5ext[1] else LT5;
plot LT5extline = LT5ext;
LT5extline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LT5extline.SetDefaultColor(Color.GRAY);
LT5extline.SetLineWeight(1);

def LT6 = if isLong then (((biggestWin * .7495) / mult) + orderPrice) else Double.NaN;
def LT6ext = if (IsNaN(LT6) and isLong) then LT6ext[1] else LT6;
plot LT6extline = LT6ext;
LT6extline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LT6extline.SetDefaultColor(Color.GRAY);
LT6extline.SetLineWeight(1);

def LT7 = if isLong then (((biggestWin * .893) / mult) + orderPrice) else Double.NaN;
def LT7ext = if (IsNaN(LT7) and isLong) then LT7ext[1] else LT7;
plot LT7extline = LT7ext;
LT7extline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LT7extline.SetDefaultColor(Color.GRAY);
LT7extline.SetLineWeight(1);
#########################################
##Short Stop
#########################################
def ShortStop = if SellSig then high else Double.NaN;
def ShortStopext = if (IsNaN(ShortStop) and isShort) then ShortStopext[1] else ShortStop;
plot ShortStopextline = ShortStopext;
ShortStopextline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ShortStopextline.SetDefaultColor(Color.ORANGE);
ShortStopextline.SetLineWeight(2);

########################################
##Short Targets
########################################
plot ShortEntry = if isShort then (orderPrice) else Double.NaN;
;
ShortEntry.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ShortEntry.SetDefaultColor(Color.RED);
ShortEntry.SetLineWeight(2);

plot AvgProfitLS = if isShort then (orderPrice - ((dollarPLSum) / (ClosedTradeCount) / mult)) else Double.NaN;
AvgProfitLS.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
AvgProfitLS.SetDefaultColor(Color.WHITE);
AvgProfitLS.SetLineWeight(1);

def ST1 = if isShort then (orderPrice - (biggestWin * .13) / mult) else Double.NaN;
def ST1ext = if (IsNaN(ST1) and isShort) then ST1ext[1] else ST1;
plot ST1extline = ST1ext;
ST1extline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ST1extline.SetDefaultColor(Color.GRAY);
ST1extline.SetLineWeight(1);

def ST2 = if isShort then (orderPrice - (biggestWin * .236) / mult) else Double.NaN;
def ST2ext = if (IsNaN(ST2) and isShort) then ST2ext[1] else ST2;
plot ST2extline = ST2ext;
ST2extline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ST2extline.SetDefaultColor(Color.GRAY);
ST2extline.SetLineWeight(1);

def ST3 = if isShort then (orderPrice - (biggestWin * .382) / mult) else Double.NaN;
def ST3ext = if (IsNaN(ST3) and isShort) then ST3ext[1] else ST3;
plot ST3extline = ST3ext;
ST3extline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ST3extline.SetDefaultColor(Color.GRAY);
ST3extline.SetLineWeight(1);

def ST4 = if isShort then (orderPrice - (biggestWin * .5) / mult) else Double.NaN;
def ST4ext = if (IsNaN(ST4) and isShort) then ST4ext[1] else ST4;
plot ST4extline = ST4ext;
ST4extline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ST4extline.SetDefaultColor(Color.GRAY);
ST4extline.SetLineWeight(1);

def ST5 = if isShort then (orderPrice - (biggestWin * .618) / mult) else Double.NaN;
def ST5ext = if (IsNaN(ST5) and isShort) then ST5ext[1] else ST5;
plot ST5extline = ST5ext;
ST5extline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ST5extline.SetDefaultColor(Color.GRAY);
ST5extline.SetLineWeight(1);

def ST6 = if isShort then (orderPrice - (biggestWin * .7495) / mult) else Double.NaN;
def ST6ext = if (IsNaN(ST6) and isShort) then ST6ext[1] else ST6;
plot ST6extline = ST6ext;
ST6extline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ST6extline.SetDefaultColor(Color.GRAY);
ST6extline.SetLineWeight(1);

def ST7 = if isShort then (orderPrice - (biggestWin * .893) / mult) else Double.NaN;
def ST7ext = if (IsNaN(ST7) and isShort) then ST7ext[1] else ST7;
plot ST7extline = ST7ext;
ST7extline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ST7extline.SetDefaultColor(Color.GRAY);
ST7extline.SetLineWeight(1);
###################################
##Candle Color
###################################
AssignPriceColor(if coloredCandlesOn and (TradePL > (biggestWin * .75)) then Color.YELLOW else if ((ConsensusR > Consensus_Bias)) then Color.GREEN else if coloredCandlesOn and ((ConsensusR < Consensus_Bias)) then Color.RED else Color.GRAY);

###################################
##Line Bubbles
###################################
AddChartBubble(LabelsOn and BuySig, AvgProfitLL, "Average Profit: $" + avgTrade, Color.LiGHT_GREEN);
AddChartBubble(LabelsOn and BuySig, LT1, "T1: $" + (biggestwin * .13), Color.LIGHT_GREEN);
AddChartBubble(LabelsOn and BuySig, LT2, "T2: $" + (biggestwin * .236), Color.LIGHT_GREEN);
AddChartBubble(LabelsOn and BuySig, LT3, "T3: $" + (biggestwin * .382), Color.LIGHT_GREEN);
AddChartBubble(LabelsOn and BuySig, LT4, "T4: $" + (biggestwin * .5), Color.LIGHT_GREEN);
AddChartBubble(LabelsOn and BuySig, LT5, "T5: $" + (biggestwin * .618), Color.LIGHT_GREEN);
AddChartBubble(LabelsOn and BuySig, LT6, "T6: $" + (biggestwin * .7495), Color.LIGHT_GREEN);
AddChartBubble(LabelsOn and BuySig, LT7, "T7: $" + (biggestwin * .893), Color.LIGHT_GREEN);
AddChartBubble(LabelsOn and BuySig, LongStop, "StopLoss: $ -" + (Orderprice - LongStop) * MULT, Color.ORANGE);

AddChartBubble(LabelsOn and SellSig, AvgprofitLS, "Average Profit: $" + AVGTrade, Color.Red);
AddChartBubble(LabelsOn and SellSig, ST1, "T1: $" + (biggestwin * .13), Color.Red);
AddChartBubble(LabelsOn and SellSig, ST2, "T2: $" + (biggestwin * .236), Color.Red);
AddChartBubble(LabelsOn and SellSig, ST3, "T3: $" + (biggestwin * .382), Color.Red);
AddChartBubble(LabelsOn and SellSig, ST4, "T4: $" + (biggestwin * .5), Color.Red);
AddChartBubble(LabelsOn and SellSig, ST5, "T5: $" + (biggestwin * .618), Color.Red);
AddChartBubble(LabelsOn and SellSig, ST6, "T6: $" + (biggestwin * .7495), Color.Red);
AddChartBubble(LabelsOn and SellSig, ST7, "T7: $" + (biggestwin * .893), Color.Red);
AddChartBubble(LabelsOn and SellSig, ShortStop, "StopLoss: $ -" + (ShortStop - Orderprice) * MULT, Color.ORANGE);

here is the system where i like to add the profit and loss :


#Complete_Leledc
#Leledc Exhaustion Port
#https://usethinkscript.com/threads/leledc-exhaustion-indicator-for-thinkorswim.3369/page-3
#Original by @diazlaz



#hint maj_qual: Original setting is 6
#hint maj_len: Original setting is 30
#hint showMajorArrowsWeight: Min 1 Max 5
#hint showMajorLineWeight: Min 1 Max 5

input aggregationPeriod = AggregationPeriod.five_min;
def open = Open(Period = aggregationPeriod);
def high = high(period = aggregationPeriod);
def low = low(period = aggregationPeriod);
def close = close(period = aggregationPeriod);


input showMajor = yes;
input maj_qual = 6;
input maj_len = 30; #hint: Original setting is 30


input showMajorBuyers = yes;
input showMajorSellers = yes;

input showMajorArrows = yes;
input showMajorLines = yes;
input ShowMajorClouds = yes;


input MajorArrowsWeight = 2; #hint: Max is 5
input MajorLineWeight = 2; #hint: Max is 5

script lele {
    input qual = 100;  #note: does use input variable
    input len = 100;   #note: does use input variable

    def bIndex = CompoundValue(1,
     if (bIndex[1] > qual) and (close < open) and high >= Highest(high, len) then 0 else
     if (close > close[4]) then bIndex[1] + 1 else bIndex[1]
    , 0);

    def sIndex = CompoundValue(1,
     if ((sIndex[1] > qual) and (close > open) and (low <= Lowest(low, len))) then 0 else
     if (close < close[4]) then sIndex[1] + 1 else sIndex[1]
    , 0);

    def ret =
     if (bIndex[1] > qual) and (close < open) and high >= Highest(high, len) then -1 else
     if ((sIndex[1] > qual) and (close > open) and (low <= Lowest(low, len))) then 1
    else 0;

    plot sData = ret;
}


###############
# Major section
###############

def major = lele(maj_qual,maj_len);

def MajorBuyers = major == 1;
def MajorSellers = major == -1;


###############
# Major Arrows
###############


plot MajorBuyersArrow = if showMajor and showMajorBuyers and showMajorArrows and MajorBuyers then low else double.nan ;
MajorBuyersArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
MajorBuyersArrow.SetDefaultColor(color.light_green);
MajorBuyersArrow.SetLineWeight(MajorArrowsWeight);

plot MajorSellersArrow = if showMajor and showMajorBuyers and showMajorArrows and MajorSellers then high else double.nan;
MajorSellersArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_Down);
MajorSellersArrow.SetDefaultColor(color.light_red);
MajorSellersArrow.SetLineWeight(MajorArrowsWeight);

###############
# Major Lines
###############


input showMajorBuyersLowLine = yes;
input showMajorBuyersMidLine = yes;
input showMajorBuyersHighLine = yes;

input showMajorSellersLowLine = yes;
input showMajorSellersMidLine = yes;
input showMajorSellersHighLine = yes;

def MajorBuyersLow = if MajorBuyers then (low) else MajorBuyersLow[1];
def MajorBuyersMid = if MajorBuyers then (high + low)/2 else MajorBuyersMid[1];
def MajorBuyersHigh = if MajorBuyers then (high) else MajorBuyersHigh[1];

def MajorSellersLow = if MajorSellers then (low) else MajorSellersLow[1];
def MajorSellersMid = if MajorSellers then (high + low)/2 else MajorSellersMid[1];
def MajorSellersHigh = if MajorSellers then (high) else MajorSellersHigh[1];


plot MajorBuyersLowLine = if showMajor and showMajorBuyers and showMajorLines and showMajorBuyersLowLine  then MajorBuyersLow else double.nan;
MajorBuyersLowLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
MajorBuyersLowLine.SetDefaultColor(color.light_green);
MajorBuyersLowLine.SetLineWeight(MajorLineWeight);


plot MajorBuyersMidLine = if showMajor  and showMajorBuyers and showMajorLines and showMajorBuyersMidLine and MajorBuyersMid then MajorBuyersMid else double.nan;
MajorBuyersMidLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
MajorBuyersMidLine.SetDefaultColor(color.light_green);
MajorBuyersMidLine.SetLineWeight(MajorLineWeight);


plot MajorBuyersHighLine = if showMajor and showMajorBuyers and showMajorLines and showMajorBuyersHighLine and MajorBuyersHigh then MajorBuyersHigh else double.nan;
MajorBuyersHighLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
MajorBuyersHighLine.SetDefaultColor(color.light_green);
MajorBuyersHighLine.SetLineWeight(MajorLineWeight);


plot MajorSellersLowLine = if showMajor and showMajorSellers and showMajorLines and showMajorSellersLowLine and MajorSellersLow then MajorSellersLow else double.nan;
MajorSellersLowLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
MajorSellersLowLine.SetDefaultColor(color.light_red);
MajorSellersLowLine.SetLineWeight(MajorLineWeight);


plot MajorSellersMidLine = if showMajor and showMajorSellers  and showMajorLines and showMajorSellersMidLine and MajorSellersMid then MajorSellersMid else double.nan;
MajorSellersMidLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
MajorSellersMidLine.SetDefaultColor(color.light_red);
MajorSellersMidLine.SetLineWeight(MajorLineWeight);


plot MajorSellersHighLine = if showMajor and showMajorSellers  and showMajorLines and showMajorSellersHighLine and MajorSellersHigh then MajorSellersHigh else double.nan;
MajorSellersHighLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
MajorSellersHighLine.SetDefaultColor(color.light_red);
MajorSellersHighLine.SetLineWeight(MajorLineWeight);


###############
# Major Clouds
###############

input showMajorBuyersLowToMidCloud = yes;
input showMajorBuyersMidToHighCloud = yes;
input showMajorSellersLowToMidCloud = yes;
input showMajorSellersMidToHighCloud = yes;

def MajorBuyersLowForCloud = if MajorBuyers then (low) else MajorBuyersLow[1];
def MajorBuyersMidForCloud = if MajorBuyers then (high + low)/2 else MajorBuyersmid[1];
def MajorBuyersHighforCloud = if MajorBuyers then (high) else MajorBuyersHigh[1];

def MajorSellersLowForCloud = if MajorSellers then (low) else MajorSellersLow[1];
def MajorSellersMidForCloud = if MajorSellers then (high + low)/2 else MajorSellersMid[1];
def MajorSellersHighForCloud = if MajorSellers then (high) else MajorSellersHigh[1];

addcloud(if showMajor and showMajorBuyers and showMajorClouds and showMajorBuyersLowToMidCloud  then  MajorBuyersLowForCloud else Double.nan, MajorBuyersMidForCloud,color.light_green,color.light_green);
addcloud(if showMajor and showMajorBuyers and showMajorClouds and showMajorBuyersMidToHighCloud then MajorBuyersMidForCloud else Double.nan, MajorBuyersHighforCloud,color.light_green,color.light_green);
addcloud(if showMajor and showMajorSellers and showMajorClouds and showMajorSellersLowToMidCloud then MajorSellersLowForCloud else Double.nan, MajorSellersMidForCloud,color.light_red,color.light_red);
addcloud(if showMajor and showMajorSellers and showMajorClouds and showMajorSellersMidToHighCloud  then MajorSellersMidForCloud else Double.nan, MajorSellersHighForCloud,color.light_red,color.light_red);


###############
# Minor section
###############


#hint min_qual: Original setting is 5
#hint min_len: Original setting is 5

input showMinor = yes;
input min_qual = 5; #hint: Original setting is 5
input min_len = 5; #hint: Original setting is 5
def minor = lele(min_qual,min_len);

def MinorBuyers = Minor == 1;
def MinorSellers = Minor == -1;

input ShowMinorBuyers = yes;
input ShowMinorSellers = yes;

input showMinorArrows = yes;
input showMinorLines = yes;
input ShowMinorClouds = yes;

input MinorArrowsWeight = 1;
input MinorLineWeight = 1;

###############
# Minor Arrows
###############

plot MinorBuyersArrow = if showMinor and !MajorBuyers and showMinorBuyers  and ShowMinorArrows and MinorBuyers then low else double.nan ;
MinorBuyersArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
MinorBuyersArrow.SetDefaultColor(color.cyan);
MinorBuyersArrow.SetLineWeight(MinorArrowsWeight);

plot MinorSellersArrow = if showMinor and !MajorSellers and showMinorSellers and ShowMinorArrows and MinorSellers then high else double.nan ;
MinorSellersArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_Down);
MinorSellersArrow.SetDefaultColor(color.yellow);
MinorSellersArrow.SetLineWeight(MinorArrowsWeight);



###############
# Minor Lines
###############

input showMinorBuyersLowLine = yes;
input showMinorBuyersMidLine = yes;
input showMinorBuyersHighLine = yes;

input showMinorSellersLowLine = yes;
input showMinorSellersMidLine = yes;
input showMinorSellersHighLine = yes;

def MinorBuyersLow = if MinorBuyers and !MajorBuyers then (low) else MinorBuyersLow[1];
def MinorBuyersMid = if MinorBuyers and !MajorBuyers then (high + low)/2 else MinorBuyersMid[1];
def MinorBuyersHigh = if MinorBuyers and !MajorBuyers then (high) else MinorBuyersHigh[1];

def MinorSellersLow = if MinorSellers and !MajorSellers then (low) else MinorSellersLow[1];
def MinorSellersMid = if MinorSellers and !MajorSellers then (high + low)/2 else MinorSellersMid[1];
def MinorSellersHigh = if MinorSellers and !MajorSellers then (high) else MinorSellersHigh[1];


plot MinorBuyersLowLine = if showMinor and !MajorBuyers  and showMinorBuyers  and showMinorLines and showMinorBuyersLowLine and MinorBuyersLow then MinorBuyersLow else double.nan;
MinorBuyersLowLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
MinorBuyersLowLine.SetDefaultColor(color.cyan);
MinorBuyersLowLine.SetLineWeight(MinorLineWeight);


plot MinorBuyersMidLine = if showMinor and !MajorBuyers and showMinorBuyers and showMinorLines and showMinorBuyersMidLine and MinorBuyersMid then MinorBuyersMid else double.nan;
MinorBuyersMidLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
MinorBuyersMidLine.SetDefaultColor(color.cyan);
MinorBuyersMidLine.SetLineWeight(MinorLineWeight);


plot MinorBuyersHighLine = if showMinor and !MajorBuyers and showMinorBuyers   and showMinorLines and showMinorBuyersHighLine and MinorBuyersHigh then MinorBuyersHigh else double.nan;
MinorBuyersHighLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
MinorBuyersHighLine.SetDefaultColor(color.cyan);
MinorBuyersHighLine.SetLineWeight(MinorLineWeight);


plot MinorSellersLowLine = if showMinor and !MajorSellers and showMinorSellers  and showMinorLines and showMinorSellersLowLine and MinorSellersLow then MinorSellersLow else double.nan;
MinorSellersLowLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
MinorSellersLowLine.SetDefaultColor(color.yellow);
MinorSellersLowLine.SetLineWeight(MinorLineWeight);


plot MinorSellersMidLine = if showMinor and !MajorSellers and showMinorSellers  and showMinorLines and showMinorSellersMidLine and MinorSellersMid then MinorSellersMid else double.nan;
MinorSellersMidLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
MinorSellersMidLine.SetDefaultColor(color.yellow);
MinorSellersMidLine.SetLineWeight(MinorLineWeight);


plot MinorSellersHighLine = if showMinor and !MajorSellers and showMinorSellers  and showMinorLines and showMinorSellersHighLine and MinorSellersHigh then MinorSellersHigh else double.nan;
MinorSellersHighLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
MinorSellersHighLine.SetDefaultColor(color.yellow);
MinorSellersHighLine.SetLineWeight(MinorLineWeight);





###############
# Minor Clouds
###############


input showMinorBuyersMidToHighCloud = yes;
input showMinorBuyersLowToMidCloud = yes;
input showMinorSellersMidToHighCloud = yes;
input showMinorSellersLowToMidCloud = yes;

def MinorBuyersLowForCloud = if MinorBuyers and !MajorBuyers then (low) else MinorBuyersLow[1];
def MinorBuyersMidForCloud = if MinorBuyers and !MajorBuyers  then (high + low)/2 else MinorBuyersMid[1];
def MinorBuyersHighForCloud = if MinorBuyers and !MajorBuyers  then (high) else MinorBuyersHigh[1];

def MinorSellersLowForCloud = if MinorSellers  and !MajorSellers then (low) else MinorSellersLow[1];
def MinorSellersMidForCloud = if MinorSellers  and !MajorSellers then (high + low)/2 else MinorSellersMid[1];
def MinorSellersHighForCloud = if MinorSellers and !MajorSellers then (high) else MinorSellersHigh[1];


addcloud(if ShowMinor and ShowMinorBuyers and !MajorBuyers and showMinorClouds and showMinorBuyersLowToMidCloud  then MinorBuyersLowForCloud else Double.nan, MinorBuyersMidForCloud,color.cyan,color.cyan);
addcloud(if ShowMinor and ShowMinorBuyers and !MajorBuyers and showMinorClouds and showMinorBuyersMidToHighCloud  then MinorBuyersMidForCloud else Double.nan, MinorBuyersHighForCloud,color.cyan,color.cyan);

addcloud(if ShowMinor and ShowMinorSellers and !MajorSellers and showMinorClouds and showMinorSellersLowToMidCloud  then MinorSellersLowForCloud else Double.nan, MinorSellersMidForCloud,color.yellow,color.yellow);
addcloud(if ShowMinor and ShowMinorSellers and !MajorSellers and showMinorClouds and showMinorSellersMidToHighCloud then MinorSellersMidForCloud else Double.nan, MinorSellersHighForCloud,color.yellow,color.yellow);



###############
# ALERTS
###############
input UseAlerts = yes;
input AlertMajorSellers = yes;
input AlertMajorBuyers = yes;
input AlertMinorSellers = yes;
input AlertMinorBuyers = yes;

Alert(showMajor and UseAlerts and AlertMajorBuyers  and MajorBuyers, "Leledc Major Buyers", Alert.Bar, Sound.Chimes);
Alert(showMajor and UseAlerts and AlertMajorSellers and MajorSellers, "Leledc Major Sellers", Alert.Bar, Sound.Chimes);
Alert(showMinor and UseAlerts and AlertMinorBuyers and MinorSellers and !MajorBuyers, "Leledc Minor Buyers", Alert.Bar, Sound.Chimes);
Alert(showMinor and UseAlerts and AlertMinorSellers and MinorSellers and !MajorBuyers, "Leledc Minor Sellers", Alert.Bar, Sound.Chimes);

###############
# Bubbles
###############
Input showBubbles = yes;
input showMajorBubbles = yes;
input showMinorBubbles = yes;
addchartbubble(showBubbles and showMajorBubbles and showMajor and MajorSellers,high ,"S/E ",color.light_red,yes);
addchartbubble(showBubbles and showMajorBubbles and showMajor and MajorBuyers,low ,"B/E ",color.light_green,no);
addchartbubble(showBubbles and showMinorBubbles and showMinor and MajorSellers and !MajorSellers,high ,"Minor SELLERS",color.cyan,yes);
addchartbubble(showBubbles and showMinorBubbles and showMinor and MinorBuyers and !MajorBuyers,low ,"Minor BUYERS",color.yellow,no);
 
Last edited by a moderator:
Top