Mathieu2301 / TradingView-API

📈 Get real-time stocks from TradingView
1.47k stars 332 forks source link

Strategy Optimization Steps #73

Open robert-hopla opened 2 years ago

robert-hopla commented 2 years ago

Hey Mathieu, have been playing with your library, very promising!!

I have some questions I have you can help me figure out: 1) how to download a specific time range/timeframe of data before starting a strategy backtest 3) how to select and get the strategy inputs 2) how to set the ranges of inputs for which to backtest the strategy

instead of backtest inputs "2", input ranges: "2-5" with step size: "1", for example 3) how to export the performance summary for every combination of inputs

When backtesting in the browser, changing the inputs instantly updates the performance summary. You think this is run in the browser? Or does it actually come from the server this fast?

have you tested if this can be done multithreaded? do they throttle you?

Super excited about this! would mean i no longer have to code in EasyLanguage to optimize :)

silver-hopla commented 2 years ago

hey @robert-hopla ,

  1. You can set the timeframe and range (# of periods) in setMarket's options parameter.
  2. I was able to get the indicator / strategy id from this URL: https://pine-facade.tradingview.com/pine-facade/list/?filter=standard (the scriptIdPart of the response.)
  3. Here's a sample code of how you would get the performance summary of a strategy:
    
    const TradingView = require('../main');
    const fs = require('fs');

/ This example tests fetching chart data of a number of candles before or after a timestamp /

const client = new TradingView.Client(); const chart = new client.Session.Chart(); chart.setMarket('BINANCE:BTCEUR', { timeframe: '60', currency: 'EUR', });

TradingView.getIndicator('STD;Bollinger%1Bands%1Strategy').then(async (indic) => { console.log(Loading '${indic.description}' study...); const study = new chart.Study(indic); study.onUpdate(() => { const performance = SUPERTREND.strategyReport.performance; console.log('performance', performance); client.end(); }); });

Mathieu2301 commented 2 years ago

how to download a specific time range/timeframe of data before starting a strategy backtest

how to set the ranges of inputs for which to backtest the strategy

You can use Fake replay mode or Real replay mode.

how to export the performance summary for every combination of inputs

There is no shortcut, you have to test them all. You can do it synchronously or asynchronously, it doesn't matter.

When backtesting in the browser, changing the inputs instantly updates the performance summary. You think this is run in the browser? Or does it actually come from the server this fast?

The PineScript engine is server-side.

have you tested if this can be done multithreaded? do they throttle you?

I've never had a throttling issue. I advise against abusing it anyway.

All you need is in the ./examples directory.