Home > Software design >  Googlesheet importxml find value using xpath
Googlesheet importxml find value using xpath

Time:03-01

I need to get the integer value "maximum drawdown" from this website link =enter image description here

Note:

  • This sample formula is for the URL of https://www.mql5.com/en/signals/1414510. So if you change the URL and the specification of the site is changed, the sample formula might not be able to be used. Please be careful about this.

CodePudding user response:

by xpath

Try for enter image description here

i highly recommand to test first this formula to have an overview

=importxml(A1,"//div[@class='s-data-columns hoverable']")

by json

the second way could be to parse the json contained in the source (var radarChart)

function radarChart(url){
  var source = UrlFetchApp.fetch(url, {muteHttpExceptions: true}).getContentText().replace(/(\r\n|\n|\r|\t|  )/gm,"")
  var data = source.split(`new svgRadarChart($('radarChart'),[`)[1].split(']')[0]
  var values = (data.match(/value : ([^,] )/g))
  var names = (data.match(/name : ([^,] )/g))
  var val
  for (var i=0;i<names.length;i  ){if (names[i]==`name : 'Maximum drawdown'`){val=values[i]}}
  return (val)
}

enter image description here

            [
              {
                  value : 50.0,
                  name : 'Profit Trades',
                  title : 'The total amount of profitable trades. Their percentage of the total amount of trades is given in brackets. 38 (50.00%)'
              },
              {
                  value : 50.0,
                  name : 'Loss Trades',
                  title : 'The total amount of losing trades. Their percentage of the total amount of trades is given in brackets. 38 (50.00%)'
              },
              {
                  value : 14.8,
                  name : 'Trading activity',
                  title :
                      'Open orders were present on the trading account for 14.80% of time (0 days 21 hours 6 minutes) within the total Signal monitoring period (5 days 22 hours).'
              },
              {
                  value : 37.1,
                  name : 'Max deposit load',
                  title : 'Maximum experienced deposit load'
              },
              {
                  value : 59.8,
                  name : 'Maximum drawdown',
                  title : 'The money drawdown shows the maximal drawdown fixed in money terms and is the largest difference between the last maximum and the current minimum. It can exceed the absolute drawdown and helps to see the amount of possible loss even for a rather profitable trading. Its value at the moment of reaching this drawdown is given in percents in brackets. '
              },
              {
                  value : 0,
                  name : 'Algo trading',
                  title : 'Trades made by Expert Advisors'
              }
            ]
  • Related