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

Strategy Optimization Steps

Open robert-hopla opened this issue 3 years ago • 2 comments

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
  2. how to select and get the strategy inputs
  3. 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

  1. 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 :)

robert-hopla avatar Feb 24 '22 02:02 robert-hopla

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();
  });
});

silver-hopla avatar Feb 24 '22 05:02 silver-hopla

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.

Mathieu2301 avatar Feb 24 '22 17:02 Mathieu2301