Bionic -- ORB + Midline

BionicNerd · study · 390 行 · 点赞 37 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=6
indicator("Bionic -- ORB + Midline", shorttitle="Bionic -- ORB + Midline", overlay=true, max_lines_count=500, max_labels_count=500)
 
///*///*///*///*///*///*///*///*/////
//        Ranges Configurations.   //
///*///*///*///*///*///*///*///*/////
 
// Toggle for enabling or disabling Ranges
enableRange1 = input.bool(true, "Enable Range 1 (NY Pre-Market)", group="Range 1 Inputs")
enableRange2 = input.bool(true, "Enable Range 2 (NY Open)", group="Range 2 Inputs" )
enableRange3 = input.bool(false, "Enable Range 3 (Tokyo Open)", group="Range 3 Inputs" )
enableRange4 = input.bool(false, "Enable Range 4 (London Open)", group="Range 4 Inputs" )
 
 
 
// Range 1 //
// Range 1 User inputs for time range and line extension
range1Session = input.session("0750-0810", title="Select Time for Range 1", group="Range 1 Inputs")
extendBars = input.int(33, "Range 1 Extend Lines Number of Bars", minval=0, group="Range 1 Inputs")
 
// Range 1 User inputs for line style
lineColorHigh = input.color(color.green, "Range 1 High Line Color", group="Range 1 Inputs" )
lineColorLow = input.color(color.red, "Range 1 Low Line Color", group="Range 1 Inputs")
lineWidth = input.int(4, "Line Width Range 1", minval=1, maxval=5, group="Range 1 Inputs")
 
 
// Range 2 //
// Range 2 User inputs for time range and line extension
range2Session = input.session("0830-0845", title="Select Time for Range 2", group="Range 2 Inputs")
extendBars1 = input.int(33, "Range 2 Extend Lines Number of Bars", minval=0, group="Range 2 Inputs")
 
// Range 2 User inputs for line style
lineColorHigh1 = input.color(color.purple, "Range 2 High Line Color", group="Range 2 Inputs")
lineColorLow1= input.color(color.black, "Range 2 Low Line Color", group="Range 2 Inputs" )
lineWidth1 = input.int(4, "Line Width Range 2", minval=1, maxval=5, group="Range 2 Inputs" )
 
 
// Range 3 //
// Range 3 User inputs for time range and line extension
range3Session = input.session("1850-1910", title="Select Time for Range 3", group="Range 3 Inputs")
extendBars3 = input.int(33, "Range 3 Extend Lines Number of Bars", minval=0, group="Range 3 Inputs")
 
// Range 3 User inputs for line style
lineColorHigh3 = input.color(color.green, "Range 3 High Line Color", group="Range 3 Inputs")
lineColorLow3= input.color(color.red, "Range 3 Low Line Color", group="Range 3 Inputs" )
lineWidth3 = input.int(4, "Line Width Range 3", minval=1, maxval=5, group="Range 3 Inputs" )
 
 
// Range 4 //
// Range 4 User inputs for time range and line extension
range4Session = input.session("0250-0310", title="Select Time for Range 4", group="Range 4 Inputs")
extendBars4 = input.int(44, "Range 4 Extend Lines Number of Bars", minval=0, group="Range 4 Inputs")
 
// Range 4 User inputs for line style
lineColorHigh4 = input.color(color.green, "Range 4 High Line Color", group="Range 4 Inputs")
lineColorLow4= input.color(color.red, "Range 4 Low Line Color", group="Range 4 Inputs" )
lineWidth4 = input.int(4, "Line Width Range 4", minval=1, maxval=5, group="Range 4 Inputs" )
 
 
///*///*///*///*///*///*///*///*///*///*///*///
//   Fibonacci Levels Configuration          //
//   (applies to all 4 ranges)               //
///*///*///*///*///*///*///*///*///*///*///*///
 
// Master toggle: turns all three fib lines (and their shading) on/off as a group
showFibLevels = input.bool(true, "Show Fibonacci Levels (0.382 / 0.5 / 0.618)", group="Fibonacci Levels")
 
// 0.382 line configuration
fib382Color = input.color(color.black, "0.382 Line Color", group="Fibonacci Levels")
fib382Width = input.int(2, "0.382 Line Width", minval=1, maxval=5, group="Fibonacci Levels")
fib382Style = input.string("Dotted", "0.382 Line Style", options=["Solid", "Dashed", "Dotted"], group="Fibonacci Levels")
 
// 0.5 line configuration
fib50Color = input.color(color.black, "0.5 Line Color", group="Fibonacci Levels")
fib50Width = input.int(1, "0.5 Line Width", minval=1, maxval=5, group="Fibonacci Levels")
fib50Style = input.string("Dashed", "0.5 Line Style", options=["Solid", "Dashed", "Dotted"], group="Fibonacci Levels")
 
// 0.618 line configuration
fib618Color = input.color(color.black, "0.618 Line Color", group="Fibonacci Levels")
fib618Width = input.int(2, "0.618 Line Width", minval=1, maxval=5, group="Fibonacci Levels")
fib618Style = input.string("Dotted", "0.618 Line Style", options=["Solid", "Dashed", "Dotted"], group="Fibonacci Levels")
 
// Shading configuration -- only between the three fib lines
showFibShading = input.bool(true, "Shade Areas Between Fib Lines", group="Fibonacci Shading")
fibShadeTransp = input.int(60, "Shading Transparency", minval=0, maxval=100, group="Fibonacci Shading", tooltip="0 = fully opaque, 100 = invisible")
shadeColor38250 = input.color(color.blue, "0.382 to 0.5 Shade Color", group="Fibonacci Shading")
shadeColor50618 = input.color(color.blue, "0.5 to 0.618 Shade Color", group="Fibonacci Shading")
 
// Maps the style dropdown text to a Pine line style constant
fibLineStyle(string s) =>
    s == "Solid" ? line.style_solid : s == "Dashed" ? line.style_dashed : line.style_dotted
 
// Draws the three fib lines for a completed range and shades the two bands
// between them (0.382-0.5 and 0.5-0.618). Called once per range at the same
// moment the high/low lines are drawn, so the fib lines share the exact same
// x-extent as their parent range.
f_drawFibLevels(int x1, int x2, float hi, float lo) =>
    if showFibLevels
        rng = hi - lo
        y382 = lo + rng * 0.382
        y50 = lo + rng * 0.500
        y618 = lo + rng * 0.618
        l382 = line.new(x1=x1, y1=y382, x2=x2, y2=y382, color=fib382Color, width=fib382Width, style=fibLineStyle(fib382Style))
        l50 = line.new(x1=x1, y1=y50, x2=x2, y2=y50, color=fib50Color, width=fib50Width, style=fibLineStyle(fib50Style))
        l618 = line.new(x1=x1, y1=y618, x2=x2, y2=y618, color=fib618Color, width=fib618Width, style=fibLineStyle(fib618Style))
        if showFibShading
            linefill.new(l382, l50, color.new(shadeColor38250, fibShadeTransp))
            linefill.new(l50, l618, color.new(shadeColor50618, fibShadeTransp))
 
 
//^^///^^//^^//^^///^^//^^//^^///^^//^^//^^///^^//^^//^^///^^//^^//
//^^                        LOGIC                              ^^//
//^^///^^//^^//^^///^^//^^//^^///^^//^^//^^///^^//^^//^^///^^//^^//
 
 
///*///*///*///*///*///*///*///*///*///
///           Ranges Logic          ///
///*///*///*///*///*///*///*///*///*///
 
///////////////////
// Range 1 Start //
///////////////////
 
// Tracking high and low
var float highInRange = na
var float lowInRange = na
var line highLine = na
var line lowLine = na
var int rangeStartBarIndex = na
var int rangeEndBarIndex = na
var bool shouldExtend = false
var bool buySignalGiven = false
var bool sellSignalGiven = false
 
var bool buySignal = false
var bool sellSignal = false
 
if enableRange1
    if not na(time(timeframe.period, range1Session))
        if na(highInRange)
            highInRange := high
            lowInRange := low
            rangeStartBarIndex := bar_index
            buySignalGiven := false
            sellSignalGiven := false
            buySignal := false
            sellSignal := false
        else
            highInRange := math.max(highInRange, high)
            lowInRange := math.min(lowInRange, low)
        rangeEndBarIndex := bar_index
    else
        if not na(highInRange) and not na(lowInRange) and not shouldExtend
            highLine := line.new(x1=rangeStartBarIndex, y1=highInRange, x2=rangeEndBarIndex + extendBars, y2=highInRange, color=lineColorHigh, width=lineWidth)
            lowLine := line.new(x1=rangeStartBarIndex, y1=lowInRange, x2=rangeEndBarIndex + extendBars, y2=lowInRange, color=lineColorLow, width=lineWidth)
            f_drawFibLevels(rangeStartBarIndex, rangeEndBarIndex + extendBars, highInRange, lowInRange)
            shouldExtend := true
 
        buySignal := close > highInRange and not buySignalGiven and shouldExtend
        sellSignal := close < lowInRange and not sellSignalGiven and shouldExtend
 
        if buySignal
            label.new(x=bar_index, y=lowInRange, text="Buy", color=color.green, style=label.style_label_up, textcolor=color.white)
            buySignalGiven := true
        if sellSignal
            label.new(x=bar_index, y=highInRange, text="Sell", color=color.red, style=label.style_label_down, textcolor=color.white)
            sellSignalGiven := true
 
// Reset the range after the end time plus extension
if bar_index > rangeEndBarIndex + extendBars
    highInRange := na
    lowInRange := na
    highLine := na
    lowLine := na
    shouldExtend := false
    buySignalGiven := false
    sellSignalGiven := false
    buySignal := false
    sellSignal := false
 
// Alert conditions
alertcondition(buySignal, title="Range 1 (NY Session Open) Buy Signal", message="Buy Signal at {{close}}" )
alertcondition(sellSignal, title="Range 1 (NY Session Open) Sell Signal", message="Sell Signal at {{close}}" )
//////////////////
// Range 1 End //
/////////////////
 
///////////////////
// Range 2 Start //
//////////////////
 
// Tracking high and low
var float highInRange1 = na
var float lowInRange1 = na
var line highLine1 = na
var line lowLine1 = na
var int rangeStartBarIndex1 = na
var int rangeEndBarIndex1 = na
var bool shouldExtend1 = false
var bool buySignalGiven1 = false
var bool sellSignalGiven1 = false
 
var bool buySignal1 = false
var bool sellSignal1 = false
 
if enableRange2
    if not na(time(timeframe.period, range2Session))
        if na(highInRange1)
            highInRange1 := high
            lowInRange1 := low
            rangeStartBarIndex1 := bar_index
            buySignalGiven1 := false
            sellSignalGiven1 := false
            buySignal1 := false
            sellSignal1 := false
        else
            highInRange1 := math.max(highInRange1, high)
            lowInRange1 := math.min(lowInRange1, low)
        rangeEndBarIndex1 := bar_index
    else
        if not na(highInRange1) and not na(lowInRange1) and not shouldExtend1
            highLine1 := line.new(x1=rangeStartBarIndex1, y1=highInRange1, x2=rangeEndBarIndex1 + extendBars1, y2=highInRange1, color=lineColorHigh1, width=lineWidth1)
            lowLine1 := line.new(x1=rangeStartBarIndex1, y1=lowInRange1, x2=rangeEndBarIndex1 + extendBars1, y2=lowInRange1, color=lineColorLow1, width=lineWidth1)
            f_drawFibLevels(rangeStartBarIndex1, rangeEndBarIndex1 + extendBars1, highInRange1, lowInRange1)
            shouldExtend1 := true
 
        buySignal1 := close > highInRange1 and not buySignalGiven1 and shouldExtend1
        sellSignal1 := close < lowInRange1 and not sellSignalGiven1 and shouldExtend1
 
        if buySignal1
            label.new(x=bar_index, y=lowInRange1, text="Buy", color=color.green, style=label.style_label_up, textcolor=color.white)
            buySignalGiven1 := true
        if sellSignal1
            label.new(x=bar_index, y=highInRange1, text="Sell", color=color.red, style=label.style_label_down, textcolor=color.white)
            sellSignalGiven1 := true
 
// Reset the range after the end time plus extension
if bar_index > rangeEndBarIndex1 + extendBars1
    highInRange1 := na
    lowInRange1 := na
    highLine1 := na
    lowLine1 := na
    shouldExtend1 := false
    buySignalGiven1 := false
    sellSignalGiven1 := false
    buySignal1 := false
    sellSignal1 := false
 
// Alert conditions
alertcondition(buySignal1, title="Range 2 (NY Session Close) Buy Signal", message="Buy Signal at {{close}}" )
alertcondition(sellSignal1, title="Range 2 (NY Session Close) Sell Signal ", message="Sell Signal at {{close}}" )
/////////////////
// Range 2 End //
/////////////////
 
///////////////////
// Range 3 Start //
///////////////////
 
// Tracking high and low
var float highInRange3 = na
var float lowInRange3 = na
var line highLine3 = na
var line lowLine3 = na
var int rangeStartBarIndex3 = na
var int rangeEndBarIndex3 = na
var bool shouldExtend3 = false
var bool buySignalGiven3 = false
var bool sellSignalGiven3 = false
 
var bool buySignal3 = false
var bool sellSignal3 = false
 
if enableRange3
    if not na(time(timeframe.period, range3Session))
        if na(highInRange3)
            highInRange3 := high
            lowInRange3 := low
            rangeStartBarIndex3 := bar_index
            buySignalGiven3 := false
            sellSignalGiven3 := false
            buySignal3 := false
            sellSignal3 := false
        else
            highInRange3 := math.max(highInRange3, high)
            lowInRange3 := math.min(lowInRange3, low)
        rangeEndBarIndex3 := bar_index
    else
        if not na(highInRange3) and not na(lowInRange3) and not shouldExtend3
            highLine3 := line.new(x1=rangeStartBarIndex3, y1=highInRange3, x2=rangeEndBarIndex3 + extendBars3, y2=highInRange3, color=lineColorHigh3, width=lineWidth3)
            lowLine3 := line.new(x1=rangeStartBarIndex3, y1=lowInRange3, x2=rangeEndBarIndex3 + extendBars3, y2=lowInRange3, color=lineColorLow3, width=lineWidth3)
            f_drawFibLevels(rangeStartBarIndex3, rangeEndBarIndex3 + extendBars3, highInRange3, lowInRange3)
            shouldExtend3 := true
 
        buySignal3 := close > highInRange3 and not buySignalGiven3 and shouldExtend3
        sellSignal3 := close < lowInRange3 and not sellSignalGiven3 and shouldExtend3
 
        if buySignal3
            label.new(x=bar_index, y=lowInRange3, text="Buy", color=color.green, style=label.style_label_up, textcolor=color.white)
            buySignalGiven3 := true
        if sellSignal3
            label.new(x=bar_index, y=highInRange3, text="Sell", color=color.red, style=label.style_label_down, textcolor=color.white)
            sellSignalGiven3 := true
 
// Reset Range 3 after the end time plus extension
if bar_index > rangeEndBarIndex3 + extendBars3
    highInRange3 := na
    lowInRange3 := na
    highLine3 := na
    lowLine3 := na
    shouldExtend3 := false
    buySignalGiven3 := false
    sellSignalGiven3 := false
    buySignal3 := false
    sellSignal3 := false
 
// Alert conditions
alertcondition(buySignal3, title="Range 3 (Tokyo Session Open) Buy Signal", message="Buy Signal at {{close}}" )
alertcondition(sellSignal3, title="Range 3 (Tokyo Session Close) Sell Signal ", message="Sell Signal at {{close}}" )
/////////////////
// Range 3 End //
/////////////////
 
///////////////////
// Range 4 Start //
///////////////////
 
// Tracking high and low
var float highInRange4 = na
var float lowInRange4 = na
var line highLine4 = na
var line lowLine4 = na
var int rangeStartBarIndex4 = na
var int rangeEndBarIndex4 = na
var bool shouldExtend4 = false
var bool buySignalGiven4 = false
var bool sellSignalGiven4 = false
 
var bool buySignal4 = false
var bool sellSignal4 = false
 
if enableRange4
    if not na(time(timeframe.period, range4Session))
        if na(highInRange4)
            highInRange4 := high
            lowInRange4 := low
            rangeStartBarIndex4 := bar_index
            buySignalGiven4 := false
            sellSignalGiven4 := false
            buySignal4 := false
            sellSignal4 := false
        else
            highInRange4 := math.max(highInRange4, high)
            lowInRange4 := math.min(lowInRange4, low)
        rangeEndBarIndex4 := bar_index
    else
        if not na(highInRange4) and not na(lowInRange4) and not shouldExtend4
            highLine4 := line.new(x1=rangeStartBarIndex4, y1=highInRange4, x2=rangeEndBarIndex4 + extendBars4, y2=highInRange4, color=lineColorHigh4, width=lineWidth4)
            lowLine4 := line.new(x1=rangeStartBarIndex4, y1=lowInRange4, x2=rangeEndBarIndex4 + extendBars4, y2=lowInRange4, color=lineColorLow4, width=lineWidth4)
            f_drawFibLevels(rangeStartBarIndex4, rangeEndBarIndex4 + extendBars4, highInRange4, lowInRange4)
            shouldExtend4 := true
 
        buySignal4 := close > highInRange4 and not buySignalGiven4 and shouldExtend4
        sellSignal4 := close < lowInRange4 and not sellSignalGiven4 and shouldExtend4
 
        if buySignal4
            label.new(x=bar_index, y=lowInRange4, text="Buy", color=color.green, style=label.style_label_up, textcolor=color.white)
            buySignalGiven4 := true
        if sellSignal4
            label.new(x=bar_index, y=highInRange4, text="Sell", color=color.red, style=label.style_label_down, textcolor=color.white)
            sellSignalGiven4 := true
 
// Reset the range after the end time plus extension
if bar_index > rangeEndBarIndex4 + extendBars4
    highInRange4 := na
    lowInRange4 := na
    highLine4 := na
    lowLine4 := na
    shouldExtend4 := false
    buySignalGiven4 := false
    sellSignalGiven4 := false
    buySignal4 := false
    sellSignal4 := false
 
// Alert conditions
alertcondition(buySignal4, title="Range 4 (London Session Open) Buy Signal", message="Buy Signal at {{close}}" )
alertcondition(sellSignal4, title="Range 4 (London Session Open) Sell Signal ", message="Sell Signal at {{close}}" )
//////////////////
// Range 4 End //
/////////////////

← 返回列表