Time Frame Refectoring
This commit is contained in:
1 parent
faeeb0955d
commit
64dcc390a2
2 files changed
+60
-60
No files matched your search
+30
-30
@@ -14,7 +14,7 @@
|
||||
finalize: finalize,
|
||||
container: undefined,
|
||||
getContainer: getContainer,
|
||||
setTimePeriod: setTimePeriod,
|
||||
setTimeFrame: setTimeFrame,
|
||||
setDatetime: setDatetime,
|
||||
draw: draw,
|
||||
recalculateScale: recalculateScale,
|
||||
@@ -36,14 +36,14 @@
|
||||
|
||||
let timeLineCoordinateSystem = newTimeLineCoordinateSystem(); // Needed to be able to plot on the timeline, otherwise not.
|
||||
|
||||
let timePeriod; // This will hold the current Time Period the user is at.
|
||||
let timeFrame; // This will hold the current Time Frame the user is at.
|
||||
let datetime; // This will hold the current Datetime the user is at.
|
||||
|
||||
let marketFile; // This is the current Market File being plotted.
|
||||
let fileCursor; // This is the current File Cursor being used to retrieve Daily Files.
|
||||
|
||||
let marketFiles; // This object will provide the different Market Files at different Time Periods.
|
||||
let dailyFiles; // This object will provide the different File Cursors at different Time Periods.
|
||||
let marketFiles; // This object will provide the different Market Files at different Time Frames.
|
||||
let dailyFiles; // This object will provide the different File Cursors at different Time Frames.
|
||||
|
||||
/* these are module specific variables: */
|
||||
|
||||
@@ -76,7 +76,7 @@
|
||||
dailyFiles = undefined;
|
||||
|
||||
datetime = undefined;
|
||||
timePeriod = undefined;
|
||||
timeFrame = undefined;
|
||||
|
||||
marketFile = undefined;
|
||||
fileCursor = undefined;
|
||||
@@ -87,7 +87,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
function initialize(pStorage, pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) {
|
||||
function initialize(pStorage, pExchange, pMarket, pDatetime, pTimeFrame, callBackFunction) {
|
||||
|
||||
try {
|
||||
|
||||
@@ -97,7 +97,7 @@
|
||||
dailyFiles = pStorage.dailyFiles[0];
|
||||
|
||||
datetime = pDatetime;
|
||||
timePeriod = pTimePeriod;
|
||||
timeFrame = pTimeFrame;
|
||||
|
||||
/* We need a Market File in order to calculate the Y scale, since this scale depends on actual data. */
|
||||
|
||||
@@ -107,8 +107,8 @@
|
||||
|
||||
/* Now we set the right files according to current Period. */
|
||||
|
||||
marketFile = marketFiles.getFile(pTimePeriod);
|
||||
fileCursor = dailyFiles.getFileCursor(pTimePeriod);
|
||||
marketFile = marketFiles.getFile(pTimeFrame);
|
||||
fileCursor = dailyFiles.getFileCursor(pTimeFrame);
|
||||
|
||||
/* Listen to the necesary events. */
|
||||
|
||||
@@ -162,7 +162,7 @@
|
||||
|
||||
function onMarketFilesUpdated() {
|
||||
try {
|
||||
let newMarketFile = marketFiles.getFile(timePeriod);
|
||||
let newMarketFile = marketFiles.getFile(timeFrame);
|
||||
if (newMarketFile !== undefined) {
|
||||
marketFile = newMarketFile;
|
||||
recalculate();
|
||||
@@ -174,7 +174,7 @@
|
||||
|
||||
function onDailyFilesUpdated() {
|
||||
try {
|
||||
let newFileCursor = dailyFiles.getFileCursor(timePeriod);
|
||||
let newFileCursor = dailyFiles.getFileCursor(timeFrame);
|
||||
if (newFileCursor !== undefined) {
|
||||
fileCursor = newFileCursor;
|
||||
recalculate();
|
||||
@@ -184,21 +184,21 @@
|
||||
}
|
||||
}
|
||||
|
||||
function setTimePeriod(pTimePeriod) {
|
||||
function setTimeFrame(pTimeFrame) {
|
||||
|
||||
try {
|
||||
if (timePeriod !== pTimePeriod) {
|
||||
timePeriod = pTimePeriod;
|
||||
if (timeFrame !== pTimeFrame) {
|
||||
timeFrame = pTimeFrame;
|
||||
|
||||
if (timePeriod >= _1_HOUR_IN_MILISECONDS) {
|
||||
let newMarketFile = marketFiles.getFile(pTimePeriod);
|
||||
if (timeFrame >= _1_HOUR_IN_MILISECONDS) {
|
||||
let newMarketFile = marketFiles.getFile(pTimeFrame);
|
||||
if (newMarketFile !== undefined) {
|
||||
marketFile = newMarketFile;
|
||||
recalculate();
|
||||
}
|
||||
|
||||
} else {
|
||||
let newFileCursor = dailyFiles.getFileCursor(pTimePeriod);
|
||||
let newFileCursor = dailyFiles.getFileCursor(pTimeFrame);
|
||||
if (newFileCursor !== undefined) {
|
||||
fileCursor = newFileCursor;
|
||||
recalculate();
|
||||
@@ -208,7 +208,7 @@
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] setTimePeriod -> err = " + err.stack); }
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] setTimeFrame -> err = " + err.stack); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -357,7 +357,7 @@
|
||||
|
||||
try {
|
||||
|
||||
if (timePeriod >= _1_HOUR_IN_MILISECONDS) {
|
||||
if (timeFrame >= _1_HOUR_IN_MILISECONDS) {
|
||||
|
||||
recalculateUsingMarketFiles();
|
||||
|
||||
@@ -383,7 +383,7 @@
|
||||
|
||||
if (fileCursor.files.size === 0) { return; } // We need to wait until there are files in the cursor
|
||||
|
||||
let daysOnSides = getSideDays(timePeriod);
|
||||
let daysOnSides = getSideDays(timeFrame);
|
||||
|
||||
let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem);
|
||||
let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem);
|
||||
@@ -469,7 +469,7 @@
|
||||
|
||||
if (marketFile === undefined) { return; } // Initialization not complete yet.
|
||||
|
||||
let daysOnSides = getSideDays(timePeriod);
|
||||
let daysOnSides = getSideDays(timeFrame);
|
||||
|
||||
let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem);
|
||||
let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem);
|
||||
@@ -570,22 +570,22 @@
|
||||
candle = candles[i];
|
||||
|
||||
candle.candlePoint1 = {
|
||||
x: candle.begin + timePeriod / 7 * 1.5,
|
||||
x: candle.begin + timeFrame / 7 * 1.5,
|
||||
y: candle.open
|
||||
};
|
||||
|
||||
candle.candlePoint2 = {
|
||||
x: candle.begin + timePeriod / 7 * 5.5,
|
||||
x: candle.begin + timeFrame / 7 * 5.5,
|
||||
y: candle.open
|
||||
};
|
||||
|
||||
candle.candlePoint3 = {
|
||||
x: candle.begin + timePeriod / 7 * 5.5,
|
||||
x: candle.begin + timeFrame / 7 * 5.5,
|
||||
y: candle.close
|
||||
};
|
||||
|
||||
candle.candlePoint4 = {
|
||||
x: candle.begin + timePeriod / 7 * 1.5,
|
||||
x: candle.begin + timeFrame / 7 * 1.5,
|
||||
y: candle.close
|
||||
};
|
||||
|
||||
@@ -605,22 +605,22 @@
|
||||
candle.candlePoint4 = viewPort.fitIntoVisibleArea(candle.candlePoint4);
|
||||
|
||||
candle.stickPoint1 = {
|
||||
x: candle.begin + timePeriod / 7 * 3.2,
|
||||
x: candle.begin + timeFrame / 7 * 3.2,
|
||||
y: candle.max
|
||||
};
|
||||
|
||||
candle.stickPoint2 = {
|
||||
x: candle.begin + timePeriod / 7 * 3.8,
|
||||
x: candle.begin + timeFrame / 7 * 3.8,
|
||||
y: candle.max
|
||||
};
|
||||
|
||||
candle.stickPoint3 = {
|
||||
x: candle.begin + timePeriod / 7 * 3.8,
|
||||
x: candle.begin + timeFrame / 7 * 3.8,
|
||||
y: candle.min
|
||||
};
|
||||
|
||||
candle.stickPoint4 = {
|
||||
x: candle.begin + timePeriod / 7 * 3.2,
|
||||
x: candle.begin + timeFrame / 7 * 3.2,
|
||||
y: candle.min
|
||||
};
|
||||
|
||||
@@ -770,7 +770,7 @@
|
||||
stickHeight: candle.stickPoint4.y - candle.stickPoint2.y,
|
||||
stickWidth: candle.stickPoint2.x - candle.stickPoint1.x,
|
||||
stickStart: candle.candlePoint2.y - candle.stickPoint2.y,
|
||||
period: timePeriod,
|
||||
period: timeFrame,
|
||||
innerCandle: candle
|
||||
};
|
||||
thisObject.container.eventHandler.raiseEvent("Current Candle Changed", currentCandle);
|
||||
|
||||
+30
-30
@@ -18,7 +18,7 @@
|
||||
finalize: finalize,
|
||||
container: undefined,
|
||||
getContainer: getContainer,
|
||||
setTimePeriod: setTimePeriod,
|
||||
setTimeFrame: setTimeFrame,
|
||||
setDatetime: setDatetime,
|
||||
recalculateScale: recalculateScale,
|
||||
draw: draw
|
||||
@@ -32,14 +32,14 @@
|
||||
let timeLineCoordinateSystem = newTimeLineCoordinateSystem(); // Needed to be able to plot on the timeline, otherwise not.
|
||||
let plotAreaFrame = newTimeLineCoordinateSystem(); // This chart uses this extra object.
|
||||
|
||||
let timePeriod; // This will hold the current Time Period the user is at.
|
||||
let timeFrame; // This will hold the current Time Frame the user is at.
|
||||
let datetime; // This will hold the current Datetime the user is at.
|
||||
|
||||
let marketFile; // This is the current Market File being plotted.
|
||||
let fileCursor; // This is the current File Cursor being used to retrieve Daily Files.
|
||||
|
||||
let marketFiles; // This object will provide the different Market Files at different Time Periods.
|
||||
let dailyFiles; // This object will provide the different File Cursors at different Time Periods.
|
||||
let marketFiles; // This object will provide the different Market Files at different Time Frames.
|
||||
let dailyFiles; // This object will provide the different File Cursors at different Time Frames.
|
||||
|
||||
let scaleFile; // This file is used to calculate the scale.
|
||||
|
||||
@@ -74,7 +74,7 @@
|
||||
dailyFiles = undefined;
|
||||
|
||||
datetime = undefined;
|
||||
timePeriod = undefined;
|
||||
timeFrame = undefined;
|
||||
|
||||
marketFile = undefined;
|
||||
fileCursor = undefined;
|
||||
@@ -85,7 +85,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
function initialize(pStorage, pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) {
|
||||
function initialize(pStorage, pExchange, pMarket, pDatetime, pTimeFrame, callBackFunction) {
|
||||
|
||||
try {
|
||||
|
||||
@@ -95,7 +95,7 @@
|
||||
dailyFiles = pStorage.dailyFiles[0];
|
||||
|
||||
datetime = pDatetime;
|
||||
timePeriod = pTimePeriod;
|
||||
timeFrame = pTimeFrame;
|
||||
|
||||
/* We need a Market File in order to calculate the Y scale, since this scale depends on actual data. */
|
||||
|
||||
@@ -103,8 +103,8 @@
|
||||
|
||||
/* Now we set the right files according to current Period. */
|
||||
|
||||
marketFile = marketFiles.getFile(pTimePeriod);
|
||||
fileCursor = dailyFiles.getFileCursor(pTimePeriod);
|
||||
marketFile = marketFiles.getFile(pTimeFrame);
|
||||
fileCursor = dailyFiles.getFileCursor(pTimeFrame);
|
||||
|
||||
/* Listen to the necesary events. */
|
||||
|
||||
@@ -169,7 +169,7 @@
|
||||
|
||||
function onMarketFilesUpdated() {
|
||||
try {
|
||||
let newMarketFile = marketFiles.getFile(timePeriod);
|
||||
let newMarketFile = marketFiles.getFile(timeFrame);
|
||||
if (newMarketFile !== undefined) {
|
||||
marketFile = newMarketFile;
|
||||
recalculateScaleX();
|
||||
@@ -183,7 +183,7 @@
|
||||
|
||||
function onDailyFilesUpdated() {
|
||||
try {
|
||||
let newFileCursor = dailyFiles.getFileCursor(timePeriod);
|
||||
let newFileCursor = dailyFiles.getFileCursor(timeFrame);
|
||||
if (newFileCursor !== undefined) {
|
||||
fileCursor = newFileCursor;
|
||||
recalculateScaleX();
|
||||
@@ -195,17 +195,17 @@
|
||||
}
|
||||
}
|
||||
|
||||
function setTimePeriod(pTimePeriod) {
|
||||
function setTimeFrame(pTimeFrame) {
|
||||
|
||||
try {
|
||||
|
||||
if (timePeriod !== pTimePeriod) {
|
||||
if (timeFrame !== pTimeFrame) {
|
||||
|
||||
timePeriod = pTimePeriod;
|
||||
timeFrame = pTimeFrame;
|
||||
|
||||
if (timePeriod >= _1_HOUR_IN_MILISECONDS) {
|
||||
if (timeFrame >= _1_HOUR_IN_MILISECONDS) {
|
||||
|
||||
let newMarketFile = marketFiles.getFile(pTimePeriod);
|
||||
let newMarketFile = marketFiles.getFile(pTimeFrame);
|
||||
|
||||
if (newMarketFile !== undefined) {
|
||||
|
||||
@@ -215,7 +215,7 @@
|
||||
|
||||
} else {
|
||||
|
||||
let newFileCursor = dailyFiles.getFileCursor(pTimePeriod);
|
||||
let newFileCursor = dailyFiles.getFileCursor(pTimeFrame);
|
||||
|
||||
if (newFileCursor !== undefined) {
|
||||
|
||||
@@ -227,7 +227,7 @@
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] setTimePeriod -> err = " + err.stack); }
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] setTimeFrame -> err = " + err.stack); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,7 +277,7 @@
|
||||
|
||||
try {
|
||||
|
||||
if (timePeriod >= _1_HOUR_IN_MILISECONDS) {
|
||||
if (timeFrame >= _1_HOUR_IN_MILISECONDS) {
|
||||
|
||||
recalculateUsingMarketFiles();
|
||||
|
||||
@@ -471,9 +471,9 @@
|
||||
y: 0
|
||||
};
|
||||
|
||||
let timePeriodRatio = ONE_DAY_IN_MILISECONDS / timePeriod;
|
||||
let timeFrameRatio = ONE_DAY_IN_MILISECONDS / timeFrame;
|
||||
|
||||
maxValue.y = getMaxVolume() / (timePeriodRatio / 2.5);
|
||||
maxValue.y = getMaxVolume() / (timeFrameRatio / 2.5);
|
||||
|
||||
timeLineCoordinateSystem.initializeY(
|
||||
minValue,
|
||||
@@ -555,22 +555,22 @@
|
||||
function calculateBuys(plot, height) {
|
||||
|
||||
volumePointA1 = {
|
||||
x: volume.begin + timePeriod / 7 * 2,
|
||||
x: volume.begin + timeFrame / 7 * 2,
|
||||
y: 0
|
||||
};
|
||||
|
||||
volumePointA2 = {
|
||||
x: volume.begin + timePeriod / 7 * 2,
|
||||
x: volume.begin + timeFrame / 7 * 2,
|
||||
y: volume.amountBuy
|
||||
};
|
||||
|
||||
volumePointA3 = {
|
||||
x: volume.begin + timePeriod / 7 * 5,
|
||||
x: volume.begin + timeFrame / 7 * 5,
|
||||
y: volume.amountBuy
|
||||
};
|
||||
|
||||
volumePointA4 = {
|
||||
x: volume.begin + timePeriod / 7 * 5,
|
||||
x: volume.begin + timeFrame / 7 * 5,
|
||||
y: 0
|
||||
};
|
||||
|
||||
@@ -620,22 +620,22 @@
|
||||
function calculateSells(plot, height) {
|
||||
|
||||
volumePointB1 = {
|
||||
x: volume.begin + timePeriod / 7 * 2,
|
||||
x: volume.begin + timeFrame / 7 * 2,
|
||||
y: height
|
||||
};
|
||||
|
||||
volumePointB2 = {
|
||||
x: volume.begin + timePeriod / 7 * 2,
|
||||
x: volume.begin + timeFrame / 7 * 2,
|
||||
y: height - volume.amountSell
|
||||
};
|
||||
|
||||
volumePointB3 = {
|
||||
x: volume.begin + timePeriod / 7 * 5,
|
||||
x: volume.begin + timeFrame / 7 * 5,
|
||||
y: height - volume.amountSell
|
||||
};
|
||||
|
||||
volumePointB4 = {
|
||||
x: volume.begin + timePeriod / 7 * 5,
|
||||
x: volume.begin + timeFrame / 7 * 5,
|
||||
y: height
|
||||
};
|
||||
|
||||
@@ -775,7 +775,7 @@
|
||||
let currentVolume = {
|
||||
buyInfo: buyInfo,
|
||||
sellInfo: sellInfo,
|
||||
period: timePeriod,
|
||||
period: timeFrame,
|
||||
innerVolumeBar: volume
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user