Docs / Display & Visuals

Display & Visuals

The display block decides how each returned buffer is drawn: lines, histograms, arrows or dots, on the price chart or in their own windows, with fills, levels and a fixed or automatic scale. It works the same in indicators and strategies.


Block Keys

Function / PropertyDescription
separate_window: true;The whole output is drawn in one extra window below the chart (false / omitted = on the price chart).
outputs: NNumber of output buffers (no semicolon needed).
levels: [30, 70];Horizontal reference lines drawn by the chart in the indicator window. Negative values allowed: [-80, -20].
scale: fixed(0, 100);Fixed vertical range for the window; negative bounds allowed: fixed(-100, 0).
scale: auto;Fit the visible values (default).
scale: auto_zero;Fit the visible values and always include 0 (good for histograms). autoIncludeZero is the same.
fill { … };Shade between two buffers (see Fills).

Buffer Keys

Each buffer entry is Target { key: value; … };. Unknown keys are skipped.

Function / PropertyDescription
typeOne of the 12 display types (see Display Types). Case-insensitive, singular or plural, quoted or not (arrow, "arrows", Arrows). An unknown type is a compile error.
colorHex (#rrggbb / #rrggbbaa) or rgba(...) string.
color_downcolorline / colorhistogram: colour while falling / below zero (color = rising / above zero). bars: colour when close < open.
texttype "text": the text written at each bar that holds a value, e.g. text: "BUY";. The | character is not allowed.
nameLegend / data-window label (defaults to the field name).
widthLine or glyph width, e.g. 1, 2 or 0.5.
style"solid" | "dashed" | "dotted".
arrow_code (alias code)Symbol for type "arrow": a number 32..255 or Arrow.<Name> (233 = Arrow.Up, 234 = Arrow.Down, 171 = Arrow.Star …). Default 233. Out of range = compile error. Full list: Arrow Codes page.
visible: false;Compute and expose the buffer (for proxies / data window) without drawing it.
index: N;Explicit buffer index for this entry.
separate_window: true;This buffer alone moves to its own window; the others stay where they are. Each flagged buffer gets its own window.

Display Types

Function / PropertyDescription
lineA line through the values. style: solid / dashed / dotted.
histogramBars from zero to the value.
dotsA dot at each value (0.0 = none on the price chart).
arrow (arrows)A symbol at each value; arrow_code picks it (see Arrow Codes). 0.0 = no symbol.
textThe text: key written at each value. 0.0 = nothing.
zigzagA line joining only the bars that hold a value (0.0 bars are skipped): swing highs / lows.
stepA line that moves in steps: flat until the value changes, then a vertical jump.
areaA line with the area under it filled in its colour (use a see-through colour).
colorlineA line in color while rising and color_down while falling.
colorhistogramA histogram in color above zero and color_down below.
candlesCandles from 4 buffers in a row: open, high, low, close.
barsOHLC bars (stick + open / close ticks) from 4 buffers in a row; color_down when close < open.

Named objects at any time and price (levels, zones, trend lines, labels) are not buffers. See Drawing Objects.


Addressing Buffers

Function / PropertyDescription
buffer[n] { … }By position — the n-th returned buffer (tuple returns, or struct field order).
Struct.field { … }Indicators: the field of the returned struct, e.g. BandSignal.upper.
Proxy.field { … }Strategies: the field of a bound proxy, e.g. Bands.upper (Bands bound with Load / Native.Bind / Custom.Bind).

Buffer order is the order of the struct fields (or of the tuple); fill and buffer[n] use that order.


Empty Bars

Arrow buffers draw only at bars that hold a signal: write 0.0 on every other bar (0.0 = no arrow). Dot, text and zigzag buffers use the same convention. Lines skip bars that were never written (a fresh create_array is NaN), so a line starts where your loop starts.

Arrow buffer patternTDSL
t1_buy[i]  = 0.0;                                  // no arrow on this bar
t1_sell[i] = 0.0;
if (closes[i - 1] < t1_lower[i - 1] && closes[i] > t1_lower[i]) {
    t1_buy[i] = lows[i] - (arrow_gap * pt);         // place the arrow under the bar
}

Fills

fill shades the area between two buffers (by index). color is used everywhere, or add color_up (buffer_a above buffer_b) and color_down (below) for a two-colour cloud. Several fills are allowed.

fill { }TDSL
fill { buffer_a: 0; buffer_b: 1; color: "rgba(19, 75, 228, 0.25)"; };
fill { buffer_a: 1; buffer_b: 2; color: "rgba(0, 189, 31, 0.25)"; };
fill { buffer_a: 0; buffer_b: 1; color: "rgba(128,128,128,0.2)"; color_up: "rgba(34,197,94,0.25)"; color_down: "rgba(239,68,68,0.25)"; };
Note
A fill between two buffers that end up in different windows (because one has separate_window: true;) is dropped.

Panes

There are two levels of separate_window:

  • Block level — everything goes into one extra window with one scale. Use for a single oscillator; levels and scale apply to that window.
  • Buffer level — only that buffer gets its own window. Use to mix price overlays and an oscillator in one script (e.g. arrows on price + momentum histogram below).

A buffer moved to its own window keeps everything set in its block — type, color, width, style and arrow_code. Each window scales on its own values. The indicator still shows as one entry in the indicator list, and removing it removes its extra windows too. Both levels work in indicators and strategies.

Note
The window is decided by the script. If a user changes a split-off buffer's line style in the Style tab, that buffer returns to the main output.

Example: Arrow Signals

BreakoutArrows.tdsl — arrows on channel breakoutsTDSL
about {
    author: "CoreXTrader";
    version: "1.0.0";
    about: "Docs display: breakout arrows";
}

parameters {
    int    period     = 20;   // Channel Period
    double offset_pts = 50;   // Arrow distance (points)
}

struct Breakout {
    double up_arrow;
    double down_arrow;
}

display {
    outputs: 2
    Breakout.up_arrow   { type: "arrow"; color: "#16a34a"; name: "Breakout Up";   width: 1; arrow_code: 233; };
    Breakout.down_arrow { type: "arrow"; color: "#dc2626"; name: "Breakout Down"; width: 1; arrow_code: 234; };
}

series double da_up[];
series double da_dn[];

calculate() {
    double h[] = high();
    double l[] = low();
    double c[] = close();
    int len = length(c);
    da_up[] = create_array(len);
    da_dn[] = create_array(len);

    double pt = Symbol.Point();
    int start = Chart.resume_index;
    if (start > 0) { start = start - 1; } else { start = period; }   // reads h[i - period]

    for (int i = start; i < len; i = i + 1) {
        double hh = h[i - 1];
        double ll = l[i - 1];
        for (int j = 2; j <= period; j = j + 1) {
            if (h[i - j] > hh) { hh = h[i - j]; }
            if (l[i - j] < ll) { ll = l[i - j]; }
        }
        da_up[i] = 0.0;                                   // 0.0 = no arrow
        da_dn[i] = 0.0;
        if (c[i] > hh) { da_up[i] = l[i] - (offset_pts * pt); }   // below the bar
        if (c[i] < ll) { da_dn[i] = h[i] + (offset_pts * pt); }   // above the bar
    }
    return Breakout { up_arrow: da_up, down_arrow: da_dn };
}

Example: Histogram

CloseDelta.tdsl — close-to-close change as a histogramTDSL
about {
    author: "CoreXTrader";
    version: "1.0.0";
    about: "Docs display: histogram with auto_zero scale";
}

parameters {
    int smooth = 5;   // Smoothing
}

display {
    separate_window: true;
    scale: auto_zero;
    outputs: 2
    buffer[0] { type: "histogram"; color: "#64748b"; name: "Delta";     width: 2; };
    buffer[1] { type: "line";      color: "#f59e0b"; name: "Avg Delta"; width: 2; };
}

series double dh_delta[];
series double dh_avg[];

calculate() {
    double c[] = close();
    int len = length(c);
    dh_delta[] = create_array(len);
    dh_avg[]   = create_array(len);

    double sd = smooth;
    int start = Chart.resume_index;
    if (start > 0) { start = start - 1; } else { start = smooth; }   // reads c[i - smooth]

    for (int i = start; i < len; i = i + 1) {
        dh_delta[i] = c[i] - c[i - 1];
        double s = 0.0;
        for (int j = 0; j < smooth; j = j + 1) { s = s + (c[i - j] - c[i - j - 1]); }
        dh_avg[i] = s / sd;
    }
    return [dh_delta, dh_avg];
}

Example: Dotted Levels

PrevBarLevels.tdsl — previous-bar high / low as dotted linesTDSL
about {
    author: "CoreXTrader";
    version: "1.0.0";
    about: "Docs display: dotted previous high / low";
}

display {
    outputs: 2
    buffer[0] { type: "line"; color: "#22c55e"; name: "Prev High"; width: 1; style: "dotted"; };
    buffer[1] { type: "line"; color: "#ef4444"; name: "Prev Low";  width: 1; style: "dotted"; };
}

series double dl_ph[];
series double dl_pl[];

calculate() {
    double h[] = high();
    double l[] = low();
    int len = length(h);
    dl_ph[] = create_array(len);
    dl_pl[] = create_array(len);

    int start = Chart.resume_index;
    if (start > 0) { start = start - 1; } else { start = 1; }

    for (int i = start; i < len; i = i + 1) {
        dl_ph[i] = h[i - 1];
        dl_pl[i] = l[i - 1];
    }
    return [dl_ph, dl_pl];
}

Example: Two-Colour Cloud

MACloud.tdsl — fast/slow SMA cloud with color_up / color_downTDSL
about {
    author: "CoreXTrader";
    version: "1.0.0";
    about: "Docs display: two-colour cloud";
}

parameters {
    int fast = 10;   // Fast Period
    int slow = 30;   // Slow Period
}

struct Cloud {
    double fast_ma;
    double slow_ma;
}

display {
    outputs: 2
    Cloud.fast_ma { type: "line"; color: "#16a34a"; name: "Fast"; width: 1; };
    Cloud.slow_ma { type: "line"; color: "#dc2626"; name: "Slow"; width: 1; };
    fill { buffer_a: 0; buffer_b: 1; color: "rgba(128,128,128,0.2)"; color_up: "rgba(22,163,74,0.20)"; color_down: "rgba(220,38,38,0.20)"; };
}

series double dc_f[];
series double dc_s[];

calculate() {
    double c[] = close();
    int len = length(c);
    dc_f[] = create_array(len);
    dc_s[] = create_array(len);

    double fd = fast;
    double sd = slow;
    int start = Chart.resume_index;
    if (start > 0) { start = start - 1; } else { start = slow - 1; }

    for (int i = start; i < len; i = i + 1) {
        double sf = 0.0;
        double ss = 0.0;
        for (int j = 0; j < fast; j = j + 1) { sf = sf + c[i - j]; }
        for (int j = 0; j < slow; j = j + 1) { ss = ss + c[i - j]; }
        dc_f[i] = sf / fd;
        dc_s[i] = ss / sd;
    }
    return Cloud { fast_ma: dc_f, slow_ma: dc_s };
}

Example: Oscillator with Fixed Scale and Levels

Williams %R lives between −100 and 0, so the window is fixed to that range and the chart draws levels at −80 and −20. The signal line is dotted.

WilliamsR.tdsl — fixed(-100, 0), levels [-80, -20]TDSL
about {
    author: "CoreXTrader";
    version: "1.0.0";
    about: "Docs display: Williams %R, fixed negative scale";
}

parameters {
    int period = 14;   // %R Period
    int signal_len = 3;   // Signal Length
}

struct WPR {
    double value;
    double sig;
}

display {
    separate_window: true;
    scale: fixed(-100, 0);
    levels: [-80, -20];
    outputs: 2
    WPR.value { type: "line"; color: "#8b5cf6"; name: "%R";     width: 2; };
    WPR.sig   { type: "line"; color: "#f59e0b"; name: "Signal"; width: 1; style: "dotted"; };
}

series double dw_r[];
series double dw_s[];

calculate() {
    double h[] = high();
    double l[] = low();
    double c[] = close();
    int len = length(c);
    dw_r[] = create_array(len);
    dw_s[] = create_array(len);

    double sl = signal_len;
    int first_sig = period - 1 + signal_len - 1;

    int start = Chart.resume_index;
    if (start > 0) { start = start - 1; } else { start = period - 1; }

    for (int i = start; i < len; i = i + 1) {
        double hh = h[i];
        double ll = l[i];
        for (int j = 1; j < period; j = j + 1) {
            if (h[i - j] > hh) { hh = h[i - j]; }
            if (l[i - j] < ll) { ll = l[i - j]; }
        }
        // (c - hh) is <= 0, so %R runs from -100 (at the low) to 0 (at the high)
        dw_r[i] = hh - ll > 0.0 ? 100.0 * (c[i] - hh) / (hh - ll) : -50.0;

        dw_s[i] = dw_r[i];
        if (i >= first_sig) {
            double s = 0.0;
            for (int j = 0; j < signal_len; j = j + 1) { s = s + dw_r[i - j]; }
            dw_s[i] = s / sl;
        }
    }
    return WPR { value: dw_r, sig: dw_s };
}

Example: Per-Buffer Panes in One Strategy

Bollinger Bands stay on the price chart; the RSI line and the MACD histogram each carry separate_window: true; and get their own window. Native engines can only be bound in strategies, so this is a strategy that never trades. For an indicator file with a per-buffer window, see the arrow examples on Indicators.

BandsRSIMACD.tdsl — overlay + two separate windowsTDSL
about {
    author: "CoreXTrader";
    version: "1.0.0";
    about: "Docs display: per-buffer panes in a strategy";
}

parameters {
    int    bb_period   = 20;    // Bands Period
    double bb_dev      = 2.0;   // Bands Deviation
    int    rsi_period  = 14;    // RSI Period
    int    macd_fast   = 12;    // MACD Fast
    int    macd_slow   = 26;    // MACD Slow
    int    macd_signal = 9;     // MACD Signal
}

struct BandsData  { double upper; double middle; double lower; }
struct OscData    { double value; }
struct MACDData   { double line; double signal; double histogram; }

display {
    outputs: 5
    Bands.upper     { type: "line";      color: "#dc2626"; name: "Upper";     width: 1; };
    Bands.middle    { type: "line";      color: "#94a3b8"; name: "Middle";    width: 1; style: "dashed"; };
    Bands.lower     { type: "line";      color: "#16a34a"; name: "Lower";     width: 1; };
    Osc.value       { type: "line";      color: "#3b82f6"; name: "RSI";       width: 2; separate_window: true; };
    Macd.histogram  { type: "histogram"; color: "#9ca3af"; name: "MACD Hist"; width: 2; separate_window: true; };
    fill { buffer_a: 0; buffer_b: 2; color: "rgba(59,130,246,0.08)"; };
}

Init() {
    Native.Source(i.Bollinger);
    Native.Init(Symbol(), Timeframe);
    Native.Parameter(bb_period, bb_dev, Price.Close);
    Native.Bind(Bands);

    Native.Source(i.RSI);
    Native.Init(Symbol(), Timeframe);
    Native.Parameter(rsi_period, Price.Close);
    Native.Bind(Osc);

    Native.Source(i.MACD);
    Native.Init(Symbol(), Timeframe);
    Native.Parameter(macd_fast, macd_slow, macd_signal, Price.Close);
    Native.Bind(Macd);
}

Bands.calculate() {
    int len = candle_count();
    series double dp_bb_mid[]; series double dp_bb_up[]; series double dp_bb_lo[];
    dp_bb_mid[] = create_array(len); dp_bb_up[] = create_array(len); dp_bb_lo[] = create_array(len);
    Native.Fetch(0, dp_bb_mid);
    Native.Fetch(1, dp_bb_up);
    Native.Fetch(2, dp_bb_lo);
    return BandsData { upper: dp_bb_up, middle: dp_bb_mid, lower: dp_bb_lo };
}

Osc.calculate() {
    int len = candle_count();
    series double dp_rsi[];
    dp_rsi[] = create_array(len);
    Native.Fetch(0, dp_rsi);
    return OscData { value: dp_rsi };
}

Macd.calculate() {
    int len = candle_count();
    series double dp_m_line[]; series double dp_m_sig[]; series double dp_m_hist[];
    dp_m_line[] = create_array(len); dp_m_sig[] = create_array(len); dp_m_hist[] = create_array(len);
    Native.Fetch(0, dp_m_line);
    Native.Fetch(1, dp_m_sig);
    Native.Fetch(2, dp_m_hist);
    return MACDData { line: dp_m_line, signal: dp_m_sig, histogram: dp_m_hist };
}

Tick() {
    if (!Time.IsNewBar()) { return; }
    Print("[PANES] up=" + ToString(Bands.upper(0)) + " rsi=" + ToString(Osc.value(0))
        + " hist=" + ToString(Macd.histogram(0)));
}

Example: All New Types

On the price chart: Heikin-Ashi bars, a zigzag through swing highs / lows with a live last leg, a step range high, a slow MA as an area, a fast MA as a colorline (green rising / red falling) and an "H" text over each swing high. In its own window: momentum as a colorhistogram.

DisplayTypes.tdsl — bars, zigzag, step, area, colorline, text, colorhistogramTDSL
about {
    author: "CoreXTrader";
    version: "1.0.0";
    about: "Docs display: the new display types";
}

struct Shapes {
    double ha_open;
    double ha_high;
    double ha_low;
    double ha_close;
    double swings;
    double range_high;
    double slow_ma;
    double fast_ma;
    double swing_label;
    double momentum;
}

display {
    outputs: 10
    Shapes.ha_open     { type: "bars"; color: "#64748b"; name: "HA Open"; };
    Shapes.ha_high     { type: "bars"; color: "#64748b"; name: "HA High"; };
    Shapes.ha_low      { type: "bars"; color: "#64748b"; name: "HA Low"; };
    Shapes.ha_close    { type: "bars"; color: "#64748b"; name: "HA Close"; };
    Shapes.swings      { type: zigzag;  color: "#f59e0b"; name: "Swings"; width: 2; };
    Shapes.range_high  { type: "step";  color: "#9333ea"; name: "Range High"; style: dashed; };
    Shapes.slow_ma     { type: "area";  color: "rgba(37,99,235,0.25)"; name: "Slow MA"; };
    Shapes.fast_ma     { type: "colorline"; color: "#16a34a"; color_down: "#dc2626"; name: "Fast MA"; width: 2; };
    Shapes.swing_label { type: "text";  color: "#f59e0b"; name: "Swing High"; text: "H"; };
    Shapes.momentum    { type: "colorhistogram"; color: "#16a34a"; color_down: "rgba(220,38,38,0.8)"; name: "Momentum"; separate_window: true; };
}

parameters {
    int fast  = 10;    // Fast MA
    int slow  = 30;    // Slow MA
    int range = 20;    // Range High bars
    int depth = 5;     // Swing depth (bars each side)
    int mom   = 10;    // Momentum period
}

series double t8_ho[];
series double t8_hh[];
series double t8_hl[];
series double t8_hc[];
series double t8_swing[];
series double t8_range[];
series double t8_slow[];
series double t8_fast[];
series double t8_label[];
series double t8_mom[];

calculate() {
    double opens[]  = open();
    double highs[]  = high();
    double lows[]   = low();
    double closes[] = close();
    int len = length(closes);

    t8_ho[]    = create_array(len);
    t8_hh[]    = create_array(len);
    t8_hl[]    = create_array(len);
    t8_hc[]    = create_array(len);
    t8_swing[] = create_array(len);
    t8_range[] = create_array(len);
    t8_slow[]  = create_array(len);
    t8_fast[]  = create_array(len);
    t8_label[] = create_array(len);
    t8_mom[]   = create_array(len);

    // A swing is only known `depth` bars later: recompute that far back on updates
    int start = Chart.resume_index - (2 * depth);
    if (start < slow) {
        start = slow;
    }

    for (int i = start; i < len; i = i + 1) {
        // Heikin-Ashi
        double hc = (opens[i] + highs[i] + lows[i] + closes[i]) / 4.0;
        double ho = (t8_ho[i - 1] + t8_hc[i - 1]) / 2.0;
        if (t8_ho[i - 1] == 0.0) {
            ho = (opens[i] + closes[i]) / 2.0;
        }
        t8_ho[i] = ho;
        t8_hc[i] = hc;
        t8_hh[i] = highs[i];
        if (ho > t8_hh[i]) { t8_hh[i] = ho; }
        if (hc > t8_hh[i]) { t8_hh[i] = hc; }
        t8_hl[i] = lows[i];
        if (ho < t8_hl[i]) { t8_hl[i] = ho; }
        if (hc < t8_hl[i]) { t8_hl[i] = hc; }

        // Moving averages
        double sf = 0.0;
        for (int j = 0; j < fast; j = j + 1) { sf = sf + closes[i - j]; }
        t8_fast[i] = sf / fast;
        double ss = 0.0;
        for (int j = 0; j < slow; j = j + 1) { ss = ss + closes[i - j]; }
        t8_slow[i] = ss / slow;

        // Range high (step)
        double hi = highs[i];
        for (int j = 1; j < range; j = j + 1) {
            if (highs[i - j] > hi) { hi = highs[i - j]; }
        }
        t8_range[i] = hi;

        // Momentum
        t8_mom[i] = closes[i] - closes[i - mom];
    }

    // Zigzag: depends on the whole history (a new extreme moves the last point), so it is
    // recomputed from the start every call. 0 = no point on that bar.
    for (int i = 0; i < len; i = i + 1) {
        t8_swing[i] = 0.0;
        t8_label[i] = 0.0;
    }
    int lastType = 0;        // 0 none, 1 last point is a high, -1 a low
    int lastIdx = -1;
    double lastVal = 0.0;
    for (int p = depth; p < len - depth; p = p + 1) {
        // Swing high / low: beats `depth` bars on each side
        bool isHigh = true;
        bool isLow  = true;
        for (int j = 1; j <= depth; j = j + 1) {
            if (highs[p - j] >= highs[p] || highs[p + j] > highs[p]) { isHigh = false; }
            if (lows[p - j]  <= lows[p]  || lows[p + j]  < lows[p])  { isLow  = false; }
        }
        // Both on one bar (long wicks): take the one that continues the alternation
        if (isHigh && isLow) {
            if (lastType == 1) { isHigh = false; } else { isLow = false; }
        }

        if (isHigh) {
            if (lastType == 1) {
                // Two highs in a row: keep only the higher one
                if (highs[p] > lastVal) {
                    t8_swing[lastIdx] = 0.0;
                    t8_label[lastIdx] = 0.0;
                    lastIdx = p;
                    lastVal = highs[p];
                    t8_swing[p] = highs[p];
                    t8_label[p] = highs[p] + (30.0 * Symbol.Point());
                }
            } else {
                lastType = 1;
                lastIdx = p;
                lastVal = highs[p];
                t8_swing[p] = highs[p];
                t8_label[p] = highs[p] + (30.0 * Symbol.Point());
            }
        }
        if (isLow) {
            if (lastType == -1) {
                // Two lows in a row: keep only the lower one
                if (lows[p] < lastVal) {
                    t8_swing[lastIdx] = 0.0;
                    lastIdx = p;
                    lastVal = lows[p];
                    t8_swing[p] = lows[p];
                }
            } else {
                lastType = -1;
                lastIdx = p;
                lastVal = lows[p];
                t8_swing[p] = lows[p];
            }
        }
    }

    // Live last leg: from the last confirmed point to the most extreme bar since then
    if (lastIdx >= 0) {
        int tipIdx = -1;
        double tipVal = 0.0;
        for (int i = lastIdx + 1; i < len; i = i + 1) {
            if (lastType == -1 && (tipIdx < 0 || highs[i] > tipVal)) { tipIdx = i; tipVal = highs[i]; }
            if (lastType == 1  && (tipIdx < 0 || lows[i]  < tipVal)) { tipIdx = i; tipVal = lows[i]; }
        }
        if (tipIdx >= 0) {
            t8_swing[tipIdx] = tipVal;
            if (lastType == -1) {
                t8_label[tipIdx] = tipVal + (30.0 * Symbol.Point());
            }
        }
    }

    return Shapes {
        ha_open: t8_ho, ha_high: t8_hh, ha_low: t8_hl, ha_close: t8_hc,
        swings: t8_swing, range_high: t8_range,
        slow_ma: t8_slow, fast_ma: t8_fast,
        swing_label: t8_label, momentum: t8_mom
    };
}
Tip
A zigzag or a fractal can change bars further back than the last one. The chart picks that up live: it redraws from the first bar that changed, so a swing confirmed later appears on its older bar without reloading.

Example: Strategy with ZigZag, Fractals and a Colour MA

A strategy that never trades and draws three native engines: ZigZag (yellow), Fractals (green ↑ over swing highs, red ↓ under swing lows, 2 bars each side) and an MA 20 as a colorline.

DrawingNatives.tdsl — native ZigZag / Fractals / colorline MATDSL
about {
    author: "CoreXTrader";
    version: "1.0.0";
    about: "Docs display: native ZigZag / Fractals / colorline MA drawn by a strategy";
}

parameters {
    double zz_dev   = 0.3;   // ZigZag Deviation %
    int    zz_depth = 12;    // ZigZag Depth
    int    fr_side  = 2;     // Fractal bars each side
    int    ma_period = 20;   // MA Period
}

struct ZZResult { double value; }
struct FRResult { double up; double down; }
struct MAResult { double value; }

display {
    outputs: 4
    NativeZZ.value { type: "line";      color: "#f1c40f"; name: "ZigZag";       width: 2; };
    NativeFR.up    { type: "arrow";     color: "#16a34a"; name: "Fractal Up";   arrow_code: Arrow.Up; };
    NativeFR.down  { type: "arrow";     color: "#dc2626"; name: "Fractal Down"; arrow_code: Arrow.Down; };
    NativeMA.value { type: "colorline"; color: "#16a34a"; color_down: "#dc2626"; name: "MA"; width: 2; };
}

Init() {
    Native.Source(i.ZigZag);
    Native.Init(Symbol(), Timeframe);
    Native.Parameter(zz_dev, zz_depth, 3);
    Native.Bind(NativeZZ);

    Native.Source(i.Fractals);
    Native.Init(Symbol(), Timeframe);
    Native.Parameter(fr_side);
    Native.Bind(NativeFR);

    Native.Source(i.MA);
    Native.Init(Symbol(), Timeframe);
    Native.Parameter(ma_period, MA.SMA, Price.Close);
    Native.Bind(NativeMA);
}

NativeZZ.calculate() {
    int len = candle_count();
    series double s11_zz[];
    s11_zz[] = create_array(len);
    Native.Fetch(0, s11_zz);
    return ZZResult { value: s11_zz };
}

NativeFR.calculate() {
    int len = candle_count();
    series double s11_up[]; series double s11_dn[];
    s11_up[] = create_array(len); s11_dn[] = create_array(len);
    Native.Fetch(0, s11_up);
    Native.Fetch(1, s11_dn);
    return FRResult { up: s11_up, down: s11_dn };
}

NativeMA.calculate() {
    int len = candle_count();
    series double s11_ma[];
    s11_ma[] = create_array(len);
    Native.Fetch(0, s11_ma);
    return MAResult { value: s11_ma };
}

Tick() {
    if (!Time.IsNewBar()) { return; }
    Print("[BAR] zz=" + ToString(NativeZZ.value(1)) + " up=" + ToString(NativeFR.up(1))
        + " down=" + ToString(NativeFR.down(1)) + " ma=" + ToString(NativeMA.value(1)));
}