I want to plot one more row at the end of my stats to see the date and time of the first trade that was taken using my strategy script. i tried all strategy. functions like strategy.closedtrades etc but was not able to find out how to solve that.for reference if i open the strategy tester and click the list of trades and scroll down to the bottom there is the date of the first trade, this is the date i want to see in my backtester display.
// *** BACKTESTER DISPLAY ***
// Declare performance tracking variables
drawTester = input.bool(true, "Draw Tester", group="Draw Backtester on Chart")
var balance = strategy.initial_capital
var drawdown = 0.0
var maxDrawdown = 0.0
var maxBalance = 0.0
var totalWins = 0
var totalLoss = 0
// Prepare stats table
var table testTable1 = table.new(position.bottom_left, 2, 11, border_width=2)
f_fillCell1(_table, _column, _row, _title, _bgcolor, _txtcolor) =>
_cellText = _title + "\n"
table.cell(_table, _column, _row, _cellText, bgcolor=_bgcolor, text_color=_txtcolor, height = 3, text_halign="left")
// Prepare stats table
f_fillCell2(_table, _column, _row, _value, _bgcolor, _txtcolor) =>
_cellText = _value
table.cell(_table, _column, _row, _cellText, bgcolor=_bgcolor, text_color=_txtcolor, height = 3, text_halign="right")
// Custom function to truncate (cut) excess decimal places
truncate(_number, _decimalPlaces) =>
_factor = math.pow(10, _decimalPlaces)
int(_number * _factor) / _factor
// Draw stats table
var bgcolor = color.new(color.black,0)
if drawTester
if barstate.islastconfirmedhistory
// Update table
dollarReturn = strategy.netprofit
f_fillCell1(testTable1, 0, 0, "Total Trades:", bgcolor, color.white)
f_fillCell2(testTable1, 1, 0, str.tostring(strategy.closedtrades), bgcolor, color.white)
f_fillCell1(testTable1, 0, 1, "Win Rate %:", bgcolor, color.white)
f_fillCell2(testTable1, 1, 1, str.tostring(truncate((strategy.wintrades/strategy.closedtrades)*100,2)), bgcolor, color.white)
f_fillCell1(testTable1, 0, 2, "Starting $:", bgcolor, color.white)
f_fillCell2(testTable1, 1, 2, str.tostring(strategy.initial_capital), bgcolor, color.white)
f_fillCell1(testTable1, 0, 3, "Ending $:", bgcolor, color.white)
f_fillCell2(testTable1, 1, 3, str.tostring(truncate(strategy.initial_capital + strategy.netprofit,2)), bgcolor, color.white)
f_fillCell1(testTable1, 0, 4, "Avg Win $:", bgcolor, color.white)
f_fillCell2(testTable1, 1, 4, str.tostring(truncate(strategy.grossprofit / strategy.wintrades, 2)), bgcolor, color.white)
f_fillCell1(testTable1, 0, 5, "Avg Loss $:", bgcolor, color.white)
f_fillCell2(testTable1, 1, 5, str.tostring(truncate(strategy.grossloss / strategy.losstrades, 2)), bgcolor, color.white)
f_fillCell1(testTable1, 0, 6, "Profit Factor:", bgcolor, color.white)
f_fillCell2(testTable1, 1, 6, str.tostring(truncate(strategy.grossprofit / strategy.grossloss,2)), strategy.grossprofit > strategy.grossloss ? color.green : color.red, color.white)
f_fillCell1(testTable1, 0, 7, "Max Runup:", bgcolor, color.white)
f_fillCell2(testTable1, 1, 7, str.tostring(truncate(strategy.max_runup, 2 )), bgcolor, color.white)
f_fillCell1(testTable1, 0, 8, "Return:", bgcolor, color.white)
f_fillCell2(testTable1, 1, 8, (dollarReturn > 0 ? "+" : "") + str.tostring(truncate((dollarReturn / strategy.initial_capital)*100,2)) + "%", dollarReturn > 0 ? color.green : color.red, color.white)
f_fillCell1(testTable1, 0, 9, "Max DD:", bgcolor, color.white)
f_fillCell2(testTable1, 1, 9, str.tostring(truncate((strategy.max_drawdown / strategy.equity) * 100 ,2)) + "%", color.red, color.white)
// --- END TESTER CODE --- ///////////////
Use strategy.opentrades and record the time.
At the end of your code, just before the Backtester display part :
var int MyDate = na
if strategy.opentrades == 1 and na(MyDate)
MyDate := time
You can after modify your MyDate into a string with :
str.tostring(dayofmonth(MyDate))+"/"+str.tostring(month(MyDate))+"/"+str.tostring(year(MyDate))