0% found this document useful (0 votes)
85 views49 pages

Pine Script Order Block Configuration

This document contains a Pine Script™ code for a trading indicator called 'Weighted Volume Profile Pivot Points' developed by Flux Charts. It includes various configurations and settings for displaying order blocks and pivot points on trading charts, along with functionalities for analyzing market data. The script is designed to be customizable, allowing users to adjust parameters such as volume weighting, swing length, and the number of order blocks displayed.

Uploaded by

brianototo15
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
85 views49 pages

Pine Script Order Block Configuration

This document contains a Pine Script™ code for a trading indicator called 'Weighted Volume Profile Pivot Points' developed by Flux Charts. It includes various configurations and settings for displaying order blocks and pivot points on trading charts, along with functionalities for analyzing market data. The script is designed to be customizable, allowing users to adjust parameters such as volume weighting, swing length, and the number of order blocks displayed.

Uploaded by

brianototo15
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.

0 at
[Link]

// © fluxchart

//@version=5

const bool DEBUG = false

const bool OBSettings = false

const int maxBoxesCount = 500

const int maxRowSize = 50

const int priceBoxSize = 5

const int v2Gap = 1

const string v2TextSize = [Link]

const int edgeOffset = 25

const int minDistance = 125

const float overlapThresholdPercentage = 0

const int maxDistanceToLastBar = 1750 // Affects Running Time


const int maxOrderBlocks = 30

indicator("Weighted Volume Profile Pivot Points | Flux Charts", shorttitle = "WVPPP | Flux Charts",
overlay = true, max_boxes_count = maxBoxesCount, max_labels_count = maxBoxesCount,
max_lines_count = maxBoxesCount, max_bars_back = 1005)

showPreviousSessions = [Link](true, "Show Previous Sessions", group = "General Configuration",


display = [Link])

dbgMode = [Link]("Order Blocks", "Mode", options = ["Pivots", "Order Blocks"], group = "General
Configuration")

analyzeBars = [Link](200, "Analyze Bars", minval = 1, maxval = 1000, group = "General Configuration")

rowCount = [Link](30, "Row Count", minval = 1, maxval = 1000, group = "General Configuration")

volumeWeight = [Link]("Normal", "Volume Weighting", ["Recent", "Normal", "Past"], group =


"General Configuration", display = [Link])

swingLen = [Link](10, "Swing Length", minval = 1, group = "General Configuration")

keepOldPOC = [Link](true, "Keep Past POC Lines", group = "General Configuration")

intersectionBody = DEBUG ? [Link](false, "[DBG] Intersection With Body", group = "General


Configuration") : false
// OB Settings

showInvalidated = OBSettings ? [Link](true, "Show Historic Zones", group = "Order Blocks", display =
[Link]) : true

OBRendering = OBSettings ? [Link](true, "Show Order Blocks", group = "Order Blocks", display =
[Link]) : false

orderBlockVolumetricInfo = OBSettings ? [Link](true, "Volumetric Info", group = "Order Blocks",


inline="EV", display = [Link]) : true

obEndMethod = OBSettings ? [Link]("Wick", "Zone Invalidation", options = ["Wick", "Close"],


group = "Order Blocks", display = [Link]) : "Wick"

combineOBs = DEBUG ? [Link](true, "Combine Zones", group = "Order Blocks", display =


[Link]) : true

maxATRMult = DEBUG ? [Link](3.5,"Max Atr Multiplier", group = "Order Blocks") : 3.5

zoneCount = OBSettings ? [Link]("Low", 'Zone Count', options = ["High", "Medium", "Low", "One"],
tooltip = "Number of Order Block Zones to be rendered. Higher options will result in older Order Blocks
shown.", group = "Order Blocks", display = [Link]) : "Low"

bullOrderBlockColor = OBSettings ? input(#08998180, 'Bullish', inline = 'obColor', group = 'Order Blocks',


display = [Link]) : #08998180

bearOrderBlockColor = OBSettings ? input(#f2364680, 'Bearish', inline = 'obColor', group = 'Order


Blocks', display = [Link]) : #f2364680

bullishOrderBlocks = zoneCount == "One" ? 1 : zoneCount == "Low" ? 3 : zoneCount == "Medium" ? 5 :


10
bearishOrderBlocks = zoneCount == "One" ? 1 : zoneCount == "Low" ? 3 : zoneCount == "Medium" ? 5 :
10

timeframe1Enabled = true

timeframe1 = ""

highlightSessions = [Link](true, "Highlight Sessions", group = "Style", display = [Link])

dbgStyling = DEBUG ? [Link]("v2", "[DBG] Styling", ["v1", "v2"], group = "Style", display =
[Link]) : "v2"

alignSetting = [Link]("Left", "Align To", options = ["Left", "Right"], group = "Style", display =
[Link])

POCEnabled = [Link](true, "POC Line ", inline = "POC", group = "Style", display = [Link])

POCLineStyle = [Link]("____", " ", options = ["____", "----", "...."], group = "Style", inline = "POC",
display = [Link])

POCLineWidth = [Link](2, "", options = [1,2,3], group = "Style", inline = "POC", display = [Link])

POCLineColor = [Link]([Link], "", group = "Style", inline = "POC", display = [Link])

bullishColor = [Link](#089981, "Bullish", inline = "color", group = "Style", display = [Link])


bearishColor = [Link](#f23646, "Bearish", inline = "color", group = "Style", display = [Link])

textColor = [Link](#ffffff80, "Text Color", group = "Style")

extendZonesBy = DEBUG ? [Link](15, "Extend Zones", group = "Style", minval = 1, maxval = 30, inline =
"ExtendZones") : 15

extendZonesDynamic = DEBUG ? [Link](true, "Dynamic", group = "Style", inline = "ExtendZones") :


true

combinedText = DEBUG ? [Link](false, "Combined Text", group = "Style", inline =


"CombinedColor") : false

volumeBarsPlace = DEBUG ? [Link]("Left", "Show Volume Bars At", options = ["Left", "Right"],
group = "Style", inline = "volumebars") : "Left"

mirrorVolumeBars = DEBUG ? [Link](true, "Mirror Volume Bars", group = "Style", inline =


"volumebars") : true

volumeBarsLeftSide = (volumeBarsPlace == "Left")

extendZonesByTime = extendZonesBy * timeframe.in_seconds([Link]) * 1000

atr = [Link](10)
type orderBlockInfo

float top

float bottom

float obVolume

string obType

int startTime

float bbVolume

float obLowVolume

float obHighVolume

bool breaker

int breakTime

string timeframeStr

bool disabled = false

string combinedTimeframesStr = na

bool combined = false


type orderBlock

orderBlockInfo info

bool isRendered = false

box orderBox = na

box breakerBox = na

line orderBoxLineTop = na

line orderBoxLineBottom = na

line breakerBoxLineTop = na

line breakerBoxLineBottom = na

//

box orderBoxText = na

box orderBoxPositive = na

box orderBoxNegative = na
line orderSeperator = na

line orderTextSeperator = na

createOrderBlock (orderBlockInfo orderBlockInfoF) =>

orderBlock newOrderBlock = [Link](orderBlockInfoF)

newOrderBlock

safeDeleteOrderBlock (orderBlock orderBlockF) =>

[Link] := false

[Link]([Link])

[Link]([Link])

[Link]([Link])

[Link]([Link])

[Link]([Link])
[Link]([Link])

[Link]([Link])

[Link]([Link])

[Link]([Link])

[Link]([Link])

[Link]([Link])

type timeframeInfo

int index = na

string timeframeStr = na

bool isEnabled = false

orderBlockInfo[] bullishOrderBlocksList = na

orderBlockInfo[] bearishOrderBlocksList = na

newTimeframeInfo (index, timeframeStr, isEnabled) =>


newTFInfo = [Link]()

[Link] := index

[Link] := isEnabled

[Link] := timeframeStr

newTFInfo

type obSwing

int x = na

float y = na

float swingVolume = na

bool crossed = false

// ____ TYPES END ____


var timeframeInfo[] timeframeInfos = [Link](newTimeframeInfo(1, timeframe1,
timeframe1Enabled))

var bullishOrderBlocksList = [Link]<orderBlockInfo>(0)

var bearishOrderBlocksList = [Link]<orderBlockInfo>(0)

var allOrderBlocksList = [Link]<orderBlock>(0)

moveLine(_line, _x, _y, _x2) =>

line.set_xy1(_line, _x, _y)

line.set_xy2(_line, _x2, _y)

moveBox (_box, _topLeftX, _topLeftY, _bottomRightX, _bottomRightY) =>

box.set_lefttop(_box, _topLeftX, _topLeftY)

box.set_rightbottom(_box, _bottomRightX, _bottomRightY)

isTimeframeLower (timeframe1F, timeframe2F) =>


timeframe.in_seconds(timeframe1F) < timeframe.in_seconds(timeframe2F)

getMinTimeframe (timeframe1F, timeframe2F) =>

if isTimeframeLower(timeframe1F, timeframe2F)

timeframe1F

else

timeframe2F

getMaxTimeframe (timeframe1F, timeframe2F) =>

if isTimeframeLower(timeframe1F, timeframe2F)

timeframe2F

else

timeframe1F

formatTimeframeString (formatTimeframe) =>

timeframeF = formatTimeframe == "" ? [Link] : formatTimeframe


if [Link](timeframeF, "D") or [Link](timeframeF, "W") or [Link](timeframeF, "S") or
[Link](timeframeF, "M")

timeframeF

else

seconds = timeframe.in_seconds(timeframeF)

if seconds >= 3600

hourCount = int(seconds / 3600)

[Link](hourCount) + " Hour" + (hourCount > 1 ? "s" : "")

else

timeframeF + " Min"

betterCross(s1, s2) =>

string ret = na

if s1 >= s2 and s1[1] < s2

ret := "Bull"
if s1 < s2 and s1[1] >= s2

ret := "Bear"

ret

colorWithTransparency (colorF, transparencyX) =>

[Link](colorF, color.t(colorF) * transparencyX)

createOBBox (boxColor, transparencyX = 1.0, xlocType = xloc.bar_time) =>

[Link](na, na, na, na, text_size = [Link], xloc = xlocType, extend = [Link], bgcolor =
colorWithTransparency(boxColor, transparencyX), text_color = textColor, text_halign =
text.align_center, border_color = #00000000)

renderOrderBlock (orderBlock ob) =>

orderBlockInfo info = [Link]

[Link] := true

orderColor = [Link] == "Bull" ? bullOrderBlockColor : bearOrderBlockColor


if OBRendering and (not false or not (false and [Link])) and not (not showInvalidated and
[Link])

[Link] := createOBBox(orderColor, 1.5)

if [Link]

[Link].set_bgcolor(colorWithTransparency(orderColor, 1.1))

[Link] := createOBBox([Link]([Link], 100))

if orderBlockVolumetricInfo

[Link] := createOBBox(bullOrderBlockColor)

[Link] := createOBBox(bearOrderBlockColor)

[Link] :=
[Link](na,na,na,na,xloc.bar_time,[Link],textColor,line.style_dashed,1)

[Link] :=
[Link](na,na,na,na,xloc.bar_time,[Link],textColor,line.style_solid,1)

zoneSize = extendZonesDynamic ? na([Link]) ? extendZonesByTime : ([Link] -


[Link]) : extendZonesByTime

if na([Link])

zoneSize := (time + 1) - [Link]


startX = volumeBarsLeftSide ? [Link] : [Link] + zoneSize - zoneSize / 3

maxEndX = volumeBarsLeftSide ? [Link] + zoneSize / 3 : [Link] + zoneSize

moveBox([Link], [Link], [Link], [Link] + zoneSize, [Link])

moveBox([Link], volumeBarsLeftSide ? maxEndX : [Link], [Link],


volumeBarsLeftSide ? [Link] + zoneSize : startX, [Link])

percentage = int(([Link]([Link], [Link]) /


[Link]([Link], [Link])) * 100.0)

OBText = (na([Link]) ? formatTimeframeString([Link]) :


[Link]) + " OB"

box.set_text([Link], (orderBlockVolumetricInfo ? [Link]([Link],


[Link]) + " (" + [Link](percentage) + "%)\n" : "") + (combinedText and [Link] ?
"[Combined]\n" : "") + OBText)

if orderBlockVolumetricInfo

showHighLowBoxText = false
curEndXHigh = int([Link](([Link] / [Link]) * (maxEndX - startX) + startX))

curEndXLow = int([Link](([Link] / [Link]) * (maxEndX - startX) + startX))

moveBox([Link], mirrorVolumeBars ? startX : curEndXLow, [Link],


mirrorVolumeBars ? curEndXHigh : maxEndX, ([Link] + [Link]) / 2)

box.set_text([Link], showHighLowBoxText ? [Link]([Link],


[Link]) : "")

moveBox([Link], mirrorVolumeBars ? startX : curEndXHigh, [Link],


mirrorVolumeBars ? curEndXLow : maxEndX, ([Link] + [Link]) / 2)

box.set_text([Link], showHighLowBoxText ? [Link]([Link],


[Link]) : "")

moveLine([Link], volumeBarsLeftSide ? startX : maxEndX, ([Link] + [Link]) /


2, volumeBarsLeftSide ? maxEndX : startX)

line.set_xy1([Link], volumeBarsLeftSide ? maxEndX : startX, [Link])

line.set_xy2([Link], volumeBarsLeftSide ? maxEndX : startX, [Link])


findOBSwings(len) =>

var swingType = 0

var obSwing top = [Link](na, na)

var obSwing bottom = [Link](na, na)

upper = [Link](len)

lower = [Link](len)

swingType := high[len] > upper ? 0 : low[len] < lower ? 1 : swingType

if swingType == 0 and swingType[1] != 0

top := [Link](bar_index[len], high[len], volume[len])

if swingType == 1 and swingType[1] != 1

bottom := [Link](bar_index[len], low[len], volume[len])


[top, bottom]

findOrderBlocks () =>

if bar_index > last_bar_index - maxDistanceToLastBar and [Link]

[top, btm] = findOBSwings(swingLen)

useBody = false

max = useBody ? [Link](close, open) : high

min = useBody ? [Link](close, open) : low

// Bullish Order Block

bullishBreaked = 0

if [Link]() > 0

for i = [Link]() - 1 to 0

currentOB = [Link](i)
if not [Link]

if (obEndMethod == "Wick" ? low : [Link](open, close)) < [Link]

[Link] := true

[Link] := time

[Link] := volume

else

if high > [Link]

[Link](i)

else if i < bullishOrderBlocks and top.y < [Link] and top.y > [Link]

bullishBreaked := 1

if close > top.y and not [Link]

[Link] := true

boxBtm = max[1]

boxTop = min[1]
boxLoc = time[1]

for i = 1 to (bar_index - top.x) - 1

boxBtm := [Link](min[i], boxBtm)

boxTop := boxBtm == min[i] ? max[i] : boxTop

boxLoc := boxBtm == min[i] ? time[i] : boxLoc

newOrderBlockInfo = [Link](boxTop, boxBtm, volume + volume[1] + volume[2],


"Bull", boxLoc)

[Link] := volume[2]

[Link] := volume + volume[1]

obSize = [Link]([Link] - [Link])

if obSize <= atr * maxATRMult

[Link](newOrderBlockInfo)

if [Link]() > maxOrderBlocks


[Link]()

// Bearish Order Block

bearishBreaked = 0

if [Link]() > 0

for i = [Link]() - 1 to 0

currentOB = [Link](i)

if not [Link]

if (obEndMethod == "Wick" ? high : [Link](open, close)) > [Link]

[Link] := true

[Link] := time

[Link] := volume

else
if low < [Link]

[Link](i)

else if i < bearishOrderBlocks and btm.y > [Link] and btm.y < [Link]

bearishBreaked := 1

if close < btm.y and not [Link]

[Link] := true

boxBtm = min[1]

boxTop = max[1]

boxLoc = time[1]

for i = 1 to (bar_index - btm.x) - 1

boxTop := [Link](max[i], boxTop)

boxBtm := boxTop == max[i] ? min[i] : boxBtm

boxLoc := boxTop == max[i] ? time[i] : boxLoc


newOrderBlockInfo = [Link](boxTop, boxBtm, volume + volume[1] + volume[2],
"Bear", boxLoc)

[Link] := volume + volume[1]

[Link] := volume[2]

obSize = [Link]([Link] - [Link])

if obSize <= atr * maxATRMult

[Link](newOrderBlockInfo)

if [Link]() > maxOrderBlocks

[Link]()

true

areaOfOB (orderBlockInfo OBInfoF) =>

float XA1 = [Link]

float XA2 = na([Link]) ? time + 1 : [Link]


float YA1 = [Link]

float YA2 = [Link]

float edge1 = [Link]((XA2 - XA1) * (XA2 - XA1) + (YA2 - YA2) * (YA2 - YA2))

float edge2 = [Link]((XA2 - XA2) * (XA2 - XA2) + (YA2 - YA1) * (YA2 - YA1))

float totalArea = edge1 * edge2

totalArea

doOBsTouch (orderBlockInfo OBInfo1, orderBlockInfo OBInfo2) =>

float XA1 = [Link]

float XA2 = na([Link]) ? time + 1 : [Link]

float YA1 = [Link]

float YA2 = [Link]

float XB1 = [Link]

float XB2 = na([Link]) ? time + 1 : [Link]

float YB1 = [Link]


float YB2 = [Link]

float intersectionArea = [Link](0, [Link](XA2, XB2) - [Link](XA1, XB1)) * [Link](0,


[Link](YA1, YB1) - [Link](YA2, YB2))

float unionArea = areaOfOB(OBInfo1) + areaOfOB(OBInfo2) - intersectionArea

float overlapPercentage = (intersectionArea / unionArea) * 100.0

if overlapPercentage > overlapThresholdPercentage

true

else

false

isOBValid (orderBlockInfo OBInfo) =>

valid = true

if [Link]

valid := false
valid

combineOBsFunc () =>

if [Link]() > 0

lastCombinations = 999

while lastCombinations > 0

lastCombinations := 0

for i = 0 to [Link]() - 1

curOB1 = [Link](i)

for j = 0 to [Link]() - 1

curOB2 = [Link](j)

if i == j

continue

if not isOBValid([Link]) or not isOBValid([Link])

continue

if [Link] != [Link]
continue

if doOBsTouch([Link], [Link])

[Link] := true

[Link] := true

orderBlock newOB = createOrderBlock([Link]([Link]([Link],


[Link]), [Link]([Link], [Link]), [Link] +
[Link], [Link]))

[Link] := [Link]([Link], [Link])

[Link] := [Link](nz([Link]),
nz([Link]))

[Link] := [Link] == 0 ? na : [Link]

[Link] := [Link]

[Link] := [Link] + [Link]

[Link] := [Link] + [Link]

[Link] := [Link] + [Link]

[Link] := nz([Link], 0) + nz([Link], 0)

[Link] := [Link] or [Link]


[Link] := true

if timeframe.in_seconds([Link]) !=
timeframe.in_seconds([Link])

[Link] := (na([Link]) ?
formatTimeframeString([Link]) : [Link]) + " & " +
(na([Link]) ? formatTimeframeString([Link]) :
[Link])

[Link](newOB)

lastCombinations += 1

reqSeq (timeframeStr) =>

[bullishOrderBlocksListF, bearishOrderBlocksListF] = [Link]([Link], timeframeStr,


[bullishOrderBlocksList, bearishOrderBlocksList])

[bullishOrderBlocksListF, bearishOrderBlocksListF]

getTFData (timeframeInfo timeframeInfoF, timeframeStr) =>


if not isTimeframeLower([Link], [Link]) and
[Link]

[bullishOrderBlocksListF, bearishOrderBlocksListF] = reqSeq(timeframeStr)

[bullishOrderBlocksListF, bearishOrderBlocksListF]

else

[na, na]

handleTimeframeInfo (timeframeInfo timeframeInfoF, bullishOrderBlocksListF, bearishOrderBlocksListF)


=>

if not isTimeframeLower([Link], [Link]) and


[Link]

[Link] := bullishOrderBlocksListF

[Link] := bearishOrderBlocksListF

handleOrderBlocksFinal () =>

if DEBUG

[Link]("Bullish OB Count " + [Link]([Link]()))


[Link]("Bearish OB Count " + [Link]([Link]()))

if [Link] () > 0

for i = 0 to [Link]() - 1

safeDeleteOrderBlock([Link](i))

[Link]()

for i = 0 to [Link]() - 1

curTimeframe = [Link](i)

if not [Link]

continue

if [Link]() > 0

for j = 0 to [Link]([Link]() - 1, bullishOrderBlocks - 1)

orderBlockInfoF = [Link](j)

[Link] := [Link]

[Link](createOrderBlock([Link](orderBlockInfoF)))
if [Link]() > 0

for j = 0 to [Link]([Link]() - 1, bearishOrderBlocks - 1)

orderBlockInfoF = [Link](j)

[Link] := [Link]

[Link](createOrderBlock([Link](orderBlockInfoF)))

if combineOBs

combineOBsFunc()

if [Link]() > 0

for i = 0 to [Link]() - 1

curOB = [Link](i)

if isOBValid([Link])

renderOrderBlock(curOB)
findOrderBlocks()

[bullishOrderBlocksListTimeframe1, bearishOrderBlocksListTimeframe1] =
getTFData([Link](0), timeframe1)

if [Link]

handleTimeframeInfo([Link](0), bullishOrderBlocksListTimeframe1,
bearishOrderBlocksListTimeframe1)

handleOrderBlocksFinal()

type rowType

float top

float bottom

int startIndex

int endIndex

float totalVolume = 0

float bullVolume = 0
float bearVolume = 0

box bullBox = na

box priceBox = na

box bearBox = na

type volumeProfile

array<rowType> rows

line POCLine = na

box highlightBox = na

int edgeIndex = na

int startIndex = na

float vpTop = na

float vpBottom = na

int vpStart = na

int vpEnd = na
type barType

float o = open

float c = close

float h = high

float l = low

float v = volume

var float validPivotHigh = na

var float validPivotLow = na

var int distanceToLastVP = 999

var volumeProfile latestVolumeProfile = na

if not na(latestVolumeProfile)

distanceToLastVP := bar_index - [Link]


pvHigh = [Link](swingLen, swingLen)

pvLow = [Link](swingLen, swingLen)

var float vph = na

var float vpl = na

vph := nz(pvHigh, vph)

vpl := nz(pvLow, vpl)

if dbgMode == "Pivots"

if (alignSetting == "Left" and distanceToLastVP > minDistance) or (alignSetting == "Right" and


distanceToLastVP > minDistance)

validPivotHigh := vph

validPivotLow := vpl
else if dbgMode == "Order Blocks"

if (alignSetting == "Left" and distanceToLastVP > minDistance) or (alignSetting == "Right" and


distanceToLastVP > minDistance)

if [Link]() > 0

curOB = [Link](0)

validPivotHigh := [Link]

if [Link]() > 0

curOB = [Link](0)

validPivotLow := [Link]

pivotsChanged = false

if ((validPivotHigh != validPivotHigh[1]) or (validPivotLow != validPivotLow[1])) and (not


na(validPivotHigh)) and (not na(validPivotLow)) and [Link](validPivotHigh - validPivotLow) > atr * 5

pivotsChanged := true
float top = validPivotHigh

float bottom = validPivotLow

float step = (top - bottom) / rowCount

float gap = rowCount < 100 ? (step / 3.0) : 0

var line oldLine = na

var box oldBox = na

var int latestEdgeIndex = na

if pivotsChanged

if not na(latestVolumeProfile)

[Link] := bar_index

oldBox := [Link]

if not keepOldPOC

[Link]([Link])
latestEdgeIndex := [Link]

oldLine := [Link]

latestVolumeProfile := [Link]()

[Link] := bar_index

[Link] := top

[Link] := bottom

[Link] := [Link]<rowType>(rowCount)

for x = 0 to rowCount - 1

rowTop = top - step * x

[Link](x, [Link](rowTop, rowTop - step))

doIntersect (candleTop, candleBottom, rowType row) =>

if (candleBottom > [Link])

false

else if (candleTop < [Link])


false

else

true

var float maxVolumeSize = 0

var float minVolumeSize = 0

f_lin_interpolate(x0, y0, x1, y1, x) =>

y0 + (x - x0) * (y1 - y0) / (x1 - x0)

renderRow (startIndex, flip, rowType row) =>

totalSize = f_lin_interpolate(minVolumeSize, 1, maxVolumeSize, maxRowSize, [Link])

bullSize = nz([Link](([Link] / [Link]) * totalSize), 0)

bearSize = nz([Link](([Link] / [Link]) * totalSize), 0)

bullPercent = [Link](bullSize * 100.0 / totalSize, "#.##") + "%"

bearPercent = [Link](100.0 - [Link]([Link](bullPercent,"%","")), "#.##") + "%"


rowPrice = ([Link] + [Link]) / 2.0

if dbgStyling == "v2"

[Link] := startIndex - bullSize

if flip

[Link] := startIndex + bullSize

else

[Link] := startIndex

[Link] := [Link]

if dbgStyling == "v1"

if bullSize + bearSize > 0

if not flip

[Link] := [Link] + bullSize + bearSize

[Link] := [Link]([Link], [Link] - gap / 2.0, [Link] + bullSize,


[Link] + gap / 2.0, bgcolor = bullishColor, border_color = [Link], border_width = 0)
if bearSize > 0

[Link] := [Link]([Link] + bullSize, [Link] - gap / 2.0, [Link] +


bullSize + bearSize, [Link] + gap / 2.0, bgcolor = bearishColor, border_color = [Link],
border_width = 0)

else

[Link] := [Link] - bullSize - bearSize

[Link] := [Link]([Link], [Link] - gap / 2.0, [Link] - bullSize,


[Link] + gap / 2.0, bgcolor = bullishColor, border_color = [Link], border_width = 0)

if bearSize > 0

[Link] := [Link]([Link] - bullSize, [Link] - gap / 2.0, [Link] -


bullSize - bearSize, [Link] + gap / 2.0, bgcolor = bearishColor, border_color = [Link],
border_width = 0)

else if dbgStyling == "v2"

if not flip

[Link] := [Link] + bullSize + v2Gap + priceBoxSize + v2Gap + bearSize

if bullSize > 0

[Link] := [Link]([Link], [Link] - gap / 2.0, [Link] + bullSize,


[Link] + gap / 2.0, text = bullPercent, text_size = v2TextSize, text_color = textColor, bgcolor =
[Link](bullishColor, 50), border_color = bullishColor, border_width = 1)

[Link] := [Link]([Link] + bullSize + v2Gap, [Link] - gap / 2.0, [Link] +


bullSize + v2Gap + priceBoxSize, [Link] + gap / 2.0, text = [Link](rowPrice, [Link]),
text_color = textColor, text_size = v2TextSize, bgcolor = [Link]([Link], 50), border_width = 1)

if bearSize > 0

[Link] := [Link]([Link] + bullSize + v2Gap + priceBoxSize + v2Gap, [Link] -


gap / 2.0, [Link] + bullSize + v2Gap + priceBoxSize + v2Gap + bearSize, [Link] + gap / 2.0,
text = bearPercent, text_size = v2TextSize, text_color = textColor, bgcolor = [Link](bearishColor, 50),
border_color = bearishColor, border_width = 1)

else

[Link] := [Link] - bullSize - v2Gap - priceBoxSize - v2Gap - bearSize

if bullSize > 0

[Link] := [Link]([Link], [Link] - gap / 2.0, [Link] - bullSize,


[Link] + gap / 2.0, text = bullPercent, text_size = v2TextSize, text_color = textColor, bgcolor =
[Link](bullishColor, 50), border_color = bullishColor, border_width = 1)

[Link] := [Link]([Link] - bullSize - v2Gap, [Link] - gap / 2.0, [Link] -


bullSize - v2Gap - priceBoxSize, [Link] + gap / 2.0, text = [Link](rowPrice, [Link]),
text_color = textColor, text_size = v2TextSize, bgcolor = [Link]([Link], 50), border_width = 1)

if bearSize > 0

[Link] := [Link]([Link] - bullSize - v2Gap - priceBoxSize - v2Gap, [Link] -


gap / 2.0, [Link] - bullSize - v2Gap - priceBoxSize - v2Gap - bearSize, [Link] + gap / 2.0,
text = bearPercent, text_size = v2TextSize, text_color = textColor, bgcolor = [Link](bearishColor, 50),
border_color = bearishColor, border_width = 1)

curIndex = bar_index
const float weightImpact = 0.85

if ((bar_index > last_bar_index - maxDistanceToLastBar and [Link] and


showPreviousSessions) or ([Link] and not showPreviousSessions)) and (not
na(latestVolumeProfile))

for i = 0 to analyzeBars

for j = 0 to [Link]() - 1

curRow = [Link](j)

vol = volume[i]

if volumeWeight == "Recent"

vol := ((vol * weightImpact) / (i + 1)) + (vol * (1.0 - weightImpact))

if volumeWeight == "Past"

vol := ((vol * weightImpact) * ((i + 1) / analyzeBars)) + (vol * (1.0 - weightImpact))


if doIntersect(intersectionBody ? [Link](open[i], close[i]) : high[i], intersectionBody ?
[Link](open[i], close[i]) : low[i], curRow)

if close[i] > open[i]

[Link] += vol

else

[Link] += vol

[Link] += vol

//

maxVolumeSize := 0

minVolumeSize := [Link](0).totalVolume

rowType maxVolRow = na

for i = 0 to [Link]() - 1

curRow = [Link](i)

maxVolumeSize := [Link](maxVolumeSize, [Link])

if [Link] == maxVolumeSize

maxVolRow := curRow
minVolumeSize := [Link](minVolumeSize, [Link])

int startIndex = na

if alignSetting == "Left"

startIndex := (curIndex - analyzeBars + 1)

if not na(latestEdgeIndex)

startIndex := [Link](startIndex, latestEdgeIndex + edgeOffset)

else

startIndex := (curIndex + 75)

if not na(latestEdgeIndex)

startIndex := [Link](startIndex, latestEdgeIndex + 75)

[Link] := startIndex

for i = 0 to [Link]() - 1

curRow = [Link](i)
[Link]([Link])

[Link]([Link])

[Link]([Link])

renderRow(startIndex, alignSetting == "Left" ? false : true, curRow)

if alignSetting == "Left"

[Link] := [Link](nz([Link], 0),


[Link])

else

[Link] := [Link](nz([Link], 0),


[Link])

if not na(oldLine)

oldLine.set_extend([Link])

if alignSetting == "Left"

oldLine.set_xy2(startIndex, oldLine.get_y2())

else
oldLine.set_xy1(latestEdgeIndex, oldLine.get_y2())

oldLine.set_xy2([Link], oldLine.get_y2())

if not na(oldBox)

oldBox.set_right(startIndex)

[Link]([Link])

[Link]([Link])

if highlightSessions and alignSetting == "Left"

[Link] := [Link](startIndex, [Link],


nz([Link], bar_index), [Link], bgcolor =
[Link]([Link], 80), border_width = 0)

maxRowMid = ([Link] + [Link]) / 2.0

if POCEnabled and [Link] > 0

if alignSetting == "Left"
[Link] := [Link]([Link], maxRowMid, bar_index,
maxRowMid, extend = [Link], width = POCLineWidth, color = POCLineColor, style = POCLineStyle
== "____" ? line.style_solid : POCLineStyle == "----" ? line.style_dashed : line.style_dotted)

else

[Link] := [Link](bar_index, maxRowMid, [Link],


maxRowMid, extend = [Link], width = POCLineWidth, color = POCLineColor, style = POCLineStyle ==
"____" ? line.style_solid : POCLineStyle == "----" ? line.style_dashed : line.style_dotted)

You might also like