Order Blocks

MarkMiddleton2020 · study · 120 行 · 点赞 5,609 · TradingView 原页

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

Pine Script

//@version=4
study(title="Order Blocks", overlay=true,max_bars_back=1000)
 
// Input options
sensitivity = input(title="Sensitivity", type=input.integer,defval=26, minval=5, maxval=100, group="BASIC SETTINGS")
 
bearishLLColour = input(title="Bearish OB Colour", type=input.color,defval=color.rgb(255,0,0, 80), group="STYLES")
bullishLLColour = input(title="Bullish OB Colour", type=input.color,defval=color.rgb(0,255,0, 80), group="STYLES")
 
 
// tracking for entries
var int lastDownIndex=0
var float lastDown=0
var float lastDownClose=0
var float lastDownLow=0
var float lastDownOpen=0
 
var int lastUpIndex=0
var float lastUp=0
var float lastUpLow=0
var float lastUpHigh=0
var float lastUpClose=0
var int longModeIndex=0
var float lastUpOpen=0
 
// structure
var int structureLowIndex=0
float structureLow=1000000
 
// drawings
var longBoxes = array.new_box()
var shortBoxes = array.new_box()
 
 
// load levels
var int lastLongIndex=0
var int lastShortIndex=0
var bool lastShortIndex_EL=0
 
// stop run detection
var box last_bull=na
var box last_bear=na
 
var color barc=color.red
var color obarc=color.white
barc:=color.red
 
 
// get the lowest point in the range
structureLow:=lowest(low, sensitivity)[1]
 
// bearish break of structure
if(crossunder(low,structureLow))
    // add short bos
    if(high>lastUpHigh)
        lastUpHigh:=high
    if((bar_index - lastUpIndex) < 4000)
    
         // update structure high
        for p = 1 to (bar_index-lastUpIndex) by 1
            if(high[p]>lastUpHigh)
                lastUpHigh:=high[p]
    
        last_bear:= box.new(left=lastUpIndex, top=lastUpHigh, bottom=lastUpLow,right=lastUpIndex, bgcolor=lastShortIndex==lastUpIndex?color.rgb(0, 0, 0, 100):bearishLLColour,border_color=bearishLLColour, extend=extend.right)
        array.push(shortBoxes,last_bear)
 
 
 
// bullish break of structure?
if((array.size(shortBoxes)>0))
    for i = (array.size(shortBoxes)-1) to 0
        box=array.get(shortBoxes,i)
        top=box.get_top(box)
        bottom=box.get_bottom(box)
        left=box.get_left(box)
        if(high>top and (close>open) and (bar_index!=lastLongIndex))
            // remove the short box 
            box.delete(box)
            array.remove(shortBoxes, i)
            // calculate LL bottom
            LLBottom= (low<lastDownLow?low:lastDownLow)
            // ok to darw
            if((bar_index - lastDownIndex) < 4000)
 
                // update structure low
                for p = 1 to (bar_index-lastDownIndex) by 1
                    if(low[p]<LLBottom)
                        LLBottom:=low[p]
 
                //
                last_bull:=box.new(left=lastDownIndex, top=lastDown, bottom=LLBottom,right=lastDownIndex, bgcolor=lastLongIndex==lastDownIndex?color.rgb(0, 0, 0, 100):lastShortIndex_EL==true?color.rgb(0, 255, 0, 80):bullishLLColour,border_color=lastLongIndex==lastDownIndex?color.rgb(0, 0, 0, 100):bullishLLColour, extend=extend.right)
                array.push(longBoxes, last_bull)
        
        lastLongIndex:=bar_index
 
// remove LL if close below
if((array.size(longBoxes) > 0))
    for i = (array.size(longBoxes)-1) to 0
        lbox=array.get(longBoxes,i)
        bottom=box.get_bottom(lbox)
        top=box.get_top(lbox)
        if(close<bottom)
            array.remove(longBoxes, i)
            box.delete(lbox)
 
// record last up and down candles
if(close<open)
    lastDown:=high
    lastDownClose:=close
    lastDownOpen:=open
    lastDownLow:=low
    lastDownIndex:=bar_index
 
if(close>open)
    lastUp:=close
    lastUpIndex:=bar_index
    lastUpOpen:=open
    lastUpLow:=low
    lastUpClose:=close
    lastUpHigh:=high

← 返回列表