From e5251400a4d2a5a5ebd4d746601ec9cea687a5f5 Mon Sep 17 00:00:00 2001 From: c9s Date: Mon, 27 Jun 2022 16:56:31 +0800 Subject: [PATCH] add ampl and change percentage --- apps/backtest-report/components/TradingViewChart.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/apps/backtest-report/components/TradingViewChart.tsx b/apps/backtest-report/components/TradingViewChart.tsx index 4752197da..efa202c58 100644 --- a/apps/backtest-report/components/TradingViewChart.tsx +++ b/apps/backtest-report/components/TradingViewChart.tsx @@ -648,10 +648,12 @@ const createLegendUpdater = (legend: HTMLDivElement, prefix: string) => { const createOHLCLegendUpdater = (legend: HTMLDivElement, prefix: string) => { return (param: any, time : any) => { if (param) { - const change = param.close - param.open - const t = new Date(time * 1000) + const change = Math.round((param.close - param.open) * 100.0) / 100.0 + const changePercentage = Math.round((param.close - param.open) / param.close * 10000.0) / 100.0; + const ampl = Math.round((param.high - param.low) / param.low * 10000.0) / 100.0; + const t = new Date(time * 1000); const dateStr = moment(t).format("MMM Do YY hh:mm:ss A Z"); - legend.innerHTML = prefix + ` O: ${param.open} H: ${param.high} L: ${param.low} C: ${param.close} CHG: ${change} T: ${dateStr}`; + legend.innerHTML = prefix + ` O: ${param.open} H: ${param.high} L: ${param.low} C: ${param.close} CHG: ${change} (${changePercentage}%) AMP: ${ampl}% T: ${dateStr}`; } else { legend.innerHTML = prefix + ' O: - H: - L: - C: - T: -'; }