Skip to content

Instantly share code, notes, and snippets.

@charlesdarkwind
Last active January 23, 2023 05:53
Show Gist options
  • Save charlesdarkwind/7b56afb46de23dd2ceab708a8af16335 to your computer and use it in GitHub Desktop.
Save charlesdarkwind/7b56afb46de23dd2ceab708a8af16335 to your computer and use it in GitHub Desktop.
Ichimoku cloud Javascript node
const inputs = { tenkan: -9, kijun: -26, senkou: -52, chikou: -26 };
main['ichimoku_' + pair] = generateIchimoku(pair, false);
main['chikou_' + pair] = generateIchimoku(pair, true);
const generateIchimoku = (pair, isChikou) => {
const high = isChikou ? main.high[pair].slice(0, inputs.chikou) : main.high[pair];
const low = isChikou ? main.low[pair].slice(0, inputs.chikou) : main.low[pair];
const getHi = val => Math.max(...high.slice(val));
const getLo = val => Math.min(...low.slice(val));
const tenkan = (getHi(inputs.tenkan) + getLo(inputs.tenkan)) / 2;
const kijun = (getHi(inputs.kijun) + getLo(inputs.kijun)) / 2;
const spliceTo = isChikou ? main.high[pair].length + inputs.chikou * 2 : main.high[pair].length + inputs.chikou;
const tenkanOld = (Math.max(...high.slice(spliceTo + inputs.tenkan, spliceTo)) + Math.min(...low.slice(spliceTo + inputs.tenkan, spliceTo))) / 2;
const kijunOld = (Math.max(...high.slice(spliceTo + inputs.kijun, spliceTo)) + Math.min(...low.slice(spliceTo + inputs.kijun, spliceTo))) / 2;
const senkouA = (tenkanOld + kijunOld) / 2;
const senkouB = (Math.max(...high.slice(spliceTo + inputs.senkou, spliceTo)) + Math.min(...low.slice(spliceTo + inputs.senkou, spliceTo))) / 2;
return { tenkan, kijun, senkouA, senkouB };
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment