PHP Code:
//@version=5
indicator("*", overlay = true, max_lines_count = 500, max_labels_count = 500, max_bars_back=3000)
timeframe = input.timeframe(defval = 'D', title="Source", tooltip="Must be higher than your chart timeframe\nThis chooses the most recent candle of that timeframe for the olhc levels\nIf the levels look wrong, check the last candle in that timeframe!")
p = input.int(0, 'Display nth Candle', minval=0, maxval = 100, tooltip = "Number of the candle to use, counting backwards, 0 is the current candle, 1 is the previous, etc")
display = input.string("Lines", "Display Style", options=["Lines", "Boxes","None"])
high_level = input.color(defval = color.new(color.green, 25), title="High to Open/Close")
oc_level = input.color(defval = color.new(#d7da4c, 25), title="Open to Close")
low_level = input.color(defval = color.new(color.maroon, 25), title="Open/Close to Low")
markhl = input.bool(defval = true, title="Mark High and Low with â–¼ â–²")
markoc = input.bool(defval = true, title="Mark Open Close with O C")
open_border_style = input.string(line.style_solid, 'Line Style', options=[line.style_solid, line.style_dotted, line.style_dashed])
open_border_width = input.int(1, 'Line Width', minval=0)
extend = input.bool(defval = false, title = "Extend?")
template = input.bool(defval = true, title="Draw Separate OxxC Template")
alerthigh = input.bool(defval = false, title="Alerts when high is crossed?")
alertlow = input.bool(defval = false, title="Alerts when low is crossed?")
alertopen = input.bool(defval = false, title="Alerts when new open price is created?")
extd = (extend == true ? extend.right : extend.none)
ResolutionToSec(res)=>
mins = res == "1" ? 1 :
res == "3" ? 3 :
res == "5" ? 5 :
res == "10" ? 10 :
res == "15" ? 15 :
res == "30" ? 30 :
res == "45" ? 45 :
res == "60" ? 60 :
res == "120" ? 120 :
res == "180" ? 180 :
res == "240" ? 240 :
res == "D" or res == "1D" ? 1440 :
res == "W" or res == "1W" ? 10080 :
res == "M" or res == "1M" ? 43200 :
res == "" ? int(str.tonumber(timeframe.period)) :
str.substring(timeframe.period, 2, 3) == "S" ? int(str.tonumber(str.substring(timeframe.period, 0, 2)))/60 : int(str.tonumber(res))
ms = mins * 60 * 1000
bar = ResolutionToSec(timeframe.period)
get_OHLC_day()=>
highs= high[p]
lows= low[p]
opens= open[p]
closes= close[p]
bartimes= time[p]
[highs, lows, opens, closes, bartimes]
[dhighs, dlows, dopens, dcloses, dbartimes] = request.security(syminfo.tickerid, timeframe, get_OHLC_day(), lookahead = barmerge.lookahead_on)
[dayhighs, daylows, dayopens, daycloses, daybartimes] = request.security(syminfo.tickerid, "1D", get_OHLC_day(), lookahead = barmerge.lookahead_on)
[whighs, wlows, wopens, wcloses, wbartimes] = request.security(syminfo.tickerid, "1W", get_OHLC_day(), lookahead = barmerge.lookahead_on)
ext = 0
if (bar_index == last_bar_index)
sesshigh = 0.0
sesslow = high*10
sesshighx = 0
sesslowx = 0
above = 0.0
below = 0.0
// sess = "0000-0000"
// s = time(timeframe.period, sess, zone)
var bool isTime = false
var label sessionopenlabel = na
var label sessioncloselabel = na
var line template_oc_line = na
var line template_high_line = na
var line template_low_line = na
for x = 0 to 2880
isTime := time[x] >= dbartimes
if (isTime)
if (high[x] > sesshigh)
sesshigh := high[x]
sesshighx := x
if (low[x] < sesslow)
sesslow := low[x]
sesslowx := x
if (markhl == true)
sessionhighlabel = label.new(time[sesshighx], sesshigh, text="â–¼", color=color.white, xloc=xloc.bar_time, style=label.style_none, textcolor=high_level, size=size.small, textalign=text.align_center)
sessionlowlabel = label.new(time[sesslowx], sesslow*0.9999, text="â–²", color=color.white, xloc=xloc.bar_time, style=label.style_none, textcolor=low_level, size=size.small, textalign=text.align_center)
label.delete(sessionhighlabel[1])
label.delete(sessionlowlabel[1])
if (markoc == true)
sessionopenlabel = label.new(time+(bar*2), dopens, text="O", color=color.white, xloc=xloc.bar_time, style=label.style_none, textcolor=oc_level, size=size.small, textalign=text.align_center)
sessioncloselabel = label.new(time+(bar*2), close, text="C", color=color.white, xloc=xloc.bar_time, style=label.style_none, textcolor=oc_level, size=size.small, textalign=text.align_center)
label.delete(sessionopenlabel[1])
label.delete(sessioncloselabel[1])
ext := time
if (display == "Boxes")
open_close_box = box.new(dbartimes, dopens > close ? dopens : close, ext, dopens > close ? close : dopens, color.new(oc_level, 65), extend=extd, xloc=xloc.bar_time, border_width=open_border_width, border_style=open_border_style, bgcolor=oc_level)
high_box = box.new(dbartimes, sesshigh, ext, dopens > close ? dopens : close, color.new(high_level, 65), extend=extd, xloc=xloc.bar_time, border_width=open_border_width, border_style=open_border_style, bgcolor=high_level)
low_box = box.new(dbartimes, dopens > close ? close : dopens, ext, sesslow, color.new(low_level, 65), extend=extd, xloc=xloc.bar_time, border_width=open_border_width, border_style=open_border_style, bgcolor=low_level)
box.delete(open_close_box[1])
box.delete(high_box[1])
box.delete(low_box[1])
else if (display == "Lines")
open_line = line.new(dbartimes, dopens, ext, dopens, extend=extd, xloc=xloc.bar_time, color=oc_level, width=open_border_width, style=open_border_style)
high_line = line.new(dbartimes, sesshigh, ext, sesshigh, extend=extd, xloc=xloc.bar_time, color=high_level, width=open_border_width, style=open_border_style)
low_line = line.new(dbartimes, sesslow, ext, sesslow, extend=extd, xloc=xloc.bar_time, color=low_level, width=open_border_width, style=open_border_style)
close_line = line.new(dbartimes, close, ext, close, extend=extd, xloc=xloc.bar_time, color=oc_level, width=open_border_width, style=open_border_style)
// debug label.new(bar_index, high, text=str.tostring(int(str.tonumber(str.substring(timeframe.period, 0, 2)))))
line.delete(open_line[1])
line.delete(close_line[1])
line.delete(high_line[1])
line.delete(low_line[1])
if (template == true)
mid = 10
template_open_line = line.new(time + (bar * (mid-3)), dopens, time+(bar*mid), dopens, xloc=xloc.bar_time, color=oc_level, width=open_border_width*2, style=line.style_solid)
template_close_line = line.new(time + (bar * mid), close, time+(bar*(mid+3)), close, xloc=xloc.bar_time, color=oc_level, width=open_border_width*2, style=line.style_solid)
template_oc_line = line.new(time + (bar * mid), dopens, time+(bar*mid), close, xloc=xloc.bar_time, color=oc_level, width=open_border_width*2, style=line.style_solid)
template_high_line = line.new(time + (bar * mid), dopens > close ? dopens : close, time+(bar*mid), sesshigh, xloc=xloc.bar_time, color=high_level, width=open_border_width*2, style=line.style_solid)
template_low_line = line.new(time + (bar * mid), dopens > close ? close : dopens, time+(bar*mid), sesslow, xloc=xloc.bar_time, color=low_level, width=open_border_width*2, style=line.style_solid)
line.delete(template_oc_line[1])
line.delete(template_high_line[1])
line.delete(template_low_line[1])
line.delete(template_close_line[1])
line.delete(template_open_line[1])
if (high == sesshigh and alerthigh)
alert("OHLC Price made new High of "+str.tostring(sesshigh), alert.freq_once_per_bar)
if (low == sesslow and alertlow)
alert("OHLC Price made new Low of "+str.tostring(sesslow), alert.freq_once_per_bar)
if (time == dbartimes and alertopen)
alert("New OHLC has been created with Open price "+str.tostring(open), alert.freq_once_per_bar)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © loxx
//@version=5
import loxx/loxxexpandedsourcetypes/4
greencolor = #2DD204
redcolor = #D2042D
fdip(float src, int per, int speedin)=>
float fmax = ta.highest(src, per)
float fmin = ta.lowest(src, per)
float length = 0
float diff = 0
for i = 1 to per - 1
diff := (nz(src[i]) - fmin) / (fmax - fmin)
if i > 0
length += math.sqrt( math.pow(nz(diff[i]) - nz(diff[i + 1]), 2) + (1 / math.pow(per, 2)))
float fdi = 1 + (math.log(length) + math.log(2)) / math.log(2 * per)
float traildim = 1 / (2 - fdi)
float alpha = traildim / 2
int speed = math.round(speedin * alpha)
speed
nonlagma(float src, float len)=>
float cycle = 4.0
float coeff = 3.0 * math.pi
float phase = len - 1.0
int _len = int(len * cycle + phase)
float weight = 0., float alfa = 0., float out = 0.
float[] alphas = array.new_float(_len, 0.)
for k = 0 to _len - 1
float t = 0.
t := k <= phase - 1 ? 1.0 * k / (phase - 1) : 1.0 + (k - phase + 1) * (2.0 * cycle - 1.0) / (cycle * len -1.0)
float beta = math.cos(math.pi * t)
float g = 1.0/(coeff * t + 1)
g := t <= 0.5 ? 1 : g
array.set(alphas, k, g * beta)
weight += array.get(alphas, k)
if (weight > 0)
float sum = 0.
for k = 0 to _len - 1
sum += array.get(alphas, k) * nz(src[k])
out := (sum / weight)
out
smthtype = input.string("Kaufman", "Heikin-Ashi Better Caculation Type", options = ["AMA", "T3", "Kaufman"], group = "Source Settings")
srcin = input.string("Median", "Source", group= "Source Settings",
options =
["Close", "Open", "High", "Low", "Median", "Typical", "Weighted", "Average", "Average Median Body", "Trend Biased", "Trend Biased (Extreme)",
"HA Close", "HA Open", "HA High", "HA Low", "HA Median", "HA Typical", "HA Weighted", "HA Average", "HA Average Median Body", "HA Trend Biased", "HA Trend Biased (Extreme)",
"HAB Close", "HAB Open", "HAB High", "HAB Low", "HAB Median", "HAB Typical", "HAB Weighted", "HAB Average", "HAB Average Median Body", "HAB Trend Biased", "HAB Trend Biased (Extreme)"])
per = input.int(30, "Fractal Period Ingest", group = "Adaptive Settings")
speed = input.int(20, "Speed", group = "Adaptive Settings")
ColorSteps = input.int(50, "Color Period", group = "Adaptive Settings")
colorbars = input.bool(true, "Color bars?", group = "UI Options")
kfl=input.float(0.666, title="* Kaufman's Adaptive MA (KAMA) Only - Fast End", group = "Moving Average Inputs")
ksl=input.float(0.0645, title="* Kaufman's Adaptive MA (KAMA) Only - Slow End", group = "Moving Average Inputs")
amafl = input.int(2, title="* Adaptive Moving Average (AMA) Only - Fast", group = "Moving Average Inputs")
amasl = input.int(30, title="* Adaptive Moving Average (AMA) Only - Slow", group = "Moving Average Inputs")
haclose = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, close)
haopen = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, open)
hahigh = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, high)
halow = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, low)
hamedian = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, hl2)
hatypical = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, hlc3)
haweighted = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, hlcc4)
haaverage = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, ohlc4)
src = switch srcin
"Close" => loxxexpandedsourcetypes.rclose()
"Open" => loxxexpandedsourcetypes.ropen()
"High" => loxxexpandedsourcetypes.rhigh()
"Low" => loxxexpandedsourcetypes.rlow()
"Median" => loxxexpandedsourcetypes.rmedian()
"Typical" => loxxexpandedsourcetypes.rtypical()
"Weighted" => loxxexpandedsourcetypes.rweighted()
"Average" => loxxexpandedsourcetypes.raverage()
"Average Median Body" => loxxexpandedsourcetypes.ravemedbody()
"Trend Biased" => loxxexpandedsourcetypes.rtrendb()
"Trend Biased (Extreme)" => loxxexpandedsourcetypes.rtrendbext()
"HA Close" => loxxexpandedsourcetypes.haclose(haclose)
"HA Open" => loxxexpandedsourcetypes.haopen(haopen)
"HA High" => loxxexpandedsourcetypes.hahigh(hahigh)
"HA Low" => loxxexpandedsourcetypes.halow(halow)
"HA Median" => loxxexpandedsourcetypes.hamedian(hamedian)
"HA Typical" => loxxexpandedsourcetypes.hatypical(hatypical)
"HA Weighted" => loxxexpandedsourcetypes.haweighted(haweighted)
"HA Average" => loxxexpandedsourcetypes.haaverage(haaverage)
"HA Average Median Body" => loxxexpandedsourcetypes.haavemedbody(haclose, haopen)
"HA Trend Biased" => loxxexpandedsourcetypes.hatrendb(haclose, haopen, hahigh, halow)
"HA Trend Biased (Extreme)" => loxxexpandedsourcetypes.hatrendbext(haclose, haopen, hahigh, halow)
"HAB Close" => loxxexpandedsourcetypes.habclose(smthtype, amafl, amasl, kfl, ksl)
"HAB Open" => loxxexpandedsourcetypes.habopen(smthtype, amafl, amasl, kfl, ksl)
"HAB High" => loxxexpandedsourcetypes.habhigh(smthtype, amafl, amasl, kfl, ksl)
"HAB Low" => loxxexpandedsourcetypes.hablow(smthtype, amafl, amasl, kfl, ksl)
"HAB Median" => loxxexpandedsourcetypes.habmedian(smthtype, amafl, amasl, kfl, ksl)
"HAB Typical" => loxxexpandedsourcetypes.habtypical(smthtype, amafl, amasl, kfl, ksl)
"HAB Weighted" => loxxexpandedsourcetypes.habweighted(smthtype, amafl, amasl, kfl, ksl)
"HAB Average" => loxxexpandedsourcetypes.habaverage(smthtype, amafl, amasl, kfl, ksl)
"HAB Average Median Body" => loxxexpandedsourcetypes.habavemedbody(smthtype, amafl, amasl, kfl, ksl)
"HAB Trend Biased" => loxxexpandedsourcetypes.habtrendb(smthtype, amafl, amasl, kfl, ksl)
"HAB Trend Biased (Extreme)" => loxxexpandedsourcetypes.habtrendbext(smthtype, amafl, amasl, kfl, ksl)
=> haclose
len = fdip(src, per, speed)
nonlag = nonlagma(src, len)
min = ta.lowest(nonlag, ColorSteps)
max = ta.highest(nonlag, ColorSteps)
mid = (max + min) / 2
colorBuffer = color.from_gradient(nonlag, min, mid, redcolor, greencolor)
//plot(nonlag, "Adaptive Non-Lag MA", color = colorBuffer, linewidth = 3)
barcolor(colorbars ? colorBuffer : na)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © HasanRifat
//@version=5
look_back = input.int(defval = 20, title = "Candle Lookback")
confirm_in = input.int(defval = 3, title = "Confirm Within")
bull_candle = 0
bear_candle = 0
v_up = false
v_dn = false
var bull_active_candle = false
var bull_active_candle_low = 0.0
var bull_active_candle_high = 0.0
var bull_signal_active = false
var bull_candle_count = 0
var bear_active_candle = false
var bear_active_candle_low = 0.0
var bear_active_candle_high = 0.0
var bear_signal_active = false
var bear_candle_count = 0
for i = 0 to (look_back - 1)
if close < low[i]
bull_candle := bull_candle + 1
if close > high[i]
bear_candle := bear_candle + 1
if bull_candle == (look_back - 1)
bull_active_candle := true
bull_active_candle_low := low
bull_active_candle_high := high
bull_signal_active := false
bull_candle_count := 0
if bull_active_candle == true
bull_candle_count := bull_candle_count + 1
if bear_candle == (look_back - 1)
bear_active_candle := true
bear_active_candle_low := low
bear_active_candle_high := high
bear_signal_active := false
bear_candle_count := 0
if bear_active_candle == true
bear_candle_count := bear_candle_count + 1
if close < bull_active_candle_low
bull_active_candle := false
if close > bear_active_candle_high
bear_active_candle := false
if bull_active_candle == true and close > bull_active_candle_high and bull_signal_active == false and bull_candle_count <= (confirm_in+1) and barstate.isconfirmed
bull_signal_active := true
v_up := true
if bear_active_candle == true and close < bear_active_candle_low and bear_signal_active == false and bear_candle_count <= (confirm_in+1) and barstate.isconfirmed
bear_signal_active := true
v_dn := true
plotshape(v_up, title = "V Up", style = shape.triangleup, location = location.belowbar, color = color.green, size = size.small)
plotshape(v_dn, title = "V Dn", style = shape.triangledown, location = location.abovebar, color = color.red, size = size.small)
alertcondition(v_up, "Bullish Revarsal", "Bullish Revarsal")
alertcondition(v_dn, "Bearish Revarsal", "Bearish Revarsal")
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © jdehorty
// @version=5
// A non-repainting implementation of Nadaraya–Watson Regression using a Rational Quadratic Kernel.
// Settings
src66 = input.source(close, 'Source')
h = input.float(8., 'Lookback Window', minval=3., tooltip='The number of bars used for the estimation. This is a sliding value that represents the most recent historical bars. Recommended range: 3-50')
r = input.float(8., 'Relative Weighting', step=0.25, tooltip='Relative weighting of time frames. As this value approaches zero, the longer time frames will exert more influence on the estimation. As this value approaches infinity, the behavior of the Rational Quadratic Kernel will become identical to the Gaussian kernel. Recommended range: 0.25-25')
x_0 = input.int(25, "Start Regression at Bar", tooltip='Bar index on which to start regression. The first bars of a chart are often highly volatile, and omission of these initial bars often leads to a better overall fit. Recommended range: 5-25')
smoothColors = input.bool(false, "Smooth Colors", tooltip="Uses a crossover based mechanism to determine colors. This often results in less color transitions overall.", inline='1', group='Colors')
lag = input.int(2, "Lag", tooltip="Lag for crossover detection. Lower values result in earlier crossovers. Recommended range: 1-2", inline='1', group='Colors')
size = array.size(array.from(src66)) // size of the data series
// Further Reading:
// The Kernel Cookbook: Advice on Covariance functions. David Duvenaud. Published June 2014.
// Estimation of the bandwidth parameter in Nadaraya-Watson kernel non-parametric regression based on universal threshold level. Ali T, Heyam Abd Al-Majeed Hayawi, Botani I. Published February 26, 2021.
kernel_regression(_src66, _size, _h) =>
float _currentWeight = 0.
float _cumulativeWeight = 0.
for i = 0 to _size + x_0
y = _src66[i]
w = math.pow(1 + (math.pow(i, 2) / ((math.pow(_h, 2) * 2 * r))), -r)
_currentWeight += y*w
_cumulativeWeight += w
_currentWeight / _cumulativeWeight
// Estimations
yhat1 = kernel_regression(src66, size, h)
yhat2 = kernel_regression(src66, size, h-lag)
// Rates of Change
bool wasBearish = yhat1[2] > yhat1[1]
bool wasBullish = yhat1[2] < yhat1[1]
bool isBearish = yhat1[1] > yhat1
bool isBullish = yhat1[1] < yhat1
bool isBearishChange = isBearish and wasBullish
bool isBullishChange = isBullish and wasBearish
// Crossovers
bool isBullishCross = ta.crossover(yhat2, yhat1)
bool isBearishCross = ta.crossunder(yhat2, yhat1)
bool isBullishSmooth = yhat2 > yhat1
bool isBearishSmooth = yhat2 < yhat1
// Colors
color c_bullish = input.color(#3AFF17, 'Bullish Color', group='Colors')
color c_bearish = input.color(#FD1707, 'Bearish Color', group='Colors')
color colorByCross = isBullishSmooth ? c_bullish : c_bearish
color colorByRate = isBullish ? c_bullish : c_bearish
color plotColor = smoothColors ? colorByCross : colorByRate
// Plot
plot(yhat1, "RQKE", color=plotColor, linewidth=1)
// Alert Variables
bool alertBullish = smoothColors ? isBearishCross : isBearishChange
bool alertBearish = smoothColors ? isBullishCross : isBullishChange
// Alerts for Color Changes
alertcondition(condition=alertBullish, title='Bearish Color Change', message='Nadaraya-Watson: {{ticker}} ({{interval}}) turned Bearish â–¼')
alertcondition(condition=alertBearish, title='Bullish Color Change', message='Nadaraya-Watson: {{ticker}} ({{interval}}) turned Bullish â–²')
// Non-Displayed Plot Outputs (i.e., for use in other indicators)
plot(alertBearish ? -1 : alertBullish ? 1 : 0, "Alert Stream", display=display.none)
Yer İmleri