Awesome thank so very much. Are you able to help me with this i added some more to the last one.
const predef = require(“./tools/predef”);
const EMA = require(“./tools/EMA”);
function rollingAvg(arr) {
if (!arr.length) return 0;
return arr.reduce((a, b) => a + b, 0) / arr.length;
}
class Jdog {
init() {
this.fastEMA = EMA(9);
this.slowEMA = EMA(21);
this.volEMA = EMA(20);
this.rangeHistory = ;
}
map(d) {
const open = d.open();
const high = d.high();
const low = d.low();
const close = d.close();
const volume = d.volume();
if (open === undefined || high === undefined || low === undefined || close === undefined || volume === undefined) {
return {};
}
const fast = this.fastEMA(close);
const slow = this.slowEMA(close);
const volAvg = this.volEMA(volume);
if (!fast || !slow || !volAvg) {
return {};
}
const upTrend = fast > slow;
const downTrend = fast < slow;
const barRange = high - low;
const closePos = barRange > 0 ? (close - low) / barRange : 0.5;
this.rangeHistory.push(barRange);
if (this.rangeHistory.length > 20) {
this.rangeHistory.shift();
}
const avgRange = rollingAvg(this.rangeHistory);
const isSpike = volume > volAvg * 1.5;
const isInstSize = volume > volAvg * 2.5;
const tinyRange = avgRange > 0 && barRange < avgRange * 0.4;
const isAbsorption = isInstSize && tinyRange;
const isClimaxBuy = isInstSize && closePos >= 0.70;
const isClimaxSell = isInstSize && closePos <= 0.30;
const isWideBar = avgRange > 0 && barRange > avgRange * 1.8;
const isAggressiveBuy = isInstSize && isWideBar && closePos >= 0.65 && close > open;
const isAggressiveSell = isInstSize && isWideBar && closePos <= 0.35 && close < open;
const instBuy = (isAbsorption && upTrend) || isClimaxBuy || isAggressiveBuy;
const instSell = (isAbsorption && downTrend) || isClimaxSell || isAggressiveSell;
const buySignal = !instBuy && !instSell && upTrend && isSpike ? 1 : 0;
const sellSignal = !instBuy && !instSell && downTrend && isSpike ? 1 : 0;
const volRatio = volAvg > 0 ? volume / volAvg : 1;
const base = Math.round(close / 100) * 100;
const gamma0 = base - 200;
const gamma1 = base - 100;
const gamma2 = base - 50;
const gamma3 = base;
const gamma4 = base + 50;
const gamma5 = base + 100;
const gamma6 = base + 200;
return {
volRatio,
buySignal,
sellSignal,
instBuy: instBuy ? 1 : 0,
instSell: instSell ? 1 : 0,
gamma0,
gamma1,
gamma2,
gamma3,
gamma4,
gamma5,
gamma6
};
}
filter(d) {
return d.volume() !== undefined;
}
}
module.exports = {
name: “jdog”,
description: “jdog Liquidity Volume Trend with Institutional Flow and Gamma Levels”,
calculator: Jdog,
plots: {
volRatio: { title: “Vol Ratio” },
buySignal: { title: “Buy” },
sellSignal: { title: “Sell” },
instBuy: { title: “Inst Buy” },
instSell: { title: “Inst Sell” },
gamma0: { title: “Gamma -200” },
gamma1: { title: “Gamma -100” },
gamma2: { title: “Gamma -50” },
gamma3: { title: “Key Level” },
gamma4: { title: “Gamma +50” },
gamma5: { title: “Gamma +100” },
gamma6: { title: “Gamma +200” }
},
schemeStyles: predef.styles.standard({
volRatio: { color: “#4fc3f7” },
buySignal: { color: “#00e676” },
sellSignal: { color: “#ff1744” },
instBuy: { color: “#00ffaa” },
instSell: { color: “#ff4466” },
gamma0: { color: “#ff4466”, lineWidth: 1 },
gamma1: { color: “#ff4466”, lineWidth: 1 },
gamma2: { color: “#ffaa00”, lineWidth: 1 },
gamma3: { color: “#ffffff”, lineWidth: 2 },
gamma4: { color: “#ffaa00”, lineWidth: 1 },
gamma5: { color: “#00ffaa”, lineWidth: 1 },
gamma6: { color: “#00ffaa”, lineWidth: 1 }
}),
plotter: [
predef.plotters.histogram(“volRatio”),
predef.plotters.custom(function(canvas, item) {
if (!item.buySignal) return;
var x = canvas.rect.x;
var y = canvas.rect.y;
var h = canvas.rect.height;
canvas.text(“BUY”, x, y + h - 6, {
textAlign: “center”,
fillStyle: “#00e676”,
font: “bold 10px sans-serif”
});
}),
predef.plotters.custom(function(canvas, item) {
if (!item.sellSignal) return;
var x = canvas.rect.x;
var y = canvas.rect.y;
canvas.text(“SELL”, x, y + 12, {
textAlign: “center”,
fillStyle: “#ff1744”,
font: “bold 10px sans-serif”
});
}),
predef.plotters.custom(function(canvas, item) {
if (!item.instBuy) return;
var x = canvas.rect.x;
var y = canvas.rect.y;
var h = canvas.rect.height;
canvas.text(“INST BUY”, x, y + h - 6, {
textAlign: “center”,
fillStyle: “#00ffaa”,
font: “bold 11px sans-serif”
});
}),
predef.plotters.custom(function(canvas, item) {
if (!item.instSell) return;
var x = canvas.rect.x;
var y = canvas.rect.y;
canvas.text(“INST SELL”, x, y + 12, {
textAlign: “center”,
fillStyle: “#ff4466”,
font: “bold 11px sans-serif”
});
})
]
};