2

Actually i want to make the screener of winrate of a specific strategy of all the symbols but i am not able to do that so please guide me

this is what i tried

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © amjupvc1234

//@version=5
strategy("Table", overlay=true)
GetWinRate(includeEvens = false) =>
    winTradeCount = strategy.wintrades + 
         (includeEvens ? strategy.eventrades : 0)
    (winTradeCount / strategy.closedtrades) * 100
ATRCalc(length,highcalc,lowcalc,closecalc) =>
    trueRange = na(highcalc[1])? highcalc-lowcalc : math.max(math.max(highcalc - lowcalc, math.abs(highcalc - closecalc[1])), math.abs(lowcalc - closecalc[1]))
    ta.rma(trueRange, length)
    
getsymbolRate(symbol) =>
    CloseSym = request.security("BINANCE:"+symbol+".P","60", close)
    OpenSym = request.security("BINANCE:"+symbol+".P","60", open)
    LowSym = request.security("BINANCE:"+symbol+".P","60", low)
    HighSym = request.security("BINANCE:"+symbol+".P","60", high)
    [BBMID, BBUP, BBDOWN] = ta.bb(CloseSym, 20, 2)
    RSI = ta.rsi(CloseSym, 14)
    ATR = ATRCalc(14,HighSym,LowSym,CloseSym)
    longCondition = CloseSym > BBMID and OpenSym < BBMID and RSI > 52
    var float TakeProfit = na
    var float StopLoss = na
    var bool PositionOpen = false
    if longCondition and not PositionOpen
        Low = LowSym
        Close = CloseSym
        STOPPRICE = Low - ATR
        StopLoss := STOPPRICE
        SLPCT = ((Close - STOPPRICE) * 100) / STOPPRICE
        TPPCT = SLPCT * 2
        PROFITPRICE = Close
        PROFITPRICE += PROFITPRICE * TPPCT / 100
        TakeProfit := PROFITPRICE
        strategy.entry("Entry", strategy.long)
        PositionOpen := true
    if PositionOpen
        strategy.exit("Exit", "Entry", stop=StopLoss, limit=TakeProfit)
    if strategy.position_size == 0
        PositionOpen := false
    winrateSym = GetWinRate()
    winrateSym
BTCUSDT = getsymbolRate("BTCUSDT")
ADAUSDT = getsymbolRate("ADAUSDT")
DOTUSDT = getsymbolRate("DOTUSDT")
INCHUSDT = getsymbolRate("1INCHUSDT")
var tbl = table.new(position.top_right, 6, 11, frame_color=#151715, frame_width=1, border_width=2, border_color=color.new(color.white, 100))
if barstate.islastconfirmedhistory or barstate.isrealtime
    table.clear(tbl, 0, 0, 5, 10)
    table.cell(tbl, 0, 0, 'SYMBOL',     text_halign = text.align_center, bgcolor = color.rgb(252, 252, 252), text_color = color.rgb(3, 3, 3), text_size = size.small)
    table.cell(tbl, 1, 0, 'WINRATE%',      text_halign = text.align_center, bgcolor = color.rgb(255, 255, 255), text_color = color.rgb(0, 0, 0), text_size = size.small)
    table.cell(tbl, 3, 0, 'PNL',        text_halign = text.align_center, bgcolor = color.rgb(255, 255, 255), text_color = color.rgb(7, 7, 7), text_size = size.small)
    table.cell(tbl,0,1,"BTCUSDT",text_halign = text.align_center, bgcolor = color.rgb(239, 255, 67), text_color = color.rgb(0, 0, 0), text_size = size.small)
    if BTCUSDT >= 50
        table.cell(tbl,1,1,str.tostring(BTCUSDT,"0.00"),text_halign = text.align_center, bgcolor = color.rgb(101, 255, 74), text_color = color.rgb(3, 3, 3), text_size = size.small)
    else
        table.cell(tbl,1,1,str.tostring(BTCUSDT,"0.00"),text_halign = text.align_center, bgcolor = color.rgb(255, 74, 74), text_color = color.rgb(255, 255, 255), text_size = size.small)
    table.cell(tbl,0,2,"ADAUSDT",text_halign = text.align_center, bgcolor = color.rgb(239, 255, 67), text_color = color.rgb(0, 0, 0), text_size = size.small)
    if ADAUSDT >= 50
        table.cell(tbl,1,2,str.tostring(ADAUSDT,"0.00"),text_halign = text.align_center, bgcolor = color.rgb(101, 255, 74), text_color = color.rgb(3, 3, 3), text_size = size.small)
    else
        table.cell(tbl,1,2,str.tostring(ADAUSDT,"0.00"),text_halign = text.align_center, bgcolor = color.rgb(255, 74, 74), text_color = color.rgb(255, 255, 255), text_size = size.small)
    table.cell(tbl,0,3,"DOTUSDT",text_halign = text.align_center, bgcolor = color.rgb(239, 255, 67), text_color = color.rgb(0, 0, 0), text_size = size.small)
    if DOTUSDT >= 50
        table.cell(tbl,1,3,str.tostring(DOTUSDT,"0.00"),text_halign = text.align_center, bgcolor = color.rgb(101, 255, 74), text_color = color.rgb(3, 3, 3), text_size = size.small)
    else
        table.cell(tbl,1,3,str.tostring(DOTUSDT,"0.00"),text_halign = text.align_center, bgcolor = color.rgb(255, 74, 74), text_color = color.rgb(255, 255, 255), text_size = size.small)
    table.cell(tbl,0,4,"1INCHUSDT",text_halign = text.align_center, bgcolor = color.rgb(239, 255, 67), text_color = color.rgb(0, 0, 0), text_size = size.small)
    if INCHUSDT >= 50
        table.cell(tbl,1,4,str.tostring(INCHUSDT,"0.00"),text_halign = text.align_center, bgcolor = color.rgb(101, 255, 74), text_color = color.rgb(3, 3, 3), text_size = size.small)
    else
        table.cell(tbl,1,4,str.tostring(INCHUSDT,"0.00"),text_halign = text.align_center, bgcolor = color.rgb(255, 74, 74), text_color = color.rgb(255, 255, 255), text_size = size.small)

iam expecting that it should plot the winrate of different symbols in each row. but it is not doing that Actually iam new to pinescript and stackoverflow. so if there is any mistake please ignore it.and please guide me

1 Answers1

0

The strategy script can execute trades and therefore calculate the strategy result only on the currently selected symbol on the chart. You can access data from another symbol through request.security(), but you cannot execute strategy orders on another symbol.

Therefore, it is not possible to calculate winrate based on strategy.* commands, since they only refer to the current chart's symbol.

e2e4
  • 3,428
  • 6
  • 18
  • 30
  • will you please provide another way to do that. eg we can make the indicator for buy sell and calulate the percent profitable value and net profit for different symbols – Welder Pasha Jul 01 '23 at 10:23
  • Yeah, with an indicator type of script, you can manually track the required conditions and calculate whatever you want, however, it will require replicating the entire strategy backtesting framework. You can find examples of such frameworks in the community library and adapt to the security() calls accordingly, eg - https://www.tradingview.com/script/DTYsoEN1-fareid-Quick-Backtest-Framework/ – e2e4 Jul 01 '23 at 10:46