Sonarlab - Order Blocks

vuetratrading · study · 98 行 · 点赞 16,421 · TradingView 原页

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

Pine Script

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ClayeWeight
// Sonarlabs - Order Block finder
 
//@version=4
study(title="Sonarlab - Order Blocks", shorttitle="Sonarlab - OB", overlay=true, max_boxes_count=20)
sens = input(28, minval=1, title="Sensitivity", group="Order Block", tooltip="Lower the sensitivity to show more order blocks. A higher sensitivity will show less order blocks.")
sens := sens/100
src = close
 
// Alerts
buy_alert = input(title="Buy Signal", type=input.bool, defval=true, group="Alerts", tooltip="An alert will be sent when price goes below the top of a bullish order block.")
sell_alert = input(title="Sell Signal", type=input.bool, defval=true, group="Alerts", tooltip="An alert will be sent when price goes above the bottom of a bearish order block.")
 
 
// Colours
color col_bullish = #5db49e
color col_bearish = #4760bb
color col_bullish_ob = color.new(#64C4AC,85)
color col_bearish_ob = color.new(#506CD3,85)
 
// Delacring Variables
bool ob_created = false
bool ob_created_bull = false
 
// Declaring Box Arrays
var box drawlongBox = na
var longBoxes = array.new_box()
var box drawShortBox = na
var shortBoxes = array.new_box()
 
 
 
pc = ((open-open[4])/open[4])*100
var int cross_index = na
 
if crossunder(pc,-sens)
    ob_created := true
    cross_index := bar_index
 
if crossover(pc,sens)
    ob_created_bull := true
    cross_index := bar_index
 
 
 
// Bearish OB
if (ob_created and (cross_index-cross_index[1])>5)
    float last_green = 0
    float highest = 0
    for i = 4 to 15
        if(close[i]>open[i])
            last_green := i
            break
    drawlongBox := box.new(left=bar_index[last_green], top=high[last_green], bottom=low[last_green], right=bar_index[last_green], bgcolor=col_bearish_ob, border_color=col_bearish, extend=extend.right)
    array.push(longBoxes, drawlongBox)
    
// Bullish OB
if (ob_created_bull and (cross_index-cross_index[1])>5)
    float last_red = 0
    float highest = 0
    for i = 4 to 15
        if(close[i]<open[i])
            last_red := i
            break
    drawShortBox := box.new(left=bar_index[last_red], top=high[last_red], bottom=low[last_red], right=bar_index[last_red], bgcolor=col_bullish_ob, border_color=col_bullish, extend=extend.right)
    array.push(shortBoxes, drawShortBox)
 
 
// ----------------- Bearish Order Block -------------------
// Clean up OB boxes, and Place alerts
if (array.size(longBoxes) > 0)
    for i = (array.size(longBoxes) - 1) to 0
        sbox = array.get(longBoxes,i)
        top = box.get_top(sbox)
        bot = box.get_bottom(sbox)
        if close[1] > top and close[2] > top
            array.remove(longBoxes, i)
            box.delete(sbox)
        //Alerts
        if high > bot
            if sell_alert
                alert("Price inside Bearish OB", alert.freq_once_per_bar)
 
// ----------------- Bullish Clean Up -------------------
// Clean up OB boxes
if (array.size(shortBoxes) > 0)
    for i = (array.size(shortBoxes) - 1) to 0
        sbox = array.get(shortBoxes,i)
        bot = box.get_bottom(sbox)
        top = box.get_top(sbox)
        if close[1] < bot and close[2] < bot
            array.remove(shortBoxes, i)
            box.delete(sbox)
        //Alerts
        if low < top
            if sell_alert
                alert("Price inside Bullish OB", alert.freq_once_per_bar)

← 返回列表