TradingView just recently added a feature to download your paper trading data. Unfortunately, it works only with pro accounts. But in this article, I’ll show you a hack that will allow you to export this data with any account.
So you already did a bunch of trades in your Paper Account and you have some history as I have in my TradingView:
To export this data you need to do the following. Open Developer tools in your Chrome (Brave) browser. To open Developer tools click on Chrome settings then More Tools -> Developer tools.
After that you’ll see a browser console open:
Cope the following Java Script code and execute it in your console:
// declaring functions
function tz(n) {
return n.replace(/([0-9]+(\.[0-9]+[1-9])?)(\.?0+$)/, "$1");
}
function mv(a, k) {
if (typeof k === "function") {
return a.push(k());
}
if (typeof k === "string") {
const reg = /^(\$)?(.+?)(?:\.(\d+))?(%)?$/;
const res = reg.exec(k);
if (!a.hasOwnProperty(res[2])) {
return;
}
res[1] = /*res[1] ||*/ "";
res[2] = a[res[2]];
res[3] = +res[3] || 0;
res[4] = /*res[4] ||*/ "";
if (res[2] === null) {
return "N/A";
}
if (res[4] === "%") {
res[2] *= 100;
}
if (k === "profitFactor" && res[2] < 1) {
res[2] *= -1;
}
return res[1] + tz(res[2].toFixed(res[3])) + res[4];
}
throw new TypeError("Unsupported type: " + typeof k);
}
function dt(timestamp) {
const D = new Date(timestamp);
const d = [D.getFullYear(), p(D.getMonth() + 1), p(D.getDate())].join("-");
const t = [p(D.getHours()), p(D.getMinutes()), p(D.getSeconds())].join(":");
return d + " " + t;
}
function p(x) {
return (x.length === 1 || x < 10) ? "0" + x : x;
}
function output(trades) {
let ret = [];
trades.items = trades.items.map(tab);
ret.push(trades.headings.join("\t"));
ret = ret.concat(trades.items);
return ret.join("\n");
}
function tab(array) {
return array.join("\t");
}
function clipboard(format, data) {
const tmp = document.oncopy;
document.oncopy = function clipboard_oncopy(e) {
e.clipboardData.setData(format, data);
e.preventDefault();
};
document.execCommand("copy", false, null);
alert("Copied to Clipboard");
document.oncopy = tmp;
}
// find React object from DOM node
function findReact(dom, traverseUp = 0) {
const key = Object.keys(dom).find(key=>{
return key.startsWith("__reactFiber$");
});
const domFiber = dom[key];
if (domFiber == null) return null;
const getCompFiber = fiber=>{
let parentFiber = fiber.return;
while (typeof parentFiber.type == "string") {
parentFiber = parentFiber.return;
}
return parentFiber;
};
let compFiber = getCompFiber(domFiber);
for (let i = 0; i < traverseUp; i++) {
compFiber = getCompFiber(compFiber);
}
return compFiber;
}
// defining variables
var props = findReact(document.querySelector(".js-page.active .ka-table"), 0).memoizedProps;
var data_new = props.data;
var columns_new = props.columns;
var sd_new = 4;
var headings = [];
var items = [];
for (col = 0; col < columns_new.length; col++) {
if (!columns_new[col].visible || !columns_new[col].title) continue;
headings.push(columns_new[col].title);
}
for (row = 0; row < data_new.length; row++) {
var record = [];
for (col = 0; col < columns_new.length; col++) {
if (!columns_new[col].visible || !columns_new[col].title) continue;
var val = data_new[row][columns_new[col].key];
if (typeof val === "undefined" || Number.isNaN(val)) {
val = "";
}
if (columns_new[col].key.match(/time/i)) {
val = dt(val);
}
if (columns_new[col].key === "exp") {
val = dt(val * 1000);
}
if (columns_new[col].key === "side") {
val = val === 1 ? "Buy" : "Sell";
}
if (columns_new[col].key === "type") {
val = val === 1 ? "Limit" : (val === 2 ? "Market" : (val === 3 ? "Stop" : val));
}
record.push(val);
}
items.push(record);
}
// parsing trades
let trades3 = {
headings: headings,
items: items
};
// Copying trades to the clipboard
clipboard("text/plain", output(trades3));
If everything went well you’ll see the following message:
And now you can past it to your Excel or Google Docs and it will be inserted as a nice table:
The beauty of this script is that it will copy any of the active tabs you have open on your paper tab. For example, here I’m running it on the Trading Journal tab:
And this exported the entire trading journal for me:
So you can see it’s an extremely simple way to export paper trading data from TradingView. To simplify it even more I’m thinking to create a Chrome Extension with these features. If you have any other ideas on what to add to it – let me know.
Follow me on TradingView and YouTube.