策略知识库.EN
策略

Pivot-Order-Blocks

ChaoZhang · PineScript · 工具与附录 · 2022-05-11 23:35:28

全部策略 →

无说明:源文件没有中文正文。

阅读英文版本 →

参数

参数默认值说明
v_input_int_110(?=== Pivots ===)Pivot High
v_input_int_210/
v_input_int_310Pivot Low
v_input_int_410/
v_input_int_530(?=== Plots ===)Box Size
v_input_1#00E600Bullish Box Color
v_input_2#FF0000Bearish Box Color
源码(64 行)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © MensaTrader

//@version=5
indicator("Pivot Order Blocks", shorttitle="Pivot - OB", overlay=true, max_bars_back=500, max_boxes_count=250)

//Titles
inputGroupTitle     = "=== Pivots ==="
plotGroupTitle      = "=== Plots ==="


//Inputs
leftLenH            = input.int(title="Pivot High", defval=10, minval=1, inline="Pivot High", group=inputGroupTitle)
rightLenH           = input.int(title="/", defval=10, minval=1, inline="Pivot High", group=inputGroupTitle)

leftLenL            = input.int(title="Pivot Low", defval=10, minval=1, inline="Pivot Low", group=inputGroupTitle)
rightLenL           = input.int(title="/", defval=10, minval=1, inline="Pivot Low", group=inputGroupTitle)

boxLength           = input.int(30, title="Box Size", tooltip="Amount of candles long", group=plotGroupTitle)
bullBoxColor        = input('#00E600', title="Bullish Box Color", group=plotGroupTitle, inline="1")
bearBoxColor        = input('#FF0000', title="Bearish Box Color", group=plotGroupTitle, inline="1")

ph                  = ta.pivothigh(leftLenH, rightLenH)
pl                  = ta.pivotlow(leftLenL, rightLenL)

//Variables
var leftBull        = bar_index
var rightBull       = bar_index
var topBull         = close
var bottomBull      = close

var leftBear        = bar_index
var rightBear       = bar_index
var topBear         = close
var bottomBear      = close


//Bear Box Calc
if ph
    leftBear        := bar_index-leftLenH
    rightBear       := bar_index-(leftLenH-boxLength)
    topBear         := close>open ? close[leftLenH] : open[leftLenH]
    bottomBear      := close>open ? open[leftLenH] : close[leftLenH]

//Bull Box Calc
if pl
    leftBull        := bar_index-leftLenL
    rightBull       := bar_index-(leftLenL-boxLength)
    topBull         := close>open ? close[leftLenL] : open[leftLenL]
    bottomBull      := close>open ? open[leftLenL] : close[leftLenL]
     
    
//if pl
//    bull            = box.new(left=leftBull, right=rightBull, top=topBull, bottom=bottomBull, bgcolor=color.new(bullBoxColor,80), border_color=bullBoxColor)

//if ph
//    bear            = box.new(left=leftBear, right=rightBear, top=topBear, bottom=bottomBear, bgcolor=color.new(bearBoxColor,80), border_color=bearBoxColor)



if pl
    strategy.entry("Enter Long", strategy.long)
else if ph
    strategy.entry("Enter Short", strategy.short)