TradingView-API icon indicating copy to clipboard operation
TradingView-API copied to clipboard

No "strategyReport.trades" data for private strategy backtest

Open klguang opened this issue 3 years ago • 0 comments

hello, there is a question, public strategy backtest has "strategyReport.trades" data,Indicator id: STD;Supertrend%Strategy but private strategy backtest has no "strategyReport.trades" data, Indicator id: USER;0dab3bee3026488c9c5c139aed1f1c06

Thanks very much.

test code

const TradingView = require('..//../main');

const client = new TradingView.Client();

client.onError((...error) => { err('Client error', error); throw new Error('Client error'); });

const chart = new client.Session.Chart(); chart.setMarket('BINANCE:ETHUSDT', { timeframe: '240', });

chart.onError((...error) => { err('Chart error', error); throw new Error('Chart error'); });

//TradingView.getIndicator('STD;Supertrend%Strategy').then((indicator) => { TradingView.getIndicator('USER;0dab3bee3026488c9c5c139aed1f1c06').then((indicator) => {

const SuperTrend = new chart.Study(indicator);

SuperTrend.onError((...error) => {
    err('SuperTrend error', error[0]);
    throw new Error('SuperTrend error');
});

SuperTrend.onUpdate(async () => {

    const perfReport= SuperTrend.strategyReport.performance;
    
    success("trades", SuperTrend.strategyReport.trades[0])
    success('Performances:', {
        total: {
        trades: perfReport.all.totalTrades,
        perf: `${Math.round(perfReport.all.netProfitPercent * 10000) / 100} %`,
        },
        buy: {
        trades: perfReport.long.totalTrades,
        perf: `${Math.round(perfReport.long.netProfitPercent * 10000) / 100} %`,
        },
        sell: {
        trades: perfReport.short.totalTrades,
        perf: `${Math.round(perfReport.short.netProfitPercent * 10000) / 100} %`,
        },
    });
    SuperTrend.remove();
    chart.delete();
    await client.end();
});  

});

function success(title,data){ console.log(title, data) }

klguang avatar Apr 15 '22 08:04 klguang