akumidv / tradingview-assistant-chrome-extension

An assistant for backtesting trading strategies and checking (showing) external signals in Tradingview implemented as a Chrome browser extension.
GNU General Public License v3.0
176 stars 63 forks source link

DeepBacktesting Issue - first run of deep-backtesting optimization does not get strategy parameters accurately. #153

Closed stefantabakovq closed 10 months ago

stefantabakovq commented 1 year ago

When running deep backtesting optimization, the first run "getting initial parameters" appears to get incorrect parameters, and sets the optimization parameter to a random value.

Any idea of the idea why that is? I think deep optimization is broken...

This is pre-optimization params of deep-backtesting

pre-optimization

This is first run of deep-optimization

first-run

As you can see, when running the deep-opti, it seems to set random params at start....

@akumidv

stefantabakovq commented 1 year ago

Have you tried reproducing this error?

akumidv commented 1 year ago

@stefantabakovq thank you, I'll try today

akumidv commented 1 year ago

Yes, I reproduced. Extension start with default parameter for deepbacktesting for me for some strategies. The problem there that the best start parameters that tested in standard mode before deep mode backtesting is different for deepmode. I'll think how to solve it. There two options exactly. First - for deep backtesting use only last best parameters. The second recheck best parameters in deepmode.

The only random method - is not reproduced for me. It's working for me in another methods too

akumidv commented 1 year ago

It was already implemented, I forgot. The init stage contained an error, I fixed it. New version have sent to review to google webstore and will published after that. Thank you for this issue.

stefantabakovq commented 1 year ago

@akumidv It seems to have started happening again, :( It was working for about a month and now started getting random values for initial parameters.

stefantabakovq commented 12 months ago

@akumidv Any ideas? Basically, most of the time deep backtesting starts with 0 for the performance param I want to optimize for, or takes some random values for the params.. Like last time, I am guessing TV changed something in the UI again, but I don't see any errors

akumidv commented 12 months ago

@akumidv Any ideas? Basically, most of the time deep backtesting starts with 0 for the performance param I want to optimize for, or takes some random values for the params.. Like last time, I am guessing TV changed something in the UI again, but I don't see any errors

Didn't reprodduce it yet. Can you attach the part of log in browser console - before backtesting iteration. That part where is checking best start condition (from current parameters, previous best found)?

stefantabakovq commented 12 months ago

www.tradingview.com-1696689433254.log

and a video of the error: https://we.tl/t-CwRvifaeFK

stefantabakovq commented 11 months ago

@akumidv Have you had the chance to look at this issue? I still can't get deep backtesting to run... The previous WeTransfer video expired; I'm uploading it again. https://we.tl/t-KapKyAmZA5

stefantabakovq commented 10 months ago

@akumidv I found a solution. TradingView has updated their UX so that the first iteration on clicking enable DeepBacktesting switch auto-generates the report; This then disables the generate report button and it does not allow it to get the correct data.

The way I've solved it for now is adding a global counter, of how many times we run tv.getPerformance and if it is the first time, skip looking for the Generate Report button.

let getPerformanceCallCount = 0;

tv.getPerformance = async (testResults, isIgnoreError=false) => {
  getPerformanceCallCount++; // Increment the counter
  let reportData = {}

  // let isProcessStart = await page.waitForSelector(SEL.strategyReportInProcess, 2500)
  let isProcessStart = false
  let isProcessEnd = false
  let isProcessError = null
  if (testResults.isDeepTest) {
    isProcessEnd = await tv.generateDeepTestReport(testResults.dataLoadingTime * 2000, getPerformanceCallCount)
    isProcessStart = isProcessEnd
    isProcessError = !isProcessEnd
  } else .......

and for generateDeepTestReport:


tv.generateDeepTestReport = async (loadingTime = 60000, callCount) => {
  const generateBtnEl = await page.waitForSelector(SEL.strategyDeepTestGenerateBtn)
  if (generateBtnEl) {
    if (callCount > 1){
      page.mouseClick(generateBtnEl)
    }
    const reportHeader = await page.waitForSelector(SEL.strategyReportHeader, loadingTime)
..........