PHP Code:
// This Pine Scriptâ„¢ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © AllanDecker
//@version=5
indicator("Deck@r True Range Index", overlay=true,precision = 2, format = format.price, timeframe = "", timeframe_gaps = true)
// ATR period
atr_period = input.int(14, title="ATR Period")
// ATR multiplier
atr_multiplier = input.float(1.0, title="ATR Multiplier")
// Calculate ATR
atr_value = ta.atr(atr_period)
// Calculate upper and lower bands for ATR Bands
upper_band = ta.sma(close, 20) + (atr_multiplier * atr_value)
lower_band = ta.sma(close, 20) - (atr_multiplier * atr_value)
// Calculate midline at Fibonacci retracement level of 0.75
midline_75 = upper_band - (upper_band - lower_band) * 0.75
// Calculate midline at Fibonacci retracement level of 0.25
midline_25 = upper_band - (upper_band - lower_band) * 0.25
// Plot bands and midlines for ATR Bands
//plot(upper_band, color=color.red, title="Upper Band", style=plot.style_cross)
//plot(lower_band, color=color.red, title="Lower Band", style=plot.style_cross)
//plot(midline_75, color=color.purple, title="Midline 0.75")
//plot(midline_25, color=color.orange, title="Midline 0.25")
// Define buy and sell conditions
buy_condition = close > midline_25
sell_condition = close < midline_75
// Set candle colors
candle_color = buy_condition ? color.blue : sell_condition ? color.red : na
//barcolor(candle_color)
// Check for buy signal (price breaking above midline 0.25 of ATR Bands and CCI line color1 is blue)
buy_signal = ta.crossover(close, midline_25)
// Check for sell signal (price breaking below midline 0.75 of ATR Bands and CCI line color1 is red)
sell_signal = ta.crossunder(close, midline_75)
// Plot buy and sell signals for ATR Bands
plotshape(series=buy_signal, title="Buy Signal ATR", location=location.belowbar, color=color.rgb(41,98,255), style=shape.triangleup, size = size.tiny)
plotshape(series=sell_signal, title="Sell Signal ATR", location=location.abovebar, color=color.rgb(236,64,122), style=shape.triangledown, size = size.tiny)
// Alert conditions for ATR Bands
alertcondition(buy_signal, title="Buy", message="BUY")
alertcondition(sell_signal, title="Sell", message="SELL")
/////
// This Pine Scriptâ„¢ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © BackQuant
//@version=5
// Kalman Filter parameters
series float pricesource = input.source(close, "Kalman Price Source", group = "Calculation")
simple float processNoise = input.float(0.01, title="Process Noise", step = 0.01, group = "Calculation")
simple float measurementNoise = input.float(3.0, title="Measurement Noise", group = "Calculation")
simple int N = input.int(5, title="Filter Order", minval=1, group = "Calculation")
simple bool showkalman = input.bool(true, "Show Filtered Price on chart?", group = "UI Settings")
simple bool paintCandles = input.bool(true, "Paint candles according to Trend?", group = "UI Settings")
var float[] stateEstimate = array.new_float(N, na)
var float[] errorCovariance = array.new_float(N, 100.0)
f_init(series float pricesource) =>
if na(array.get(stateEstimate, 0))
for i = 0 to N-1
array.set(stateEstimate, i, pricesource)
array.set(errorCovariance, i, 1.0)
f_kalman(series float pricesource) =>
// Prediction Step
predictedStateEstimate = array.new_float(N)
predictedErrorCovariance = array.new_float(N)
for i = 0 to N-1
array.set(predictedStateEstimate, i, array.get(stateEstimate, i)) // Simplified prediction
array.set(predictedErrorCovariance, i, array.get(errorCovariance, i) + processNoise)
kalmanGain = array.new_float(N)
for i = 0 to N-1
kg = array.get(predictedErrorCovariance, i) / (array.get(predictedErrorCovariance, i) + measurementNoise)
array.set(kalmanGain, i, kg)
array.set(stateEstimate, i, array.get(predictedStateEstimate, i) + kg * (pricesource - array.get(predictedStateEstimate, i)))
array.set(errorCovariance, i, (1 - kg) * array.get(predictedErrorCovariance, i))
array.get(stateEstimate, 0)
f_init(pricesource)
kalmanFilteredPrice = f_kalman(pricesource)
// Conditional Trend
var Trend = 0
if kalmanFilteredPrice>kalmanFilteredPrice[1]
Trend := 1
if kalmanFilteredPrice<kalmanFilteredPrice[1]
Trend := -1
// Colouring
var barColour = #ffffff
if Trend == 1
barColour := #33ff00
if Trend == -1
barColour := #ff0000
// Plotting
barcolor(paintCandles ? barColour : na)
plot(
showkalman ? kalmanFilteredPrice : na,
"Kalman",
color = color.new(barColour, 40),
linewidth = 4
)
/////////
Yer İmleri