Fibonacci Archer Box
Updated
March 11, 2024
TradingView

For free use on the TradingView platform

Fibonacci Archer Box (ChartPrime) is a full featured Fibonacci box indicator that automatically plots based on pivot points. This indicator plots retracement levels, time lines, fan lines, and angles. Each one of these features are fully customizable with the ability to disable individual features. A unique aspect to this implementation is the ability to set targets based on retracement levels and time zones. This is set to 0.618 by default but you can pick any Fibonacci zone you like. Also included are markings that show you when Fibonacci levels are met or exceeded. These moments are plotted on the chart as colored dots that can be enabled or disabled. Along with these markings are crosses that can be shown when targets are hit. Both of these markings are colored with the related Fibonacci level colors.

When there is a zig-zag, this indicator will test to see if the zig-zag meets the criteria set up by the user before plotting a new Fibonacci box. You can pick from either higher highs or lower highs for bearish patterns, and higher lows or lower lows for bullish patterns. Both patterns can be set to use both when finding new boxes if you want to make it more sensitive. You also have the option to filter based on minimum and maximum size. If the box isn't within the selected size range, it will simply be ignored. The pivot levels can be configured to use either candle wicks or candle bodies. By default this is configured to use candle wick with a lookforward of 5 and lookback of 10.

We have included alerts for Fibonacci level crosses, Fibonacci time crosses, and target hits. All alerts are found in the add alert section built into tradingview to make alert creation as easy as possible. Each alert is labeled with their correct names to make navigation simple.

W.D. Gann, a renowned figure in the world of trading and market analysis, is often questioned for his use of Fibonacci levels in his strategies. However, evidence points to the fact that Gann did not directly employ Fibonacci price levels in his work. Instead, Gann had his unique approach, dividing price ranges into thirds, eighths, and other fractions, which, although somewhat aligning with Fibonacci levels, are not exact matches. It is clear that Gann was familiar with Fibonacci and the golden ratio, as references to them appear in his recommended reading list and some of his writings. Despite this awareness, Gann chose not to incorporate Fibonacci levels explicitly in his methodologies, preferring instead to use his divisions of price and time. Notably, Gann's emphasis on the 50% level—a marker not associated with Fibonacci numbers—further illustrates his departure from Fibonacci usage. This level, despite its popularity among some Fibonacci enthusiasts, does not stem from Fibonacci's sequence. This is why we opted to call this indicator Fibonacci Archer Box instead of a Gann Box as we didn't feel like it was appropriate.

In summary, the Fibonacci Archer Box (ChartPrime) is a tool that incorporates Fibonacci retracements and projections with an automated pivot point-based plotting system. It allows for customization across various features including retracement levels, timelines, fan lines, and angles, and integrates visual cues for level crosses and target hits. While it acknowledges the methodologies of W.D. Gann, it distinctively utilizes Fibonacci techniques, providing a straightforward tool for market analysis. We hope you enjoy using this indicator as much as we enjoyed making it!

Enjoy


// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ChartPrime

//@version=5
indicator("Fibonacci Archer Box [ChartPrime]", overlay = true, max_lines_count = 500, max_labels_count = 500, max_polylines_count = 100, max_bars_back = 5000)

type pivot
    float current = na
    int current_idx = na
    float previous = na
    int previous_idx = na

type fib_box
    line[] body_x
    line[] body_y
    line[] fan_upper
    line[] fan_lower
    line[] target
    polyline[] angles
    label[] labels

type box_settings
    bool levels
    bool[] enabled_levels
    bool times
    bool[] enabled_time
    bool fan
    bool[] enabled_fan
    bool extend_fan
    bool angles
    bool[] enabled_angle
    color[] colors
    float fill_alpha
    bool enable_level_fill
    bool enable_time_fill
    bool enable_fan_fill
    bool enable_angle_fill
    bool enable_labels
    bool[] enable_target
    int[] x_target_value
    int[] y_target_value
    bool enable_target_fill
    float target_fill_alpha

target_switch(string target)=>
    switch target
        "0.236" => 1
        "0.382" => 2
        "0.5" => 3
        "0.618" => 4
        "0.786" => 5
        "1" => 6

fib(float n)=>
    (math.pow(math.phi, n) - math.pow(-math.phi, -1)) / math.sqrt(5)

fib_level(int n) =>
    cycle_offset = 5 - n % 6
    fib_offset = cycle_offset < 1 ? 0 : cycle_offset == 1 ? 0.5 : cycle_offset > 3 ? cycle_offset - 2 : cycle_offset - 1 
    complete_cycles = math.max(0, math.floor(n/6))
    complete_cycles + math.round(cycle_offset == 3 ? 0.5 : (n > -1 ? fib(40 + fib_offset) / fib(40 + fib_offset + fib_offset) : 0), 3)

create_box_locations(float price_range, int idx_range)=>
    int[] x = array.new()
    float[] y = array.new()
    for i = -1 to 5
        float fib = fib_level(i)
        x.push(int(idx_range * fib))
        y.push(price_range * fib)

    [x, y]

method dump(line[] self)=>
    if self.size() > 0
        for i = self.size() - 1 to 0
            self.get(i).delete()
            self.remove(i)

method dump(polyline[] self)=>
    if self.size() > 0
        for i = self.size() - 1 to 0
            self.get(i).delete()
            self.remove(i)

method dump(label[] self)=>
    if self.size() > 0
        for i = self.size() - 1 to 0
            self.get(i).delete()
            self.remove(i)

method dump(fib_box[] self, int history)=>
    if self.size() > (history - 1)
        fib_box get = self.first()
        get.body_x.dump()
        get.body_y.dump()
        get.fan_upper.dump()
        get.fan_lower.dump()
        get.target.dump()
        get.angles.dump()
        get.labels.dump()
        self.remove(0)

generate_ellipse(int start_x, int end_x, float start_y, float end_y, bool order)=>
    chart.point[] points = array.new()
    float w = (end_x - start_x)
    float h = (end_y - start_y)

    int x = na

    int start = order ? 0 : 90
    int end = order ? 90 : 0

    for i = 0 to 90
        int new_x = int(w * math.cos(math.toradians(i)))
        float y = h * math.sin(math.toradians(i))
        if x != new_x
            points.push(chart.point.new(na, start_x + x, start_y + y))
        x := new_x

    if order
        points.unshift(chart.point.new(na, end_x, start_y))
        points.push(chart.point.new(na, start_x, end_y))
    else
        points.reverse()
        points.unshift(chart.point.new(na, start_x, end_y))
        points.push(chart.point.new(na, end_x, start_y))
    points

target_box(chart.point[] angle, int[] x, float[] y, int start_x, float start_y, int p, int x_target, int y_target)=>
    chart.point[] target_box = array.new()
    for i = 0 to angle.size() - 1
        chart.point angle_point = angle.get(i)
        int angle_idx = angle_point.index
        if angle_idx >= (start_x + x.get(x_target - 1)) and angle_idx <= (start_x + x.get(x_target))
            target_box.push(angle_point)
    target_box.push(chart.point.new(na, start_x + x.get(x_target - 1), start_y + y.get(y_target) * p))
    target_box.push(chart.point.new(na, start_x + x.get(x_target), start_y + y.get(y_target) * p))
    target_box.push(chart.point.new(na, start_x + x.get(x_target), start_y + y.get(y_target - 1) * p))
    target_box

f_sort(int[] x, int[] y, bool[] enable)=>
    int[] temp = array.new()
    int[] new_x = array.new()
    int[] new_y = array.new()
    bool[] new_enable = array.new()
    for i = 0 to 2
        int score = y.get(i) + math.max(0, x.get(i) - y.get(i))
        if i == 0
            temp.push(score)
            new_x.push(x.get(i))
            new_y.push(y.get(i))
            new_enable.push(enable.get(i))
        else if i == 1
            if score > temp.max()
                new_x.push(x.get(i))
                new_y.push(y.get(i))
                new_enable.push(enable.get(i))
            else
                new_x.unshift(x.get(i))
                new_y.unshift(y.get(i))
                new_enable.unshift(enable.get(i))
        else
            if score > temp.max()
                new_x.push(x.get(i))
                new_y.push(y.get(i))
                new_enable.push(enable.get(i))
            else if score < temp.min()
                new_x.unshift(x.get(i))
                new_y.unshift(y.get(i))
                new_enable.unshift(enable.get(i))
            else
                new_x.insert(1, x.get(i))
                new_y.insert(1, y.get(i))
                new_enable.insert(1, enable.get(i))
    [new_x, new_y, new_enable]

create_fib_box(float bottom, float top, int start_idx, float price_range, int idx_range, bool polarity, box_settings s)=>
    color na_color = color.new(color.black, 100)
    line[] body_x = array.new()
    line[] body_y = array.new()
    line[] fan_upper = array.new()
    line[] fan_lower = array.new()
    line[] target = array.new()
    polyline[] angles = array.new()
    label[] labels = array.new

Get access to our Exclusive
premium indicators