QQE Reversals Strategy For ThinkOrSwim

Ramisegal

Active member
Plus
The script was removed by the author, after further research it turns out it was meaningless and potentially misleading.
 
Last edited:
Hello, Thank you for sharing I would like to play around with this but I am not sure if I followed your instruction correctly. I added this P&L code to the bottom of the code you posted above.
### Use this below any script to give Win/Loss info ###

input showStats = yes;

#Globals
def nan = Double.NaN;
def bn = if !IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close[-1]) then BarNumber() else bn[1];

#Inputs
input fplTargetWinLoss = .50;
#hint fplTargetWinLoss: sets the target winlossRatio (in percent) which determines display colors of the W/L label.

input fplTargetWinRate = 1;
#hint fplTargetWinRate: sets the target winRate (float) which determines display colors of the WinRate label;

input fplHidePrice = no;
#hint fplHidePrice: hide's the underlying price graph. \nDefault is no.

input fplHideFPL = yes;
#hint fplHideFPL: hide's the underlying P&L graph.\nDefault is yes.

#temp input var references
def targetWinLoss = fplTargetWinLoss;
def targetWinRate = fplTargetWinRate;
def hidePrice = fplHidePrice;
def hideFPL = fplHideFPL;

#hide chart candles
HidePricePlot(hidePrice);

#Plot default Floating P&L
plot FPL = FPL();
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"));
FPL.SetHiding(hideFPL);

plot ZeroLine = if IsNaN(close)
then nan
else 0;
ZeroLine.SetDefaultColor(Color.GRAY);
ZeroLine.SetHiding(hideFPL);

#Global Scripts
script incrementValue {
input condition = yes;
input increment = 1;
input startingValue = 0;

def _value = CompoundValue(1,
if condition
then _value[1] + increment
else _value[1], startingValue);

plot incrementValue = _value;
}
;

# Entry Calculations. Note: Only parses on a Strategy Chart
def entry = EntryPrice();

def entryPrice = if !IsNaN(entry)
then entry
else entryPrice[1];

def hasEntry = !IsNaN(entry);

def isNewEntry = entryPrice != entryPrice[1];

#is active trade
def highFPL = HighestAll(FPL);
def lowFPL = LowestAll(FPL);

def fplreturn = (FPL - FPL[1]) / FPL[1];
def cumsum = Sum(fplreturn);

def highBarNumber = CompoundValue(1, if FPL == highFPL
then bn
else highBarNumber[1], 0);

def lowBarNumber = CompoundValue(1, if FPL == lowFPL
then bn
else lowBarNumber[1], 0);

#Win/Loss ratios
def entryBarsTemp = if hasEntry
then bn
else nan;

def entryBarNum = if hasEntry and isNewEntry
then bn
else entryBarNum[1];

def isEntryBar = entryBarNum != entryBarNum[1];

def entryBarPL = if isEntryBar
then FPL
else entryBarPL[1];

def exitBarsTemp = if !hasEntry
and bn > entryBarsTemp[1]
then bn
else nan;

def exitBarNum = if !hasEntry and !IsNaN(exitBarsTemp[1])
then bn
else exitBarNum[1];

def isExitBar = exitBarNum != exitBarNum[1];

def exitBarPL = if isExitBar
then FPL
else exitBarPL[1];

def entryReturn = if isExitBar then exitBarPL - exitBarPL[1] else entryReturn[1];
def isWin = if isExitBar and entryReturn >= 0 then 1 else 0;
def isLoss = if isExitBar and entryReturn < 0 then 1 else 0;
def entryReturnWin = if isWin then entryReturn else entryReturnWin[1];
def entryReturnLoss = if isLoss then entryReturn else entryReturnLoss[1];
def entryFPLWins = if isWin then entryReturn else 0;
def entryFPLLosses = if isLoss then entryReturn else 0;
def entryFPLAll = if isLoss or isWin then entryReturn else 0;

#Counts
def entryCount = incrementValue(entryFPLAll);
def winCount = incrementValue(isWin);
def lossCount = incrementValue(isLoss);

def highestReturn = if entryReturnWin[1] > highestReturn[1]
then entryReturnWin[1]
else highestReturn[1];

def lowestReturn = if entryReturnLoss[1] < lowestReturn[1]
then entryReturnLoss[1]
else lowestReturn[1];


def winRate = winCount / lossCount;
def winLossRatio = winCount / entryCount;
def avgReturn = TotalSum(entryFPLAll) / entryCount;
def avgWin = TotalSum(entryFPLWins) / winCount;
def avgLoss = TotalSum(entryFPLLosses) / lossCount;

# My Add -----------------------------------------
# This is the area I can't seem to understand what I'm doing wrong

def tmpMaxLossCount = if isLoss then tmpMaxLossCount[1] + 1 else 0;
def maxLossCount = if tmpMaxLossCount > tmpMaxLossCount[1] then tmpMaxLossCount else MaxLossCount[1];

AddLabel(showStats,
text = "Max Loss Count: " + maxLossCount +
" ",
color = color.ORANGE
);

# End My Add -------------------------------------

#Labels
AddLabel(showStats,
text = "Total Trades: " + entryCount + " ",
color = Color.WHITE
);

AddLabel(showStats,
text = "WinCount: " + winCount +
" | LossCount: " + lossCount +
" | WinRate: " + round(winRate,2) + " ",
color = if winRate >= targetWinRate
then Color.CYAN
else Color.MAGENTA
);

AddLabel(showStats,
text = "W/L: " + AsPercent(winLossRatio) + " ",
color = if winLossRatio > targetWinLoss
then Color.CYAN
else Color.MAGENTA
);

AddLabel(showStats,
text = "AvgReturn: " + AsDollars(avgReturn) +
" | AvgLoss: " + AsDollars(avgLoss) +
" | BiggestLoss: " + AsDollars(lowestReturn) +
" | AvgWin: " + AsDollars(avgWin) +
" | HighestWin: " + AsDollars(highestReturn) + " ",
color = if avgReturn >= 0
then Color.CYAN
else Color.MAGENTA
);

AddLabel(showStats,
text = "Total Profit: " + AsDollars(FPL) + " ",
color = if FPL > 0
then Color.CYAN
else Color.MAGENTA
);


So It looks like this.
#Code...

# QQE Indicator
# Converted by Kory Gill for BenTen at useThinkScript.com
# Original https://www.tradingview.com/script/zwbe2plA-Ghosty-s-Zero-Line-QQE/

#declare lower;

input RSI_Period = 232;
input Slow_Factor = 29;
input QQE = 4.236;

def Wilder_Period = RSI_Period * 2 - 1;
def vClose = close;

def rsi = RSI(price = vClose, length = RSI_Period).RSI;
def rsi_ma = MovingAverage(AverageType.EXPONENTIAL, rsi, Slow_Factor);
def atr_rsi = AbsValue(rsi_ma[1] - rsi_ma);
def atr_rsi_ma = MovingAverage(AverageType.EXPONENTIAL, atr_rsi, Wilder_Period);
def dar = MovingAverage(AverageType.EXPONENTIAL, atr_rsi_ma, Wilder_Period) * QQE;

def DeltaFastAtrRsi = dar;
def RSIndex = rsi_ma;
def newshortband = RSIndex + DeltaFastAtrRsi;
def newlongband = RSIndex - DeltaFastAtrRsi;

def longband = if RSIndex[1] > longband[1] and RSIndex > longband[1]
then max(longband[1],newlongband)
else newlongband;

def shortband = if RSIndex[1] < shortband[1] and RSIndex < shortband[1]
then min(shortband[1], newshortband)
else newshortband;

def trend = if Crosses(RSIndex, shortband[1])
then 1
else if Crosses(longband[1], RSIndex)
then -1
else if !IsNAN(trend[1])
then trend[1]
else 1;

def FastAtrRsiTL = if trend == 1
then longband
else shortband;

input useorder = no;
input usereversal = yes;

addOrder(OrderType.BUY_AUTO,useorder and trend<>trend[1] and trend == 1 ,tickColor = GetColor(1), arrowColor = GetColor(1), name = "B@ "+close);
addOrder(OrderType.sell_AUTO,useorder and trend<>trend[1] and trend == -1 , tickColor = GetColor(4), arrowColor = GetColor(4), name = "S@ " +close);


addOrder(OrderType.BUY_AUTO,usereversal and trend<>trend[1] and trend == -1 ,tickColor = GetColor(1), arrowColor = GetColor(1), name = "Br@ "+close);
addOrder(OrderType.sell_AUTO,usereversal and trend<>trend[1] and trend == 1 , tickColor = GetColor(4), arrowColor = GetColor(4), name = "Sr@ " +close);
### Use this below any script to give Win/Loss info ###

input showStats = yes;

#Globals
def nan = Double.NaN;
def bn = if !IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close[-1]) then BarNumber() else bn[1];

#Inputs
input fplTargetWinLoss = .50;
#hint fplTargetWinLoss: sets the target winlossRatio (in percent) which determines display colors of the W/L label.

input fplTargetWinRate = 1;
#hint fplTargetWinRate: sets the target winRate (float) which determines display colors of the WinRate label;

input fplHidePrice = no;
#hint fplHidePrice: hide's the underlying price graph. \nDefault is no.

input fplHideFPL = yes;
#hint fplHideFPL: hide's the underlying P&L graph.\nDefault is yes.

#temp input var references
def targetWinLoss = fplTargetWinLoss;
def targetWinRate = fplTargetWinRate;
def hidePrice = fplHidePrice;
def hideFPL = fplHideFPL;

#hide chart candles
HidePricePlot(hidePrice);

#Plot default Floating P&L
plot FPL = FPL();
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"));
FPL.SetHiding(hideFPL);

plot ZeroLine = if IsNaN(close)
then nan
else 0;
ZeroLine.SetDefaultColor(Color.GRAY);
ZeroLine.SetHiding(hideFPL);

#Global Scripts
script incrementValue {
input condition = yes;
input increment = 1;
input startingValue = 0;

def _value = CompoundValue(1,
if condition
then _value[1] + increment
else _value[1], startingValue);

plot incrementValue = _value;
}
;

# Entry Calculations. Note: Only parses on a Strategy Chart
def entry = EntryPrice();

def entryPrice = if !IsNaN(entry)
then entry
else entryPrice[1];

def hasEntry = !IsNaN(entry);

def isNewEntry = entryPrice != entryPrice[1];

#is active trade
def highFPL = HighestAll(FPL);
def lowFPL = LowestAll(FPL);

def fplreturn = (FPL - FPL[1]) / FPL[1];
def cumsum = Sum(fplreturn);

def highBarNumber = CompoundValue(1, if FPL == highFPL
then bn
else highBarNumber[1], 0);

def lowBarNumber = CompoundValue(1, if FPL == lowFPL
then bn
else lowBarNumber[1], 0);

#Win/Loss ratios
def entryBarsTemp = if hasEntry
then bn
else nan;

def entryBarNum = if hasEntry and isNewEntry
then bn
else entryBarNum[1];

def isEntryBar = entryBarNum != entryBarNum[1];

def entryBarPL = if isEntryBar
then FPL
else entryBarPL[1];

def exitBarsTemp = if !hasEntry
and bn > entryBarsTemp[1]
then bn
else nan;

def exitBarNum = if !hasEntry and !IsNaN(exitBarsTemp[1])
then bn
else exitBarNum[1];

def isExitBar = exitBarNum != exitBarNum[1];

def exitBarPL = if isExitBar
then FPL
else exitBarPL[1];

def entryReturn = if isExitBar then exitBarPL - exitBarPL[1] else entryReturn[1];
def isWin = if isExitBar and entryReturn >= 0 then 1 else 0;
def isLoss = if isExitBar and entryReturn < 0 then 1 else 0;
def entryReturnWin = if isWin then entryReturn else entryReturnWin[1];
def entryReturnLoss = if isLoss then entryReturn else entryReturnLoss[1];
def entryFPLWins = if isWin then entryReturn else 0;
def entryFPLLosses = if isLoss then entryReturn else 0;
def entryFPLAll = if isLoss or isWin then entryReturn else 0;

#Counts
def entryCount = incrementValue(entryFPLAll);
def winCount = incrementValue(isWin);
def lossCount = incrementValue(isLoss);

def highestReturn = if entryReturnWin[1] > highestReturn[1]
then entryReturnWin[1]
else highestReturn[1];

def lowestReturn = if entryReturnLoss[1] < lowestReturn[1]
then entryReturnLoss[1]
else lowestReturn[1];


def winRate = winCount / lossCount;
def winLossRatio = winCount / entryCount;
def avgReturn = TotalSum(entryFPLAll) / entryCount;
def avgWin = TotalSum(entryFPLWins) / winCount;
def avgLoss = TotalSum(entryFPLLosses) / lossCount;

# My Add -----------------------------------------
# This is the area I can't seem to understand what I'm doing wrong

def tmpMaxLossCount = if isLoss then tmpMaxLossCount[1] + 1 else 0;
def maxLossCount = if tmpMaxLossCount > tmpMaxLossCount[1] then tmpMaxLossCount else MaxLossCount[1];

AddLabel(showStats,
text = "Max Loss Count: " + maxLossCount +
" ",
color = color.ORANGE
);

# End My Add -------------------------------------

#Labels
AddLabel(showStats,
text = "Total Trades: " + entryCount + " ",
color = Color.WHITE
);

AddLabel(showStats,
text = "WinCount: " + winCount +
" | LossCount: " + lossCount +
" | WinRate: " + round(winRate,2) + " ",
color = if winRate >= targetWinRate
then Color.CYAN
else Color.MAGENTA
);

AddLabel(showStats,
text = "W/L: " + AsPercent(winLossRatio) + " ",
color = if winLossRatio > targetWinLoss
then Color.CYAN
else Color.MAGENTA
);

AddLabel(showStats,
text = "AvgReturn: " + AsDollars(avgReturn) +
" | AvgLoss: " + AsDollars(avgLoss) +
" | BiggestLoss: " + AsDollars(lowestReturn) +
" | AvgWin: " + AsDollars(avgWin) +
" | HighestWin: " + AsDollars(highestReturn) + " ",
color = if avgReturn >= 0
then Color.CYAN
else Color.MAGENTA
);

AddLabel(showStats,
text = "Total Profit: " + AsDollars(FPL) + " ",
color = if FPL > 0
then Color.CYAN
else Color.MAGENTA
);

#end of code



After that, I added it 2x to my chart and changed the settings to the settings you recommended above.

Is this correct or was I supposed to create two separate strategies and add Floating P&L code to the bottom of each and edit the code with your settings for both? How do I change the contract size? I do not see the option. Why isnt the number of trades showing up? It may be easier for you to just share your chart with me so i can figure it out for myself (trying to learn a little coding here) Thanks
y33cUN.png
 
The script is a strategy not an indicator (no need to modify the script) . in tos select the create strategy option (not study)
delete the default line created in the script and paste the code above, name the strategy. (just as you did)

Click on the Global strategy settings... for contract size and number of contracts per order

select the display floating pnl so it will display a chart with your profit and loss.
The pnl can be also scripted to display more information and statistics about the trades but in my experience it has to integrate with the strategy since the entryprice() is not a data array.
I have a version of that code if you are interested.

You would be better served by saving the report and importing to excel to analyze the win rate, drawdowns and profits.
 
Last edited:
Ramisegal: Hello, can you please help me how to interpret the Buy and Sell signals?
I don't understand the Signals.

I loaded it as a strategy twice and changed inputs. Looks better on 5min 180 days. I am asking what signals are the best. Maybe you could do a short video or mark-up a Chart? Maybe too much to ask.

I don't really care to have a floating PnL. https://gyazo.com/6d4f3668d4821cfc9e90cedb8c84ac98
vM2tLkE.png
 
The script was removed by the author, after further research it turns out it was meaningless and potentially misleading.
 
Last edited:
The script was removed by the author, after further research it turns out it was meaningless and potentially misleading.
 
Last edited:
I assembled some scripts together so you can get some performance information, must install in TOS as a strategy
The input parameters are setup for 1 Hour time frame

Screen Capture
2023-01-31-TOS_CHARTS - NMQ 1 Hour with stats

#start

input Enable= yes;

# QQE Indicator
# Converted by Kory Gill for BenTen at useThinkScript.com
# Original https://www.tradingview.com/script/zwbe2plA-Ghosty-s-Zero-Line-QQE/

#declare lower;

input RSI_Period = 23;
input Slow_Factor = 11;
input QQE = 4.236;

def Wilder_Period = RSI_Period * 2 - 1;
def vClose = close;

def rsi = RSI(price = vClose, length = RSI_Period).RSI;
def rsi_ma = MovingAverage(AverageType.EXPONENTIAL, rsi, Slow_Factor);
def atr_rsi = AbsValue(rsi_ma[1] - rsi_ma);
def atr_rsi_ma = MovingAverage(AverageType.EXPONENTIAL, atr_rsi, Wilder_Period);
def dar = MovingAverage(AverageType.EXPONENTIAL, atr_rsi_ma, Wilder_Period) * QQE;

def DeltaFastAtrRsi = dar;
def RSIndex = rsi_ma;
def newshortband = RSIndex + DeltaFastAtrRsi;
def newlongband = RSIndex - DeltaFastAtrRsi;

def longband = if RSIndex[1] > longband[1] and RSIndex > longband[1]
then max(longband[1],newlongband)
else newlongband;

def shortband = if RSIndex[1] < shortband[1] and RSIndex < shortband[1]
then min(shortband[1], newshortband)
else newshortband;

def trend = if Crosses(RSIndex, shortband[1])
then 1
else if Crosses(longband[1], RSIndex)
then -1
else if !IsNAN(trend[1])
then trend[1]
else 1;

def FastAtrRsiTL = if trend == 1
then longband
else shortband;


input useorder = yes;


def entryPrice = if trend<>trend[1] then close else entryPrice[1];
plot Qt = entryPrice;
qt.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#qt.SetStyle(Curve.MEDIUM_DASH );
qt.AssignValueColor(if useorder and trend < 0 then Color.red else Color.GREEN);

def abuy = trend<>trend[1] and trend == 1;
def asell = trend<>trend[1] and trend == -1;

AddOrder(OrderType.BUY_AUTO,Enable and useorder and ABuy , tickColor = GetColor(1), arrowColor = GetColor(1), name = "B@ " + open[-1]);
AddOrder(OrderType.SELL_AUTO,Enable and useorder and ASell , tickColor = GetColor(4), arrowColor = GetColor(4), name = "S@ " + open[-1]);




input ShowSignals = yes;
input showLabels = yes;
input showBubbles = yes;
input useStops = no;

############################################
## Create Signals - FILL IN THIS SECTION
############################################


def BuySignal = abuy ; # insert condition to create long position
def SellSignal =asell ; # insert condition to create short position


def BuyStop = if !useStops then 0 else 1 ; # insert condition to stop in place of the 0 after else
def SellStop = if !useStops then 0 else 1 ; # insert condition to stop in place of the 0 after else

input AudibleAlerts = no;
Alert(AudibleAlerts and BuySignal, "QQETMT BuySignal", Alert.BAR, Sound.Ding);
Alert(AudibleAlerts and SellSignal, "QQETMT SellSignal", Alert.BAR, Sound.Ding);


#######################################
## 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 (BuySignal) {
CurrentPosition = 1;
} else if (SellSignal) {
CurrentPosition = -1;
} else {
CurrentPosition = CurrentPosition[1];
}
} else if CurrentPosition[1] == 1 { # LONG
if (SellSignal) {
CurrentPosition = -1;
} else if (BuyStop) {
CurrentPosition = 0;
} else {
CurrentPosition = CurrentPosition[1];
}
} else if CurrentPosition[1] == -1 { # SHORT
if (BuySignal) {
CurrentPosition = 1;
} else if (SellStop) {
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;



#######################################
## Plot the Signals
#######################################

plot BuySig = if (!isLong[1] and BuySignal and ShowSignals) then 1 else 0;
BuySig.AssignValueColor(Color.YELLOW);
BuySig.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
BuySig.SetLineWeight(3);

plot SellSig = if (!isShort[1] and SellSignal and ShowSignals) then 1 else 0;
SellSig.AssignValueColor(Color.WHITE);
SellSig.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
SellSig.SetLineWeight(3);

plot BuyStpSig = if (BuyStop and isLong[1] and ShowSignals) then 1 else 0;
BuyStpSig.AssignValueColor(Color.GRAY);
BuyStpSig.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
BuyStpSig.SetLineWeight(3);

plot SellStpSig = if (SellStop and isShort[1] and ShowSignals) then 1 else 0;
SellStpSig.AssignValueColor(Color.GRAY);
SellStpSig.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
SellStpSig.SetLineWeight(3);



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

def isOrder = if CurrentPosition == CurrentPosition[1] then 0 else 1; # Status changed so it's a new order
def orderPrice = if (isOrder and (BuySignal or SellSignal)) then open[-1] else orderPrice[1];


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

def profitLoss;

if (!isOrder) {
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;
}

def profitLossSum = CompoundValue(1, if IsNaN(isOrder) then 0 else if isOrder then profitLossSum[1] + profitLoss else profitLossSum[1], 0);
def profitWinners = CompoundValue(1, if IsNaN(isOrder) then 0 else if isOrder and profitLoss > 0 then profitWinners[1] + 1 else profitWinners[1], 0);
def profitLosers = CompoundValue(1, if IsNaN(isOrder) then 0 else if isOrder and profitLoss < 0 then profitLosers[1] + 1 else profitLosers[1], 0);
def profitPush = CompoundValue(1, if IsNaN(isOrder) then 0 else if isOrder and profitLoss == 0 then profitPush[1] + 1 else profitPush[1], 0);
def TradePL = if isLong then Round(((close - orderPrice) / TickSize()) * TickValue()) else if isShort then Round(((orderPrice - close) / TickSize()) * TickValue()) else 0; # current trade p/l
def dollarProfitLoss = Round((profitLoss / TickSize()) * TickValue()); # per trade for chart bubbles
def biggestWin = CompoundValue(1, if IsNaN(isOrder) then 0 else if isOrder and (dollarProfitLoss > 0) and (dollarProfitLoss > biggestWin[1]) then dollarProfitLoss else biggestWin[1], 0);
def biggestLoss = CompoundValue(1, if IsNaN(isOrder) then 0 else if isOrder and (dollarProfitLoss < 0) and (dollarProfitLoss < biggestLoss[1]) then dollarProfitLoss else biggestLoss[1], 0);

def orderCount = (profitWinners + profitLosers + profitPush);
def PCTWin = Round((profitWinners / orderCount) * 100, 2);

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

AddLabel(yes, GetSymbol() + " Tick Size: " + TickSize() + " Value: " + TickValue(), Color.WHITE);
AddLabel(showSignals and showLabels, "Orders: " + orderCount + " P/L: " + AsDollars(profitLossSum), if profitLossSum > 0 then Color.GREEN else if profitLossSum < 0 then Color.RED else Color.GRAY);
AddLabel(yes, "Winners: " + PCTWin + "%", if PCTWin > 50 then Color.GREEN else if PCTWin > 40 then Color.YELLOW else Color.GRAY);
AddLabel(yes, "MaxUp: " + AsDollars(biggestWin) + " MaxDown: " + AsDollars(biggestLoss), Color.WHITE);
AddLabel(if !IsNaN(CurrentPosition) then 1 else 0, "Current: " + (if isLong then "Bought" else "Sold") + " @ " + orderPrice, Color.WHITE);
AddLabel(if !IsNaN(orderPrice) then 1 else 0, "Trade P/L: " + AsDollars(TradePL), 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, 1);
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, 0);

#End


2023-01-31-TOS_CHARTS - NMQ 1 Hour with stats
Do you mind doing a chart share link? I am getting different results compared to your screenshots. Thanks in advance!
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
445 Online
Create Post

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top