https://www.youtube.com/watch?v=Q3vHXIJF4lU
As you can see in this video, I have set the condition for long and the condition for short, I entered with trade ID and set the exit limit the same as the entry ID, however on the list of trades, it doesn’t match the exit with the correct ID? For example how is it possible that Short Loss 2 is used to closed Short 1 when littertatly I put strategy.exit(Short 1) after strategy.entry(Short 1) ?? I hope this pinescript bug have a parameter I dont know of to fix this issue or else it the pinescript developers would need to actually fix this bug. What funny is Short 1 is matched with Short Loss 1 on the chart but NOT ON THE LIST OF trades. As you can see I calculated TP at 0.25% and SL 0.05% for each trade but due to Pinescript bug it show average winning trade 0.15% instead of 0.25%.
Here is the code for testing
//@version=5
strategy("Wrong ID Closed", overlay=true, initial_capital=2500, currency="USD", default_qty_type=strategy.percent_of_equity, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0, pyramiding=30, slippage=0, calc_on_every_tick=true, margin_long=0, margin_short=0)
volume_delta = input.int(500, title="Volume Delta",inline = "5")
useCustomTimeframeInput = input.bool(false, "Use custom timeframe")
lowerTimeframeInput = input.timeframe("1", "Timeframe")
float FixedTPPercent = 0.25/100 //0.20% FixedTPPercent
float FixedSLpercent = 0.05/100 //0.05% SL
tZone = input.string("UTC+3","Timezone",options = ["UTC-12", "UTC-11", "UTC-10", "UTC-9", "UTC-8", "UTC-7", "UTC-6", "UTC-5", "UTC-4", "UTC-3", "UTC-2", "UTC-1", "UTC+0", "UTC+1", "UTC+2", "UTC+3", "UTC+3:30", "UTC+4", "UTC+4:30", "UTC+5", "UTC+5:30", "UTC+5:45", "UTC+6", "UTC+6:30", "UTC+7", "UTC+8", "UTC+9", "UTC+9:30", "UTC+10", "UTC+10:30", "UTC+11", "UTC+11:30", "UTC+12", "UTC+12:45", "UTC+13", "UTC+14"])
timeinrange(TimeRange) => not na(time("1", TimeRange, tZone))
i_sess_1 = input.session("1000-1200", "Trading Session",inline = "1")
i_sess_2 = input.session("1500-1700", "Trading Session",inline = "2")
float ema_longest = ta.ema(close, 30)
float ema_medium = ta.ema(close, 15)
float ema_shortest = ta.ema(close, 14)
longCondition = ema_shortest > ema_medium and ema_medium > ema_longest
shortCondition = ema_shortest < ema_medium and ema_medium < ema_longest
var int LongCount = 0
var int ShortCount = 0
//Volume Delta Calculator by Lux Algo*******************
upAndDownVolume() =>
posVol = 0.0
negVol = 0.0
var isBuyVolume = true
switch
close > open => isBuyVolume := true
close < open => isBuyVolume := false
close > close[1] => isBuyVolume := true
close < close[1] => isBuyVolume := false
if isBuyVolume
posVol += volume
else
negVol -= volume
posVol + negVol
var lowerTimeframe = switch
useCustomTimeframeInput => lowerTimeframeInput
timeframe.isseconds => "1S"
timeframe.isintraday => "1"
timeframe.isdaily => "5"
=> "60"
diffVolArray = request.security_lower_tf(syminfo.tickerid, lowerTimeframe, upAndDownVolume())
getHighLow(arr) =>
float cumVolume = na
float maxVolume = na
float minVolume = na
for item in arr
cumVolume := nz(cumVolume) + item
maxVolume := math.max(nz(maxVolume), cumVolume)
minVolume := math.min(nz(minVolume), cumVolume)
[maxVolume, minVolume, cumVolume]
[maxVolume, minVolume, lastVolume] = getHighLow(diffVolArray)
openVolume = not na(lastVolume) ? 0.0 : na
//Volume Delta Calculator By Lux Algo ***********************************
if ((longCondition) and (timeinrange(i_sess_1) or timeinrange(i_sess_2)) and (lastVolume > volume_delta))
LongCount += 1
strategy.entry("Long " + str.tostring(LongCount), strategy.long)
strategy.exit("Exit Long " + str.tostring(LongCount), "Long " + str.tostring(LongCount), limit = close + (close*FixedTPPercent), stop = close - (close*FixedSLpercent), comment_profit = "Long Profit " + str.tostring(LongCount), comment_loss = "Long loss " + str.tostring(LongCount))
if (shortCondition and (timeinrange(i_sess_1) or timeinrange(i_sess_2)) and (lastVolume < (-1 * volume_delta)))
ShortCount += 1
strategy.entry("Short " + str.tostring(ShortCount), strategy.short)
strategy.exit("Exit Short " + str.tostring(ShortCount), "Short " + str.tostring(ShortCount), limit = close - (close*FixedTPPercent), stop = close + (close*FixedSLpercent), comment_profit = "Short Profit " + str.tostring(ShortCount), comment_loss = "Short Loss " + str.tostring(ShortCount))
For each entry, TP should be EXACTLY 0.25% away from entry and SL 0.05% away from ENTRY. But from Performance Summary, average winning trade % and average losing trade % say something different.
As seen in the code, an attempt to make each TP and SL seperate for each trade is made by using trade ID + str.tostring(tradeCount) in strategy.entry(), it should work but pinescript compiler bugged so it doesn’t work? It works perfectly on chart but not in the list of trades and performance summary.