From fa363bd92251b21649c2d412caee38377e4c9b16 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 26 Apr 2018 12:50:39 +0200 Subject: [PATCH] Plotting Sequence Files implemented --- .vs/Plotters-Trading/v15/.suo | Bin 26624 -> 27136 bytes History.js | 243 ++++++++++++++++++---------------- this.plotter.config.json | 2 +- 3 files changed, 131 insertions(+), 114 deletions(-) diff --git a/.vs/Plotters-Trading/v15/.suo b/.vs/Plotters-Trading/v15/.suo index 756b29c887ca32abee0c3f07134156d2b842a9f5..a8a02b08f4cda5dfd3d58ab296e372119088c5bf 100644 GIT binary patch delta 1536 zcmd5+Ur1A76!*Kk`=@tvo2F}Sdi~q{f0qQ-CR9@jn@vTbk&r|WRhC@JAlWQbfopC_vUp2RAaCqFY*2K8K>&9Of1jl6x$_MtBhSGhrWDg@X?_|C1u zQ!W4*ga245`pOZQB438wqRW)ihH|B@li#k(F632+YJ^C8CMF#NO}di;iJDPwK^#E% z5p4*vcj&wmxunZv51^b|9tpA}7s2}P9}y9p+Q&2a`2Y2W_DC1#z z*h*;!T9@k+MYj0;VvE)HA)Ns&&ghLzqtWA;?UM1qlC zU?W`an*m#2Da;>v=rE#%{(x(X-@KuF=_N?`C5Q*(H2A$Em3VNBwapxVuYTAl|FZS* z=4R^o^if>8{cx6WgH_ZQaYEw^a-j+PCi!)0XE4>bkPNN=Ym&KQ2ITEbnL4+?rzTCq zKKy?M(KL^o9@qwQ8eSDX-bZ+*ulP`Y;BDjZo?7tP(&ZzyYT4P$teiVE;=&KLJiX B1JwWk delta 1209 zcmb`F&ubG=5XW~mn`ZN4(`^%zR=4SA**RDbLJd6#UTpT_!GqGA)M`Xe{Tn=3h+rkg`d&>#o`5ML{m3T*=5i&S7O`4PZ@QL$Z7FK%?YHs3=teLIYo#pAf{7=i`- zEWU9AJL?1%Q!y+#Vy*3DkdVEUZRZH9Iy?9VA9}+OWcxsrY!A^&=tL*6o9H6Ci5{Yl zs4MQNpK;9-whGcPm|`3n@SUjpjJfD9!}O7#PE^Bm>2r;BAyRhJ*FEyT{+-7eZSqK$}gdf8-)(o04^!A=9#3uzRx$za|y01`iihBu9m zyr;5B$@Go60q9SD!j3cTE6N;;*CK9l`N{ zf$7jRmjX+nqRf-S^JZ)EqoP&rb&2`z0$@QgoJZ+Ow#xl3$<)Sw7q<+#k%nAcG$Z4G zlz`7pfYf>Ak5wE_o-G~ECvKpU@Zi#kCn_h*>*|9oZDghJ7_YY(R_5e1sL!rMy^Htv zm#&@d+t|FlwTRDCnwgmKbI%r(OGMDeihWaZ*QFwFF|)bUQ3<*WOwcVre!UhUY2t6;!p2kcJKnO3?{b&!Z#^B BdguTE diff --git a/History.js b/History.js index 227de904e..50378b898 100644 --- a/History.js +++ b/History.js @@ -32,8 +32,8 @@ /* these are module specific variables: */ - let file; // Here we keep the history records to be ploted every time the Draw() function is called by the AAWebPlatform. - let history = []; // This is where the history records are stored before plotting. + let files = []; // Here we keep the history records to be ploted every time the Draw() function is called by the AAWebPlatform. + let plotElements = []; // This is where the elements to be plotted are stored before plotting. return thisObject; @@ -42,7 +42,13 @@ datetime = pDatetime; timePeriod = pTimePeriod; - file = pStorage.file.getFile(); + let maxSequence = pStorage.fileSequence.getExpectedFiles(); + + for (let i = 0; i < maxSequence; i++) { + + file.push(pStorage.fileSequence.getFile(i)); + + } recalculate(); recalculateScale(); @@ -91,7 +97,7 @@ function recalculate() { - if (file === undefined) { return; } + if (files === undefined | files = []) { return; } /* @@ -100,29 +106,36 @@ */ - history = []; + for (let j = 0; j < files.length; j++) { - let oneMin = 60000; - let step = timePeriod / oneMin; + let file = files[j]; - for (let i = 0; i < file.length; i = i + step) { + let history = []; - let newHistoryRecord = { + let oneMin = 60000; + let step = timePeriod / oneMin; - date: Math.trunc(file[i][0] / 60000) * 60000 + 30000, - buyAvgRate: file[i][1], - sellAvgRate: file[i][2], - marketRate: file[i][3], - newPositions: file[i][4], - newTrades: file[i][5], - movedPositions: file[i][6], - profitsAssetA: file[i][7], - profitsAssetB: file[i][8], - combinedProfitsA: file[i][9], - combinedProfitsB: file[i][10] - }; + for (let i = 0; i < file.length; i = i + step) { - history.push(newHistoryRecord); + let newHistoryRecord = { + + date: Math.trunc(file[i][0] / 60000) * 60000 + 30000, + buyAvgRate: file[i][1], + sellAvgRate: file[i][2], + marketRate: file[i][3], + newPositions: file[i][4], + newTrades: file[i][5], + movedPositions: file[i][6], + profitsAssetA: file[i][7], + profitsAssetB: file[i][8], + combinedProfitsA: file[i][9], + combinedProfitsB: file[i][10] + }; + + history.push(newHistoryRecord); + } + + plotElements.push(history); } thisObject.container.eventHandler.raiseEvent("History Changed", history); @@ -157,121 +170,132 @@ let maxValue = 0; - for (let i = 0; i < file.length; i++) { + for (let j = 0; j < files.length; j++) { - let currentMax = file[i][1] + file[i][2]; // 1 = rates. + let file = files[j]; - if (maxValue < currentMax) { - maxValue = currentMax; + for (let i = 0; i < file.length; i++) { + + let currentMax = file[i][1] + file[i][2]; // 1 = rates. + + if (maxValue < currentMax) { + maxValue = currentMax; + } } } return maxValue; } - } function plotChart() { let point; + let history; - for (let i = 0; i < history.length; i++) { + for (let j = 0; j < plotElements.length; j++) { - record = history[i]; + let history = plotElements[j]; - point = { - x: record.date, - y: record.sellAvgRate - }; + for (let i = 0; i < history.length; i++) { - point = timeLineCoordinateSystem.transformThisPoint(point); - point = transformThisPoint(point, thisObject.container); + record = history[i]; - if (point.x < viewPort.visibleArea.bottomLeft.x || point.x > viewPort.visibleArea.bottomRight.x) { continue;} + point = { + x: record.date, + y: record.sellAvgRate + }; - point = viewPort.fitIntoVisibleArea(point); + point = timeLineCoordinateSystem.transformThisPoint(point); + point = transformThisPoint(point, thisObject.container); - let isCurrentRecord = false; + if (point.x < viewPort.visibleArea.bottomLeft.x || point.x > viewPort.visibleArea.bottomRight.x) { continue;} - if (datetime !== undefined) { - let dateValue = datetime.valueOf(); - if (dateValue >= record.date - timePeriod / 2 && dateValue <= record.date + timePeriod / 2 - 1) { - isCurrentRecord = true; + point = viewPort.fitIntoVisibleArea(point); + + let isCurrentRecord = false; + + if (datetime !== undefined) { + let dateValue = datetime.valueOf(); + if (dateValue >= record.date - timePeriod / 2 && dateValue <= record.date + timePeriod / 2 - 1) { + isCurrentRecord = true; + } } - } - let radiusFactor = 3; - let opacity = '0.2'; + let radiusFactor = 3; + let opacity = '0.2'; - let radius1 = record.newPositions * radiusFactor; - let radius2 = radius1 + record.movedPositions * radiusFactor; - let radius3 = radius2 + record.newTrades * radiusFactor; + let radius1 = record.newPositions * radiusFactor; + let radius2 = radius1 + record.movedPositions * radiusFactor; + let radius3 = radius2 + record.newTrades * radiusFactor; - browserCanvasContext.lineWidth = 1; + browserCanvasContext.lineWidth = 1; - /* Outer Circle */ + /* Outer Circle */ - browserCanvasContext.beginPath(); + browserCanvasContext.beginPath(); - browserCanvasContext.strokeStyle = 'rgba(27, 105, 7, ' + opacity + ')'; + browserCanvasContext.strokeStyle = 'rgba(27, 105, 7, ' + opacity + ')'; - if (isCurrentRecord === false) { - browserCanvasContext.fillStyle = 'rgba(64, 217, 26, ' + opacity + ')'; - } else { - browserCanvasContext.fillStyle = 'rgba(255, 233, 31, ' + opacity + ')'; /* highlight the current record */ + if (isCurrentRecord === false) { + browserCanvasContext.fillStyle = 'rgba(64, 217, 26, ' + opacity + ')'; + } else { + browserCanvasContext.fillStyle = 'rgba(255, 233, 31, ' + opacity + ')'; /* highlight the current record */ + } + + browserCanvasContext.arc(point.x, point.y, radius3, 0, Math.PI * 2, true); + browserCanvasContext.closePath(); + + if (point.x < viewPort.visibleArea.topLeft.x + 50 || point.x > viewPort.visibleArea.bottomRight.x - 50) {/*we leave this history without fill. */ } else { + browserCanvasContext.fill(); + } + + browserCanvasContext.stroke(); + + /* Middle Circle */ + + browserCanvasContext.beginPath(); + browserCanvasContext.strokeStyle = 'rgba(44, 61, 89, ' + opacity + ')'; + + if (isCurrentRecord === false) { + browserCanvasContext.fillStyle = 'rgba(50, 108, 201, ' + opacity + ')'; + } else { + browserCanvasContext.fillStyle = 'rgba(255, 233, 31, ' + opacity + ')'; /* highlight the current record */ + } + + browserCanvasContext.arc(point.x, point.y, radius2, 0, Math.PI * 2, true); + browserCanvasContext.closePath(); + + if (point.x < viewPort.visibleArea.topLeft.x + 50 || point.x > viewPort.visibleArea.bottomRight.x - 50) {/*we leave this history without fill. */ } else { + browserCanvasContext.fill(); + } + browserCanvasContext.stroke(); + + /* Inner Circle */ + + browserCanvasContext.beginPath(); + browserCanvasContext.strokeStyle = 'rgba(27, 7, 105, ' + opacity + ')'; + + if (isCurrentRecord === false) { + browserCanvasContext.fillStyle = 'rgba(64, 26, 217, ' + opacity + ')'; + } else { + browserCanvasContext.fillStyle = 'rgba(255, 233, 31, ' + opacity + ')'; /* highlight the current record */ + } + + browserCanvasContext.arc(point.x, point.y, radius1, 0, Math.PI * 2, true); + browserCanvasContext.closePath(); + + if (point.x < viewPort.visibleArea.topLeft.x + 50 || point.x > viewPort.visibleArea.bottomRight.x - 50) {/*we leave this history without fill. */ } else { + browserCanvasContext.fill(); + } + browserCanvasContext.stroke(); + + /* Since there is at least some point plotted, then the profile should be visible. */ + + thisObject.profile.visible = true; } - browserCanvasContext.arc(point.x, point.y, radius3, 0, Math.PI * 2, true); - browserCanvasContext.closePath(); - - if (point.x < viewPort.visibleArea.topLeft.x + 50 || point.x > viewPort.visibleArea.bottomRight.x - 50) {/*we leave this history without fill. */ } else { - browserCanvasContext.fill(); - } - - browserCanvasContext.stroke(); - - /* Middle Circle */ - - browserCanvasContext.beginPath(); - browserCanvasContext.strokeStyle = 'rgba(44, 61, 89, ' + opacity + ')'; - - if (isCurrentRecord === false) { - browserCanvasContext.fillStyle = 'rgba(50, 108, 201, ' + opacity + ')'; - } else { - browserCanvasContext.fillStyle = 'rgba(255, 233, 31, ' + opacity + ')'; /* highlight the current record */ - } - - browserCanvasContext.arc(point.x, point.y, radius2, 0, Math.PI * 2, true); - browserCanvasContext.closePath(); - - if (point.x < viewPort.visibleArea.topLeft.x + 50 || point.x > viewPort.visibleArea.bottomRight.x - 50) {/*we leave this history without fill. */ } else { - browserCanvasContext.fill(); - } - browserCanvasContext.stroke(); - - /* Inner Circle */ - - browserCanvasContext.beginPath(); - browserCanvasContext.strokeStyle = 'rgba(27, 7, 105, ' + opacity + ')'; - - if (isCurrentRecord === false) { - browserCanvasContext.fillStyle = 'rgba(64, 26, 217, ' + opacity + ')'; - } else { - browserCanvasContext.fillStyle = 'rgba(255, 233, 31, ' + opacity + ')'; /* highlight the current record */ - } - - browserCanvasContext.arc(point.x, point.y, radius1, 0, Math.PI * 2, true); - browserCanvasContext.closePath(); - - if (point.x < viewPort.visibleArea.topLeft.x + 50 || point.x > viewPort.visibleArea.bottomRight.x - 50) {/*we leave this history without fill. */ } else { - browserCanvasContext.fill(); - } - browserCanvasContext.stroke(); - - /* Since there is at least some point plotted, then the profile should be visible. */ - - thisObject.profile.visible = true; } /* @@ -285,12 +309,5 @@ thisObject.profile.position.y = point.y; } - function onZoomChanged(event) { - - } - - function onDragFinished() { - - } } diff --git a/this.plotter.config.json b/this.plotter.config.json index 565709a0e..73cd0f511 100644 --- a/this.plotter.config.json +++ b/this.plotter.config.json @@ -12,7 +12,7 @@ { "codeName": "History", "moduleName": "History", - "description": "Plots trading positions history.", + "description": "Plots trading history.", "profilePicture": "History.png", "panels": [] }