Cripton 4test
Cripton 4test
0
International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// © LuxAlgo
//@version=6
indicator('Simple by Criptom4N', overlay = true, max_labels_count = 500,
max_lines_count = 500, max_boxes_count = 500)
// Calculate Supertrend
var float supertrend = na
var float highestHigh = na
var float lowestLow = na
for i = length to 1 by 1
if ta.change(close[i]) > 0
highestHigh := math.max(highestHigh, high[i])
highestHigh
else
lowestLow := math.min(lowestLow, low[i])
lowestLow
BULLISH = +1
BEARISH = -1
GREEN = color.rgb(0, 0, 0)
RED = color.rgb(0, 0, 0)
BLUE = #2157f3
GRAY = #878b94
MONO_BULLISH = #b2b5be
MONO_BEARISH = #5d606b
HISTORICAL = 'Historical'
PRESENT = 'Present'
COLORED = 'Colored'
MONOCHROME = 'Monochrome'
ALL = 'All'
BOS = 'BOS'
CHOCH = 'CHoCH'
TINY = size.tiny
SMALL = size.small
NORMAL = size.normal
ATR = 'Atr'
RANGE = 'Cumulative Mean Range'
CLOSE = 'Close'
HIGHLOW = 'High/Low'
SOLID = '⎯⎯⎯'
DASHED = '----'
DOTTED = '····'
//---------------------------------------------------------------------------------
------------------------------------}
//DATA STRUCTURES & VARIABLES
//---------------------------------------------------------------------------------
------------------------------------{
// @type UDT representing alerts as bool fields
// @field internalBullishBOS internal structure custom alert
// @field internalBearishBOS internal structure custom alert
// @field internalBullishCHoCH internal structure custom alert
// @field internalBearishCHoCH internal structure custom alert
// @field swingBullishBOS swing structure custom alert
// @field swingBearishBOS swing structure custom alert
// @field swingBullishCHoCH swing structure custom alert
// @field swingBearishCHoCH swing structure custom alert
// @field internalBullishOrderBlock internal order block custom alert
// @field internalBearishOrderBlock internal order block custom alert
// @field swingBullishOrderBlock swing order block custom alert
// @field swingBearishOrderBlock swing order block custom alert
// @field equalHighs equal high low custom alert
// @field equalLows equal high low custom alert
// @field bullishFairValueGap fair value gap custom alert
// @field bearishFairValueGap fair value gap custom alert
type alerts
bool internalBullishBOS = false
bool internalBearishBOS = false
bool internalBullishCHoCH = false
bool internalBearishCHoCH = false
bool swingBullishBOS = false
bool swingBearishBOS = false
bool swingBullishCHoCH = false
bool swingBearishCHoCH = false
bool internalBullishOrderBlock = false
bool internalBearishOrderBlock = false
bool swingBullishOrderBlock = false
bool swingBearishOrderBlock = false
bool equalHighs = false
bool equalLows = false
bool bullishFairValueGap = false
bool bearishFairValueGap = false
// we create the needed boxes for displaying order blocks at the first execution
if barstate.isfirst
if showSwingOrderBlocksInput
for index = 1 to swingOrderBlocksSizeInput by 1
swingOrderBlocksBoxes.push(box.new(na, na, na, na, xloc =
xloc.bar_time, extend = extend.right))
if showInternalOrderBlocksInput
for index = 1 to internalOrderBlocksSizeInput by 1
internalOrderBlocksBoxes.push(box.new(na, na, na, na, xloc =
xloc.bar_time, extend = extend.right))
//---------------------------------------------------------------------------------
------------------------------------}
//USER-DEFINED FUNCTIONS
//---------------------------------------------------------------------------------
------------------------------------{
// @function Get the value of the current leg, it can be 0 (bearish) or
1 (bullish)
// @returns int
leg(int size) =>
var leg = 0
newLegHigh = high[size] > ta.highest(size)
newLegLow = low[size] < ta.lowest(size)
if newLegHigh
leg := BEARISH_LEG
leg
else if newLegLow
leg := BULLISH_LEG
leg
leg
if modeInput == PRESENT
l_abel.delete()
if equalHigh
tag := 'EQH'
equalColor := swingBearishColor
labelStyle := label.style_label_down
labelStyle
if modeInput == PRESENT
line.delete(e_qualDisplay.l_ine)
label.delete(e_qualDisplay.l_abel)
// @function store current structure and trailing swing points, and also
display swing points and equal highs/lows
// @param size (int) structure size
// @param equalHighLow (bool) true for displaying current highs/lows
// @param internal (bool) true for getting internal structures
// @returns label ID
getCurrentStructure(int size, bool equalHighLow = false, bool internal = false) =>
currentLeg = leg(size)
newPivot = startOfNewLeg(currentLeg)
pivotLow = startOfBullishLeg(currentLeg)
pivotHigh = startOfBearishLeg(currentLeg)
if newPivot
if pivotLow
pivot p_ivot = equalHighLow ? equalLow : internal ? internalLow :
swingLow
p_ivot.lastLevel := p_ivot.currentLevel
p_ivot.currentLevel := low[size]
p_ivot.crossed := false
p_ivot.barTime := time[size]
p_ivot.barIndex := bar_index[size]
p_ivot.lastLevel := p_ivot.currentLevel
p_ivot.currentLevel := high[size]
p_ivot.crossed := false
p_ivot.barTime := time[size]
p_ivot.barIndex := bar_index[size]
if modeInput == PRESENT
l_ine.delete()
l_abel.delete()
array<float> a_rray = na
int parsedIndex = na
if bias == BEARISH
a_rray := parsedHighs.slice(p_ivot.barIndex, bar_index)
parsedIndex := p_ivot.barIndex + a_rray.indexof(a_rray.max())
parsedIndex
else
a_rray := parsedLows.slice(p_ivot.barIndex, bar_index)
parsedIndex := p_ivot.barIndex + a_rray.indexof(a_rray.min())
parsedIndex
if orderBlocksSize > 0
maxOrderBlocks = internal ? internalOrderBlocksSizeInput :
swingOrderBlocksSizeInput
array<orderBlock> parsedOrdeBlocks = orderBlocks.slice(0,
math.min(maxOrderBlocks, orderBlocksSize))
array<box> b_oxes = internal ? internalOrderBlocksBoxes :
swingOrderBlocksBoxes
// @function detect and draw structures, also detect and store order
blocks
// @param internal true for internal structures or order blocks
// @returns void
displayStructure(bool internal = false) =>
var bullishBar = true
var bearishBar = true
if internalFilterConfluenceInput
bullishBar := high - math.max(close, open) > math.min(close, open - low)
bearishBar := high - math.max(close, open) < math.min(close, open - low)
bearishBar
if internal
currentAlerts.internalBullishCHoCH := tag == CHOCH
currentAlerts.internalBullishBOS := tag == BOS
currentAlerts.internalBullishBOS
else
currentAlerts.swingBullishCHoCH := tag == CHOCH
currentAlerts.swingBullishBOS := tag == BOS
currentAlerts.swingBullishBOS
p_ivot.crossed := true
t_rend.bias := BULLISH
if displayCondition
drawStructure(p_ivot, tag, bullishColor, lineStyle,
label.style_label_down, labelSize)
if internal
currentAlerts.internalBearishCHoCH := tag == CHOCH
currentAlerts.internalBearishBOS := tag == BOS
currentAlerts.internalBearishBOS
else
currentAlerts.swingBearishCHoCH := tag == CHOCH
currentAlerts.swingBearishBOS := tag == BOS
currentAlerts.swingBearishBOS
p_ivot.crossed := true
t_rend.bias := BEARISH
if displayCondition
drawStructure(p_ivot, tag, bearishColor, lineStyle,
label.style_label_up, labelSize)
if bullishFairValueGap
currentAlerts.bullishFairValueGap := true
fairValueGaps.unshift(fairValueGap.new(currentLow, last2High, BULLISH,
fairValueGapBox(lastTime, currentTime, currentLow, math.avg(currentLow, last2High),
fairValueGapBullishColor), fairValueGapBox(lastTime, currentTime,
math.avg(currentLow, last2High), last2High, fairValueGapBullishColor)))
if bearishFairValueGap
currentAlerts.bearishFairValueGap := true
fairValueGaps.unshift(fairValueGap.new(currentHigh, last2Low, BEARISH,
fairValueGapBox(lastTime, currentTime, currentHigh, math.avg(currentHigh,
last2Low), fairValueGapBearishColor), fairValueGapBox(lastTime, currentTime,
math.avg(currentHigh, last2Low), last2Low, fairValueGapBearishColor)))
if not sameTimeframe
int leftIndex = times.binary_search_rightmost(parsedLeftTime)
int rightIndex = times.binary_search_rightmost(parsedRightTime)
var line topLine = line.new(na, na, na, na, xloc = xloc.bar_time, color =
levelColor, style = getStyle(style))
var line bottomLine = line.new(na, na, na, na, xloc = xloc.bar_time, color =
levelColor, style = getStyle(style))
var label topLabel = label.new(na, na, xloc = xloc.bar_time, text =
str.format('P{0}H', timeframe), color = color(na), textcolor = levelColor, size =
size.small, style = label.style_label_left)
var label bottomLabel = label.new(na, na, xloc = xloc.bar_time, text =
str.format('P{0}L', timeframe), color = color(na), textcolor = levelColor, size =
size.small, style = label.style_label_left)
topLine.set_first_point(chart.point.new(trailing.lastTopTime, na,
trailing.top))
topLine.set_second_point(chart.point.new(rightTimeBar, na, trailing.top))
topLabel.set_point(chart.point.new(rightTimeBar, na, trailing.top))
topLabel.set_text(swingTrend.bias == BEARISH ? 'Strong High' : 'Weak High')
bottomLine.set_first_point(chart.point.new(trailing.lastBottomTime, na,
trailing.bottom))
bottomLine.set_second_point(chart.point.new(rightTimeBar, na, trailing.bottom))
bottomLabel.set_point(chart.point.new(rightTimeBar, na, trailing.bottom))
bottomLabel.set_text(swingTrend.bias == BULLISH ? 'Strong Low' : 'Weak Low')
//---------------------------------------------------------------------------------
------------------------------------}
//MUTABLE VARIABLES & EXECUTION
//---------------------------------------------------------------------------------
------------------------------------{
parsedOpen = showTrendInput ? open : na
candleColor = internalTrend.bias == BULLISH ? swingBullishColor : swingBearishColor
plotcandle(parsedOpen, high, low, close, color = candleColor, wickcolor =
candleColor, bordercolor = candleColor)
if showHighLowSwingsInput or showPremiumDiscountZonesInput
updateTrailingExtremes()
if showHighLowSwingsInput
drawHighLowSwings()
if showPremiumDiscountZonesInput
drawPremiumDiscountZones()
if showFairValueGapsInput
deleteFairValueGaps()
getCurrentStructure(swingsLengthInput, false)
getCurrentStructure(5, false, true)
if showEqualHighsLowsInput
getCurrentStructure(equalHighsLowsLengthInput, true)
if showInternalOrderBlocksInput
deleteOrderBlocks(true)
if showSwingOrderBlocksInput
deleteOrderBlocks()
if showFairValueGapsInput
drawFairValueGaps()
if barstate.islastconfirmedhistory or barstate.islast
if showInternalOrderBlocksInput
drawOrderBlocks(true)
if showSwingOrderBlocksInput
drawOrderBlocks()
lastBarIndex := currentBarIndex
currentBarIndex := bar_index
newBar = currentBarIndex != lastBarIndex
//---------------------------------------------------------------------------------
------------------------------------}
//ALERTS
//---------------------------------------------------------------------------------
------------------------------------{
alertcondition(currentAlerts.internalBullishBOS, 'Internal Bullish BOS', 'Internal
Bullish BOS formed')
alertcondition(currentAlerts.internalBullishCHoCH, 'Internal Bullish CHoCH',
'Internal Bullish CHoCH formed')
alertcondition(currentAlerts.internalBearishBOS, 'Internal Bearish BOS', 'Internal
Bearish BOS formed')
alertcondition(currentAlerts.internalBearishCHoCH, 'Internal Bearish CHoCH',
'Internal Bearish CHoCH formed')
//---------------------------------------------------------------------------------
------------------------------------}
Periods = input(title = 'ATR Period', defval = 38)
src2 = input(hl2, title = 'Source')
Multiplier = input.float(title = 'ATR Multiplier', step = 0.1, defval = 12.0)
changeATR = input(title = 'Change ATR Calculation Method ?', defval = true)
showsignals = input(title = 'Show Buy/Sell Signals ?', defval = true)
highlighting = input(title = 'Highlighter On/Off ?', defval = false)
atr2 = ta.sma(ta.tr, Periods)
atr = changeATR ? ta.atr(Periods) : atr2
up = src2 - Multiplier * atr
up1 = nz(up[1], up)
up := close[1] > up1 ? math.max(up, up1) : up
dn = src2 + Multiplier * atr
dn1 = nz(dn[1], dn)
dn := close[1] < dn1 ? math.min(dn, dn1) : dn
trend = 1
trend := nz(trend[1], trend)
trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend
upPlot = plot(trend == 1 ? up : na, title = 'Up Trend', style = plot.style_linebr,
linewidth = 2, color = #4caf4f00)
buySignal = trend == 1 and trend[1] == -1
plotshape(buySignal ? up : na, title = 'UpTrend Begins', location =
location.absolute, style = shape.circle, size = size.tiny, color = #4caf4f00)
plotshape(buySignal and showsignals ? up : na, title = 'Buy', text = 'Buy',
location = location.absolute, style = shape.labelup, size = size.tiny, color =
color.new(color.green, 0), textcolor = color.new(color.white, 0))
dnPlot = plot(trend == 1 ? na : dn, title = 'Down Trend', style =
plot.style_linebr, linewidth = 2, color = #ff525200)
sellSignal = trend == -1 and trend[1] == 1
plotshape(sellSignal ? dn : na, title = 'DownTrend Begins', location =
location.absolute, style = shape.circle, size = size.tiny, color = #ff525200)
plotshape(sellSignal and showsignals ? dn : na, title = 'Sell', text = 'Sell',
location = location.absolute, style = shape.labeldown, size = size.tiny, color =
color.new(color.red, 0), textcolor = color.new(color.white, 0))
mPlot = plot(ohlc4, title = '', style = plot.style_circles, linewidth = math.max(1,
0))
longFillColor = highlighting ? trend == 1 ? #4caf4f00 : #ffffff00 : #ffffff00
shortFillColor = highlighting ? trend == -1 ? #ff525200 : #ffffff00 : #ffffff00
fill(mPlot, upPlot, title = 'UpTrend Highligter', color = longFillColor)
fill(mPlot, dnPlot, title = 'DownTrend Highligter', color = shortFillColor)
alertcondition(buySignal, title = 'Buy', message = 'Buy!')
alertcondition(sellSignal, title = 'Sell', message = 'Sell!')
changeCond = trend != trend[1]
alertcondition(changeCond, title = 'Change Direction', message = 'Change
direction!')