Rishav Mundhra
Rishav Mundhra

Reputation: 21

Tradingview - Number of Trades

I am using tradingview to backtest a strategy, that works the following way - I enter the trade at x lots. I then place a profit target order with x/2 lots and stop loss with x lots. If my Profit target gets executed I place a trailing stop loss with the remaining lots. Now, the issue that I am facing is that tradingview counts my partial exits as two separate trades, thus affecting the performance indicators. As of now I have to copy all my data to excel, change the number of trades and then calculate the performance metrics. Please suggest if there is way to get the partial exit trade counted as one trade and not two on tradingview. Thanks in advance

Upvotes: 2

Views: 902

Answers (1)

doppelgunner
doppelgunner

Reputation: 649

Yes, one way I know is to create a global variable

var arrGainLoss = array.new_float()

Then after all your trades are closed add it to the array.

array.push(arrGainLoss, gainLoss)

That way you can calculate the results later at the last bar and display it using table or label...

if barstate.islast
    win = 0
    loss = 0
    breakeven = 0
    for i to array.size(arrGainLoss)
        if (array.get(arrGainLoss, i) > 0)
            win := win + 1
        else
            loss := loss + 1
    totalTrades = (win + loss)
    hitRate = win  / (totalTrades)

Upvotes: 2

Related Questions