Skip to content

Instantly share code, notes, and snippets.

@snowkidind
Last active May 23, 2019 01:13
Show Gist options
  • Save snowkidind/424ad893452cae52dbcc513385d213cf to your computer and use it in GitHub Desktop.
Save snowkidind/424ad893452cae52dbcc513385d213cf to your computer and use it in GitHub Desktop.
median
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