Description
More Choco on the Taco
Comments (0)
0/2000
Loading comments…
Source code
function calculate(bars, ctx) {
const last = bars.length - 1;
if (last < 0) return;
// ── Inputs ──
const range = ctx.input('Range', 300, { min: 100, max: 1000, step: 100 });
const showTodayOnly = ctx.input('Show Today Only', true);
const centerRed80 = ctx.input('Center Red +80', true);
const centerGrn35 = ctx.input('Center Green +35', true);
const centerPnk64 = ctx.input('Center Pink +64', true);
const centerPnk6 = ctx.input('Center Pink +06', true);
const centerBlu0 = ctx.input('Center Blue +00', true);
const centerBlu10 = ctx.input('Center Blue +10', true);
const centerBlu20 = ctx.input('Center Blue +20', true);
const centerBlu50 = ctx.input('Center Blue +50', true);
const centerBlk47 = ctx.input('Center Black +47', true);
const centerBlk72 = ctx.input('Center Black +72', true);
const centerBlk86 = ctx.input('Center Black +86', true);
const centerYel26 = ctx.input('Center Yellow +26', true);
const centerYel42 = ctx.input('Center Yellow +42', true);
const centerYel58 = ctx.input('Center Yellow +58', true);
const centerYel94 = ctx.input('Center Yellow +94', true);
const showBelow = ctx.input('Show Below Base', true);
const showAbove = ctx.input('Show Above Base', true);
// ── Determine today's date (using the last bar) ──
const lastDate = new Date(bars[last].timestamp);
const lastDateStr = lastDate.toDateString();
// ── Find the daily close for the most recent complete day ──
let firstBarOfToday = 0;
for (let i = last; i >= 0; i--) {
const d = new Date(bars[i].timestamp);
if (d.toDateString() === lastDateStr) {
firstBarOfToday = i;
} else {
break;
}
}
// Daily close = close of the bar just before today's first bar
const prevDayClose = firstBarOfToday > 0 ? bars[firstBarOfToday - 1].close : bars[last].close;
// ── Compute base levels ──
const baseCenter = Math.round(prevDayClose / 100) * 100;
const baseBelow = baseCenter - 100;
const baseAbove = baseCenter + 100;
// ── Helper: draw a horizontal line across today's visible bars ──
function drawHline(price, color, lineWidth, labelText) {
ctx.line(firstBarOfToday, price, last, price, {
color: color,
lineWidth: lineWidth,
extend: 'right',
text: labelText || ''
});
}
// ── Helper: draw a dashed horizontal line (for blue 00) ──
function drawDashed(price, color, labelText) {
ctx.line(firstBarOfToday, price, last, price, {
color: color,
lineWidth: 1,
lineStyle: 'dashed',
extend: 'right',
text: labelText || ''
});
}
// ── Helper: draw cross markers (for yellow volatility levels) ──
function drawCross(price, color, labelText) {
ctx.line(firstBarOfToday, price, last, price, {
color: color,
lineWidth: 2,
lineStyle: 'dashed',
extend: 'right',
text: labelText || ''
});
}
// ── Plot all levels (only today's bars if showTodayOnly) ──
const startBar = showTodayOnly ? firstBarOfToday : 0;
// ========== CENTER BASE ==========
if (centerRed80) drawHline(baseCenter + 80, '#ff0000', 2, '+80');
if (centerGrn35) drawHline(baseCenter + 35, '#00ff00', 2, '+35');
if (centerPnk64) drawHline(baseCenter + 64, '#ff00ff', 1, '+64');
if (centerPnk6) drawHline(baseCenter + 6, '#ff00ff', 1, '+06');
if (centerBlu0) drawDashed(baseCenter, 'rgba(0,0,255,0.3)', '+00');
if (centerBlu10) drawHline(baseCenter + 10, '#0000ff', 1, '+10');
if (centerBlu20) drawHline(baseCenter + 20, '#0000ff', 1, '+20');
if (centerBlu50) drawHline(baseCenter + 50, '#0000ff', 1, '+50');
if (centerBlk47) drawHline(baseCenter + 47, '#000000', 1, '+47');
if (centerBlk72) drawHline(baseCenter + 72, '#000000', 1, '+72');
if (centerBlk86) drawHline(baseCenter + 86, '#000000', 1, '+86');
if (centerYel26) drawCross(baseCenter + 26, '#ffff00', '+26');
if (centerYel42) drawCross(baseCenter + 42, '#ffff00', '+42');
if (centerYel58) drawCross(baseCenter + 58, '#ffff00', '+58');
if (centerYel94) drawCross(baseCenter + 94, '#ffff00', '+94');
// ========== BASE BELOW ==========
if (showBelow) {
if (centerRed80) drawHline(baseBelow + 80, '#ff0000', 2, 'B-80');
if (centerGrn35) drawHline(baseBelow + 35, '#00ff00', 2, 'B-35');
if (centerPnk64) drawHline(baseBelow + 64, '#ff00ff', 1, 'B-64');
if (centerPnk6) drawHline(baseBelow + 6, '#ff00ff', 1, 'B-06');
if (centerBlu0) drawDashed(baseBelow, 'rgba(0,0,255,0.3)', 'B-00');
if (centerBlu10) drawHline(baseBelow + 10, '#0000ff', 1, 'B-10');
if (centerBlu20) drawHline(baseBelow + 20, '#0000ff', 1, 'B-20');
if (centerBlu50) drawHline(baseBelow + 50, '#0000ff', 1, 'B-50');
if (centerBlk47) drawHline(baseBelow + 47, '#000000', 1, 'B-47');
if (centerBlk72) drawHline(baseBelow + 72, '#000000', 1, 'B-72');
if (centerBlk86) drawHline(baseBelow + 86, '#000000', 1, 'B-86');
if (centerYel26) drawCross(baseBelow + 26, '#ffff00', 'B-26');
if (centerYel42) drawCross(baseBelow + 42, '#ffff00', 'B-42');
if (centerYel58) drawCross(baseBelow + 58, '#ffff00', 'B-58');
if (centerYel94) drawCross(baseBelow + 94, '#ffff00', 'B-94');
}
// ========== BASE ABOVE ==========
if (showAbove) {
if (centerRed80) drawHline(baseAbove + 80, '#ff0000', 2, 'A-80');
if (centerGrn35) drawHline(baseAbove + 35, '#00ff00', 2, 'A-35');
if (centerPnk64) drawHline(baseAbove + 64, '#ff00ff', 1, 'A-64');
if (centerPnk6) drawHline(baseAbove + 6, '#ff00ff', 1, 'A-06');
if (centerBlu0) drawDashed(baseAbove, 'rgba(0,0,255,0.3)', 'A-00');
if (centerBlu10) drawHline(baseAbove + 10, '#0000ff', 1, 'A-10');
if (centerBlu20) drawHline(baseAbove + 20, '#0000ff', 1, 'A-20');
if (centerBlu50) drawHline(baseAbove + 50, '#0000ff', 1, 'A-50');
if (centerBlk47) drawHline(baseAbove + 47, '#000000', 1, 'A-47');
if (centerBlk72) drawHline(baseAbove + 72, '#000000', 1, 'A-72');
if (centerBlk86) drawHline(baseAbove + 86, '#000000', 1, 'A-86');
if (centerYel26) drawCross(baseAbove + 26, '#ffff00', 'A-26');
if (centerYel42) drawCross(baseAbove + 42, '#ffff00', 'A-42');
if (centerYel58) drawCross(baseAbove + 58, '#ffff00', 'A-58');
if (centerYel94) drawCross(baseAbove + 94, '#ffff00', 'A-94');
}
}