Last active
May 23, 2019 01:13
-
-
Save snowkidind/424ad893452cae52dbcc513385d213cf to your computer and use it in GitHub Desktop.
median
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
median: function (high_array, low_array) { | |
let error = false; | |
const highs = trimArrayTailToSize(high_array, 100); | |
const lowArr = trimArrayTailToSize(low_array, 100); | |
const lows = detectBadLowData(lowArr); | |
const precision = findPrecision(highs); | |
const low = getLow(lows); | |
const li = getLowIndex(lows); | |
// if the most recent candle is the lowest low on the scannable area then | |
// there is no point to running this, try a larger time frame | |
if (li === 0){ | |
console.log("median:Low Index is zero, check comments."); | |
error = "Cannot calculate plot without a completed low cycle, try to use a larger timeframe, or wait until low completes." | |
} | |
let postLow = []; | |
for (let i = 0; i < li; i++) { | |
postLow.push(highs[i]); // crop out pre-low data | |
} | |
const high = getHigh(postLow); | |
const median = low + ((high - low) / 2); | |
const diff = high - low; | |
const hiT = median + diff; | |
const h = round(high, precision); // what a bitch | |
const l = round(low, precision); | |
const m = round(median, precision); | |
const ht = round(hiT, precision); | |
return {median: m, low: l, high: h, highTarget: ht, error: error}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment