0% found this document useful (0 votes)
4 views19 pages

Bilorie Revised

The document outlines a trading indicator script named 'BILORIE 2.0' which utilizes RSI logic and pivot points to generate buy and sell signals based on user-defined parameters. It includes settings for buffers, colors, and conditions for executing trades, including DCA (Dollar Cost Averaging) and stop-loss mechanisms. The script is designed to be used in a trading platform to assist traders in making informed decisions based on market movements.

Uploaded by

Ali Ahmed
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)
4 views19 pages

Bilorie Revised

The document outlines a trading indicator script named 'BILORIE 2.0' which utilizes RSI logic and pivot points to generate buy and sell signals based on user-defined parameters. It includes settings for buffers, colors, and conditions for executing trades, including DCA (Dollar Cost Averaging) and stop-loss mechanisms. The script is designed to be used in a trading platform to assist traders in making informed decisions based on market movements.

Uploaded by

Ali Ahmed
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

DCA AND SL BUFFER IN PERCETANGES

//@version=6
indicator("BILORIE 2.0", overlay=true, max_lines_count=500)

// =====================
// ===== SETTINGS ======
// =====================

// --- GENERAL
tfInput = [Link]("")
Length = [Link](14)

// 👉 GLOBAL LINE WIDTH


refWidth = [Link](6, "Reference Line Width", minval=1, maxval=10)

// ✅ NEW BUFFERS (PERCENT BASED)


dcaBufferPct = [Link](0.3, "DCA Buffer %", step=0.1)
slBufferPct = [Link](0.2, "SL Buffer %", step=0.1)

// --- SELL SETTINGS


sellArmMin = [Link](73, "Sell Arm Min")
sellTrigMax = [Link](30, "Sell Trigger Max")
sellBgOpacity = [Link](85, "Sell BG Opacity")

sellRsiSlLevel = [Link](51, "Sell RSI SL Level", step=1)


sellRsiSlMinPct = [Link](0.5, "Sell RSI SL Min Distance %", step=0.1)

// --- COLORS
sellLineBlue = [Link]
sellLineYellow = [Link]
sellDcaBg = [Link]
sellDcaText = [Link]
sellSlBg = [Link]
sellSlText = [Link]
sellBgColor = [Link]

// --- BUY SETTINGS


buyArmMax = [Link](30, "Buy Arm Max")
buyTrigMin = [Link](72, "Buy Trigger Min")
buyBgOpacity = [Link](85, "Buy BG Opacity")

buyRsiSlLevel = [Link](49, "Buy RSI SL Level", step=1)


buyRsiSlMinPct = [Link](0.5, "Buy RSI SL Min Distance %", step=0.1)

// --- COLORS
buyLineBlue = [Link]
buyLineYellow = [Link]
buyDcaBg = [Link]
buyDcaText = [Link]
buySlBg = [Link]
buySlText = [Link]
buyBgColor = [Link]

// --- COMMON
left = [Link](10)
right = [Link](10)

// =====================
// ===== RSI LOGIC =====
// =====================

rsiVal = tfInput == "" ? [Link](close, Length) :


[Link]([Link], tfInput, [Link](close, Length))

var bool sellArmed = false


var bool buyArmed = false

if rsiVal >= sellArmMin


sellArmed := true

sellSignal = sellArmed and rsiVal <= sellTrigMax


if sellSignal
sellArmed := false

if rsiVal <= buyArmMax


buyArmed := true

buySignal = buyArmed and rsiVal >= buyTrigMin


if buySignal
buyArmed := false

// =====================
// ===== PIVOTS ========
// =====================

ph = [Link](high, left, right)


pl = [Link](low, left, right)

var line[] supArr = array.new_line()


var float[] supPriceArr = array.new_float()

var line[] resArr = array.new_line()


var float[] resPriceArr = array.new_float()
if not na(pl)
l = [Link](bar_index - right, low[right], bar_index, low[right],
color=[Link])
[Link](supArr, l)
[Link](supPriceArr, low[right])

if not na(ph)
l = [Link](bar_index - right, high[right], bar_index, high[right],
color=[Link])
[Link](resArr, l)
[Link](resPriceArr, high[right])

// =====================
// ===== STATE =========
// =====================

var bool sellActive = false


var bool buyActive = false
var line refLine = na
var float refPrice = na
var bool extendActive = false
var int signalBar = na
var bool dcaDone = false
var bool slDone = false
var bool rsiSlActive = false

// =====================
// ===== SELL LOGIC ====
// =====================

if sellSignal and [Link](supArr) > 1 and [Link](resArr) > 0

sellActive := true
buyActive := false

s1 = [Link](supArr, 0)
s2 = [Link](supArr, 1)
p1 = [Link](supPriceArr, 0)
p2 = [Link](supPriceArr, 1)
r1 = [Link](resArr, 0)

float computedRefPrice = na
if p1 < low
refLine := r1
computedRefPrice := [Link](resPriceArr, 0)
line.set_color(refLine, sellLineBlue)
line.set_width(refLine, refWidth)
else
touched = low <= p1 and high >= p1
if touched
line.set_color(s1, sellLineYellow)
line.set_width(s1, refWidth)
refLine := p2 > p1 ? s2 : s1
computedRefPrice := p2 > p1 ? p2 : p1
else
refLine := s1
computedRefPrice := p1
line.set_color(refLine, sellLineBlue)
line.set_width(refLine, refWidth)

refPrice := computedRefPrice

sellDist = [Link](computedRefPrice - high) / high * 100


rsiSlActive := sellDist >= sellRsiSlMinPct

[Link](bar_index, high, "▼", color=rsiSlActive ? [Link] :


[Link])

extendActive := true
signalBar := bar_index
dcaDone := false
slDone := false

// =====================
// ===== BUY LOGIC =====
// =====================

if buySignal and [Link](resArr) > 1 and [Link](supArr) > 0

buyActive := true
sellActive := false

r1 = [Link](resArr, 0)
r2 = [Link](resArr, 1)
p1 = [Link](resPriceArr, 0)
p2 = [Link](resPriceArr, 1)
s1 = [Link](supArr, 0)

float computedRefPrice = na
if p1 > high
refLine := s1
computedRefPrice := [Link](supPriceArr, 0)
line.set_color(refLine, buyLineBlue)
line.set_width(refLine, refWidth)
else
touched = low <= p1 and high >= p1
if touched
line.set_color(r1, buyLineYellow)
line.set_width(r1, refWidth)
refLine := p2 < p1 ? r2 : r1
computedRefPrice := p2 < p1 ? p2 : p1
else
refLine := r1
computedRefPrice := p1
line.set_color(refLine, buyLineBlue)
line.set_width(refLine, refWidth)

refPrice := computedRefPrice

buyDist = [Link](low - computedRefPrice) / low * 100


rsiSlActive := buyDist >= buyRsiSlMinPct

[Link](bar_index, low, "▲", color=rsiSlActive ? [Link] :


[Link])

extendActive := true
signalBar := bar_index
dcaDone := false
slDone := false

// =====================
// ===== EXTENSION =====
// =====================

if extendActive and not na(refLine)

line.set_x2(refLine, bar_index)

dcaBuffer = refPrice * dcaBufferPct / 100


slBuffer = refPrice * slBufferPct / 100

bars = bar_index - signalBar


valid = bars > 0

// DCA
if (sellActive or buyActive) and valid and not dcaDone and (low <=
refPrice + dcaBuffer and high >= refPrice - dcaBuffer)
[Link](bar_index, sellActive ? high : low, "DCA",
color=[Link], textcolor=[Link])
dcaDone := true

// SL
if valid and not slDone
bodyHigh = [Link](open, close)
bodyLow = [Link](open, close)

crossed = (sellActive and close > refPrice) or (buyActive and close <
refPrice)
inside = bodyHigh <= refPrice + slBuffer and bodyLow >= refPrice -
slBuffer

if crossed and not inside


[Link](bar_index, sellActive ? high : low, "SL",
color=[Link], textcolor=[Link])
slDone := true
extendActive := false
sellActive := false
buyActive := false

if bars >= 99
extendActive := false

// =====================
// ===== BACKGROUND ====
// =====================

bgcolor(
sellActive ? [Link](sellBgColor, sellBgOpacity) :
buyActive ? [Link](buyBgColor, buyBgOpacity) :
na
)

Final bilorie

//@version=6
indicator("BILORIE 2.0", overlay=true, max_lines_count=500)

// =====================
// ===== SETTINGS ======
// =====================

// --- GENERAL
tfInput = [Link]("")
Length = [Link](14)

// 👉 GLOBAL LINE WIDTH


refWidth = [Link](6, "Reference Line Width", minval=1, maxval=10)
// ✅ BUFFERS (PERCENT BASED)
dcaBufferPct = [Link](0.3, "DCA Buffer %", step=0.1)
slBufferPct = [Link](0.2, "SL Buffer %", step=0.1)

// ✅ NEW: DCA Arm Distance % — price must move this far away first before DCA
can fire
dcaArmPct = [Link](0.3, "DCA Arm Distance %", step=0.1, tooltip="Price
must move this % away from reference line after signal before DCA is allowed
to fire on retrace.")

// --- SELL SETTINGS


sellArmMin = [Link](73, "Sell Arm Min")
sellTrigMax = [Link](30, "Sell Trigger Max")
sellBgOpacity = [Link](85, "Sell BG Opacity")

sellRsiSlLevel = [Link](51, "Sell RSI SL Level", step=1)


sellRsiSlMinPct = [Link](0.5, "Sell RSI SL Min Distance %", step=0.1)

// --- COLORS
sellLineBlue = [Link]
sellLineYellow = [Link]
sellDcaBg = [Link]
sellDcaText = [Link]
sellSlBg = [Link]
sellSlText = [Link]
sellBgColor = [Link]

// --- BUY SETTINGS


buyArmMax = [Link](30, "Buy Arm Max")
buyTrigMin = [Link](72, "Buy Trigger Min")
buyBgOpacity = [Link](85, "Buy BG Opacity")

buyRsiSlLevel = [Link](49, "Buy RSI SL Level", step=1)


buyRsiSlMinPct = [Link](0.5, "Buy RSI SL Min Distance %", step=0.1)

// --- COLORS
buyLineBlue = [Link]
buyLineYellow = [Link]
buyDcaBg = [Link]
buyDcaText = [Link]
buySlBg = [Link]
buySlText = [Link]
buyBgColor = [Link]

// --- COMMON
left = [Link](10)
right = [Link](10)
// =====================
// ===== RSI LOGIC =====
// =====================

rsiVal = tfInput == "" ? [Link](close, Length) :


[Link]([Link], tfInput, [Link](close, Length))

var bool sellArmed = false


var bool buyArmed = false

if rsiVal >= sellArmMin


sellArmed := true

sellSignal = sellArmed and rsiVal <= sellTrigMax


if sellSignal
sellArmed := false

if rsiVal <= buyArmMax


buyArmed := true

buySignal = buyArmed and rsiVal >= buyTrigMin


if buySignal
buyArmed := false

// =====================
// ===== PIVOTS ========
// =====================

ph = [Link](high, left, right)


pl = [Link](low, left, right)

var line[] supArr = array.new_line()


var float[] supPriceArr = array.new_float()

var line[] resArr = array.new_line()


var float[] resPriceArr = array.new_float()

if not na(pl)
l = [Link](bar_index - right, low[right], bar_index, low[right],
color=[Link])
[Link](supArr, l)
[Link](supPriceArr, low[right])

if not na(ph)
l = [Link](bar_index - right, high[right], bar_index, high[right],
color=[Link])
[Link](resArr, l)
[Link](resPriceArr, high[right])
// =====================
// ===== STATE =========
// =====================

var bool sellActive = false


var bool buyActive = false
var line refLine = na
var float refPrice = na
var bool extendActive = false
var int signalBar = na
var bool dcaDone = false
var bool slDone = false
var bool rsiSlActive = false
var bool dcaArmed = false // ✅ NEW: becomes true once price moves away
enough

// =====================
// ===== SELL LOGIC ====
// =====================

if sellSignal and [Link](supArr) > 1 and [Link](resArr) > 0

sellActive := true
buyActive := false

s1 = [Link](supArr, 0)
s2 = [Link](supArr, 1)
p1 = [Link](supPriceArr, 0)
p2 = [Link](supPriceArr, 1)
r1 = [Link](resArr, 0)

float computedRefPrice = na
if p1 < low
refLine := r1
computedRefPrice := [Link](resPriceArr, 0)
line.set_color(refLine, sellLineBlue)
line.set_width(refLine, refWidth)
else
touched = low <= p1 and high >= p1
if touched
line.set_color(s1, sellLineYellow)
line.set_width(s1, refWidth)
refLine := p2 > p1 ? s2 : s1
computedRefPrice := p2 > p1 ? p2 : p1
else
refLine := s1
computedRefPrice := p1
line.set_color(refLine, sellLineBlue)
line.set_width(refLine, refWidth)

refPrice := computedRefPrice

sellDist = [Link](computedRefPrice - high) / high * 100


rsiSlActive := sellDist >= sellRsiSlMinPct

[Link](bar_index, high, "▼", color=rsiSlActive ? [Link] :


[Link])

extendActive := true
signalBar := bar_index
dcaDone := false
slDone := false
dcaArmed := false // ✅ reset on new signal

// =====================
// ===== BUY LOGIC =====
// =====================

if buySignal and [Link](resArr) > 1 and [Link](supArr) > 0

buyActive := true
sellActive := false

r1 = [Link](resArr, 0)
r2 = [Link](resArr, 1)
p1 = [Link](resPriceArr, 0)
p2 = [Link](resPriceArr, 1)
s1 = [Link](supArr, 0)

float computedRefPrice = na
if p1 > high
refLine := s1
computedRefPrice := [Link](supPriceArr, 0)
line.set_color(refLine, buyLineBlue)
line.set_width(refLine, refWidth)
else
touched = low <= p1 and high >= p1
if touched
line.set_color(r1, buyLineYellow)
line.set_width(r1, refWidth)
refLine := p2 < p1 ? r2 : r1
computedRefPrice := p2 < p1 ? p2 : p1
else
refLine := r1
computedRefPrice := p1
line.set_color(refLine, buyLineBlue)
line.set_width(refLine, refWidth)

refPrice := computedRefPrice

buyDist = [Link](low - computedRefPrice) / low * 100


rsiSlActive := buyDist >= buyRsiSlMinPct

[Link](bar_index, low, "▲", color=rsiSlActive ? [Link] :


[Link])

extendActive := true
signalBar := bar_index
dcaDone := false
slDone := false
dcaArmed := false // ✅ reset on new signal

// =====================
// ===== EXTENSION =====
// =====================

if extendActive and not na(refLine)

line.set_x2(refLine, bar_index)

dcaBuffer = refPrice * dcaBufferPct / 100


slBuffer = refPrice * slBufferPct / 100
dcaArmDist = refPrice * dcaArmPct / 100

bars = bar_index - signalBar


valid = bars > 0

// ✅ ARM the DCA: price must move away from refPrice first
// Sell: price drops below refPrice - dcaArmDist
// Buy: price rises above refPrice + dcaArmDist
if not dcaArmed
if sellActive and low < refPrice - dcaArmDist
dcaArmed := true
if buyActive and high > refPrice + dcaArmDist
dcaArmed := true

// ✅ RSI SL — only fires if yellow signal (rsiSlActive = true)


if valid and not slDone and rsiSlActive
if sellActive and rsiVal >= sellRsiSlLevel
[Link](bar_index, high, "SL", color=sellSlBg,
textcolor=sellSlText)
slDone := true
extendActive := false
sellActive := false
buyActive := false
rsiSlActive := false

if buyActive and rsiVal <= buyRsiSlLevel


[Link](bar_index, low, "SL", color=buySlBg,
textcolor=buySlText)
slDone := true
extendActive := false
sellActive := false
buyActive := false
rsiSlActive := false

// DCA — only fires if dcaArmed = true


if (sellActive or buyActive) and valid and not dcaDone and dcaArmed and
(low <= refPrice + dcaBuffer and high >= refPrice - dcaBuffer)
[Link](bar_index, sellActive ? high : low, "DCA",
color=[Link], textcolor=[Link])
dcaDone := true

// SL — reference line cross


if valid and not slDone
bodyHigh = [Link](open, close)
bodyLow = [Link](open, close)

crossed = (sellActive and close > refPrice) or (buyActive and close <
refPrice)
inside = bodyHigh <= refPrice + slBuffer and bodyLow >= refPrice -
slBuffer

if crossed and not inside


[Link](bar_index, sellActive ? high : low, "SL",
color=[Link], textcolor=[Link])
slDone := true
extendActive := false
sellActive := false
buyActive := false
rsiSlActive := false

if bars >= 99
extendActive := false
rsiSlActive := false

// =====================
// ===== BACKGROUND ====
// =====================

bgcolor(
sellActive ? [Link](sellBgColor, sellBgOpacity) :
buyActive ? [Link](buyBgColor, buyBgOpacity) :
na
)

Fnal lbilorie

//@version=6
indicator("BILORIE 2.0", overlay=true, max_lines_count=500)

// =====================
// ===== SETTINGS ======
// =====================

// --- GENERAL
tfInput = [Link]("")
Length = [Link](14)

// 👉 GLOBAL LINE WIDTH


refWidth = [Link](6, "Reference Line Width", minval=1, maxval=10)

// ✅ BUFFERS (PERCENT BASED)


dcaBufferPct = [Link](0.3, "DCA Buffer %", step=0.1)
slBufferPct = [Link](0.2, "SL Buffer %", step=0.1)

// ✅ NEW: DCA Arm Distance % — price must move this far away first before DCA
can fire
dcaArmPct = [Link](0.3, "DCA Arm Distance %", step=0.1, tooltip="Price
must move this % away from reference line after signal before DCA is allowed
to fire on retrace.")

// --- SELL SETTINGS


sellArmMin = [Link](73, "Sell Arm Min")
sellTrigMax = [Link](30, "Sell Trigger Max")
sellBgOpacity = [Link](85, "Sell BG Opacity")

sellRsiSlLevel = [Link](51, "Sell RSI SL Level", step=1)


sellRsiSlMinPct = [Link](0.5, "Sell RSI SL Min Distance %", step=0.1)

// --- COLORS
sellLineBlue = [Link]
sellLineYellow = [Link]
sellDcaBg = [Link]
sellDcaText = [Link]
sellSlBg = [Link]
sellSlText = [Link]
sellBgColor = [Link]

// --- BUY SETTINGS


buyArmMax = [Link](30, "Buy Arm Max")
buyTrigMin = [Link](72, "Buy Trigger Min")
buyBgOpacity = [Link](85, "Buy BG Opacity")

buyRsiSlLevel = [Link](49, "Buy RSI SL Level", step=1)


buyRsiSlMinPct = [Link](0.5, "Buy RSI SL Min Distance %", step=0.1)

// --- COLORS
buyLineBlue = [Link]
buyLineYellow = [Link]
buyDcaBg = [Link]
buyDcaText = [Link]
buySlBg = [Link]
buySlText = [Link]
buyBgColor = [Link]

// --- COMMON
left = [Link](10)
right = [Link](10)

// =====================
// ===== RSI LOGIC =====
// =====================

rsiVal = tfInput == "" ? [Link](close, Length) :


[Link]([Link], tfInput, [Link](close, Length))

var bool sellArmed = false


var bool buyArmed = false

if rsiVal >= sellArmMin


sellArmed := true

sellSignal = sellArmed and rsiVal <= sellTrigMax


if sellSignal
sellArmed := false

if rsiVal <= buyArmMax


buyArmed := true

buySignal = buyArmed and rsiVal >= buyTrigMin


if buySignal
buyArmed := false

// =====================
// ===== PIVOTS ========
// =====================

ph = [Link](high, left, right)


pl = [Link](low, left, right)

var line[] supArr = array.new_line()


var float[] supPriceArr = array.new_float()

var line[] resArr = array.new_line()


var float[] resPriceArr = array.new_float()

if not na(pl)
l = [Link](bar_index - right, low[right], bar_index, low[right],
color=[Link])
[Link](supArr, l)
[Link](supPriceArr, low[right])

if not na(ph)
l = [Link](bar_index - right, high[right], bar_index, high[right],
color=[Link])
[Link](resArr, l)
[Link](resPriceArr, high[right])

// =====================
// ===== STATE =========
// =====================

var bool sellActive = false


var bool buyActive = false
var line refLine = na
var float refPrice = na
var bool extendActive = false
var int signalBar = na
var bool dcaDone = false
var bool slDone = false
var bool rsiSlActive = false
var bool dcaArmed = false // ✅ NEW: becomes true once price moves away
enough

// =====================
// ===== SELL LOGIC ====
// =====================

if sellSignal and [Link](supArr) > 1 and [Link](resArr) > 0

sellActive := true
buyActive := false
s1 = [Link](supArr, 0)
s2 = [Link](supArr, 1)
p1 = [Link](supPriceArr, 0)
p2 = [Link](supPriceArr, 1)
r1 = [Link](resArr, 0)

float computedRefPrice = na
if p1 < low
refLine := r1
computedRefPrice := [Link](resPriceArr, 0)
line.set_color(refLine, sellLineBlue)
line.set_width(refLine, refWidth)
else
touched = low <= p1 and high >= p1
if touched
line.set_color(s1, sellLineYellow)
line.set_width(s1, refWidth)
refLine := p2 > p1 ? s2 : s1
computedRefPrice := p2 > p1 ? p2 : p1
else
refLine := s1
computedRefPrice := p1
line.set_color(refLine, sellLineBlue)
line.set_width(refLine, refWidth)

refPrice := computedRefPrice

sellDist = [Link](computedRefPrice - high) / high * 100


rsiSlActive := sellDist >= sellRsiSlMinPct

[Link](bar_index, high, "▼", color=rsiSlActive ? [Link] :


[Link])

extendActive := true
signalBar := bar_index
dcaDone := false
slDone := false
dcaArmed := false // ✅ reset on new signal

// =====================
// ===== BUY LOGIC =====
// =====================

if buySignal and [Link](resArr) > 1 and [Link](supArr) > 0

buyActive := true
sellActive := false
r1 = [Link](resArr, 0)
r2 = [Link](resArr, 1)
p1 = [Link](resPriceArr, 0)
p2 = [Link](resPriceArr, 1)
s1 = [Link](supArr, 0)

float computedRefPrice = na
if p1 > high
refLine := s1
computedRefPrice := [Link](supPriceArr, 0)
line.set_color(refLine, buyLineBlue)
line.set_width(refLine, refWidth)
else
touched = low <= p1 and high >= p1
if touched
line.set_color(r1, buyLineYellow)
line.set_width(r1, refWidth)
refLine := p2 < p1 ? r2 : r1
computedRefPrice := p2 < p1 ? p2 : p1
else
refLine := r1
computedRefPrice := p1
line.set_color(refLine, buyLineBlue)
line.set_width(refLine, refWidth)

refPrice := computedRefPrice

buyDist = [Link](low - computedRefPrice) / low * 100


rsiSlActive := buyDist >= buyRsiSlMinPct

[Link](bar_index, low, "▲", color=rsiSlActive ? [Link] :


[Link])

extendActive := true
signalBar := bar_index
dcaDone := false
slDone := false
dcaArmed := false // ✅ reset on new signal

// =====================
// ===== EXTENSION =====
// =====================

if extendActive and not na(refLine)

line.set_x2(refLine, bar_index)
dcaBuffer = refPrice * dcaBufferPct / 100
slBuffer = refPrice * slBufferPct / 100
dcaArmDist = refPrice * dcaArmPct / 100

bars = bar_index - signalBar


valid = bars > 0

// ✅ ARM the DCA: price must move away from refPrice first
// Sell: price drops below refPrice - dcaArmDist
// Buy: price rises above refPrice + dcaArmDist
if not dcaArmed
if sellActive and low < refPrice - dcaArmDist
dcaArmed := true
if buyActive and high > refPrice + dcaArmDist
dcaArmed := true

// ✅ RSI SL — only fires if yellow signal (rsiSlActive = true)


if valid and not slDone and rsiSlActive
if sellActive and rsiVal >= sellRsiSlLevel
[Link](bar_index, high, "SL", color=sellSlBg,
textcolor=sellSlText)
slDone := true
extendActive := false
sellActive := false
buyActive := false
rsiSlActive := false

if buyActive and rsiVal <= buyRsiSlLevel


[Link](bar_index, low, "SL", color=buySlBg,
textcolor=buySlText)
slDone := true
extendActive := false
sellActive := false
buyActive := false
rsiSlActive := false

// DCA — only fires if dcaArmed = true


if (sellActive or buyActive) and valid and not dcaDone and dcaArmed and
(low <= refPrice + dcaBuffer and high >= refPrice - dcaBuffer)
[Link](bar_index, sellActive ? high : low, "DCA",
color=[Link], textcolor=[Link])
dcaDone := true

// SL — reference line cross


if valid and not slDone
bodyHigh = [Link](open, close)
bodyLow = [Link](open, close)
crossed = (sellActive and close > refPrice) or (buyActive and close <
refPrice)
inside = bodyHigh <= refPrice + slBuffer and bodyLow >= refPrice -
slBuffer

if crossed and not inside


[Link](bar_index, sellActive ? high : low, "SL",
color=[Link], textcolor=[Link])
slDone := true
extendActive := false
sellActive := false
buyActive := false
rsiSlActive := false

if bars >= 99
extendActive := false
rsiSlActive := false

// =====================
// ===== BACKGROUND ====
// =====================

bgcolor(
sellActive ? [Link](sellBgColor, sellBgOpacity) :
buyActive ? [Link](buyBgColor, buyBgOpacity) :
na
)

You might also like