Description
SURFING IN STYLE
Categories & Tags
Comments (0)
0/2000
Loading comments…
Source code
function calculate(bars, ctx) {
const isBars = ctx.input('Base color on prev close', false);
const barWidth = ctx.input('Line Thickness', 3, { min: 1, max: 10, step: 1 });
const bullColor = ctx.input('Bull Color', '#00be04');
const bearColor = ctx.input('Bear Color', '#ff0000');
const barColors = [];
for (let i = 0; i < bars.length; i++) {
const b = bars[i];
let color;
if (isBars) {
if (i === 0) { barColors.push(null); continue; }
color = b.close >= bars[i - 1].close ? bullColor : bearColor;
} else {
color = b.close >= b.open ? bullColor : bearColor;
}
barColors.push(color);
const bodyTop = Math.max(b.open, b.close);
const bodyBottom = Math.min(b.open, b.close);
// Upper wick only (above body)
if (b.high > bodyTop) {
ctx.line(i, b.high, i, bodyTop, { color, lineWidth: barWidth });
}
// Lower wick only (below body)
if (b.low < bodyBottom) {
ctx.line(i, bodyBottom, i, b.low, { color, lineWidth: barWidth });
}
}
// Recolor candle bodies to match so the body covers any overlapping line
ctx.barcolor(barColors);
}