FTKF EMAC [Mattes]

Mattes00 · study · 148 行 · 点赞 434 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=5
////////// MADE BY MATTES /////////
indicator("FTKF EMAC [Mattes]", overlay=true)
 
// Input parameters for Kalman Filter
kalmanProcessNoise = input(0.001, title="Kalman Process Noise", group="Kalman Filtration")
kalmanMeasurementNoise = input(0.01, title="Kalman Measurement Noise", group="Kalman Filtration")
 
// Input parameters for MAs
period1 = input(7, title="MA Period 1", group="EMA inputs")
period2 = input(21, title="MA Period 2", group ="EMA inputs")
 
PlotDema =  input(false, title="Show Both EMAs as confluence?", group="Additional")
ColoredBG = input(true, title = "Color Background?", group = "Additional")
// Function to apply a simple Kalman Filter
kalmanFilter(src) =>
    var float x = na
    var float p = na
    
    // Initialize variables if they're not set
    if na(x)
        x := src
        p := 1.0
 
    // Prediction
    k = p / (p + kalmanMeasurementNoise)  // Kalman Gain
    x := x + k * (src - x)  // Update estimate
    p := (1 - k) * p + kalmanProcessNoise  // Update error covariance
    x
 
// Applying Kalman Filter on the price
filteredPrice = kalmanFilter(close)
 
// Calculate MAs for Fourier approximation
ma1 = ta.ema(filteredPrice, period1)
ma2 = ta.ema(filteredPrice, period2)
 
// Determine the dominant MA
dominantMA = ma1 > ma2 ? ma1 : ma2
 
// Define colors based on trend direction
dominantColor = dominantMA == ma1 ? #00ff08 : #ff0707
 
// Plotting the dominant MA with corresponding colors
plot(dominantMA, color=dominantColor, title="Dominant MA", linewidth=2)
plot(PlotDema ? ma1 : na, color = #b9b9b9, title = "ma1", linewidth = 1)
plot(PlotDema ? ma2 : na, color = #6f6f6f, title = "ma1", linewidth = 1)
 
// Optional: Add background color based on trend direction
bgcolor(ColoredBG ? dominantMA == ma1 ? color.new(color.green, 90) : color.new(color.red, 90) : na)
 
////////// MADE BY MATTES //////////
 
//███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
//███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
//███████████████████████████████████████████████████████████████████████████░███████████████████████████████████████████████████████████████████████████
//███████████████████████████████████████████████████████████████████████████░███████████████████████████████████████████████████████████████████████████
//█████████████████████████████████████████████████████████████████████████░░░███████████████████████████████████████████████████████████████████████████
//███████████████████████████████████████████████████████░░░░░░░░█████████░░░░███░░░▓█████░░░░░░░░███████████████████████████████████████████████████████
//██████████████████████████████████████████████████████░░░░░░░░░░░███████░░░░██░░░█████▒░░░░░░░░░░██████████████████████████████████████████████████████
//████████████████████████████████████████████████████▓░▓█████▓░░░░░░▓█░░░░░░░░░░░░░██░░░░░░██████▓░░████████████████████████████████████████████████████
//████████████████████████████████████████████████████▓░████████▒░░░░▒█░░░░░░░░░░░░░▓▒░░░░▒████████░▒████████████████████████████████████████████████████
//██████████████████████████████████████████████████████░▒█████▒░█▒░░▒█░░░░░░░░░░░░░▓▒░░░█░░█████▓░██████████████████████████████████████████████████████
//████████████████████████████████████████████████████████████░░░░░██░░░░░░░░░░░░░░░░░██░░░░░▓███████████████████████████████████████████████████████████
//█████████████████████████████████████████████████████████▓░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓█████████████████████████████████████████████████████████
//█████████████████████████████████████████████████████████░░░░░░░░░░▒██░░░░░░░░░░░░░░░░░░░░░░░░█████████████████████████████████████████████████████████
//███████████████████████████████████████████████████████▓░░░░░░░░░░░░░░▒█░░░░░░░░░░▒█████░░░░░░░▒███████████████████████████████████████████████████████
//███████████████████████████████████████████████████████▒░░░░░░░░░░░░░░░░█░░░░░████░░░░░░░░░░░░░░███████████████████████████████████████████████████████
//██████████████████████████████████████████████████████▒░░░░░░░░░░▓███░░░░░░░░░░░░░░▓█▓░░░░░░░░░░▒██████████████████████████████████████████████████████
//██████████████████████████████████████████████████████░░░░░░░░█░░░███░██░░░░░░░░░░███░░░█▒░░░░░░░██████████████████████████████████████████████████████
//██████████████████████████████████████████████████████░░░░░░░░█░░░░░░░▓█░░░░░░░█▓░░░░░░░█▒░░░░░░░██████████████████████████████████████████████████████
//██████████████████████████████████████████████████████░░░░░░░░█░░░█░░░░░░░░░░░░░░░░░█░░░█▒░░░░░░░██████████████████████████████████████████████████████
//██████████████████████████████████████████████████░░▒█░░░░░░░░█████▒░░░░░░░░░░░░░░░░█████▒░░░░░░░█▓░░▒█████████████████████████████████████████████████
//█████████████████████████████████████████████░░░▓█████░░░░░░░░██▒░░░░░░░▓░░░░░▓░░░░░░░░██▒░░░░░░░█████▓░░░█████████████████████████████████████████████
//████████████████████████████████████████████░░░▓██████░░░░░░░░██▒░░▒█░░░░░░░░░░░░░▓▒░░░██▒░░░░░░░███████░░░▓███████████████████████████████████████████
//██████████████████████████████████████████░░░░░░░░░████▒░░░░░░████░░░███░░░░░░░███░░░▓███▒░░░░░░████░░░░░░░░░██████████████████████████████████████████
//████████████████████████████████████████▓░░░░░░░░░░░░██▒░░░░░░████░░░░▓█░█████░█▓░░░░▓███▒░░░░░░██▒░░░░░░░░░░░░████████████████████████████████████████
//████████████████████████████████████████▓░░░███░░░░░░░█▒░░░░░░░████▓░░░▓░█████░▒░░░▒████░░░░░░░░█░░░░░░░▓██▒░░░████████████████████████████████████████
//██████████████████████████████████████████░░████████▒░░▒█░░░░░░███████░░░░░░░░░░░███████░░░░░░█▓░░░████████░░██████████████████████████████████████████
//████████████████████████████████████████████████████▓░░░█░░░░░░░▒█████████████████████▓░░░░░░░█▓░░░████████████████████████████████████████████████████
//▒░░░█░▒█████████████████████████████░░██████████████▓░░░██▒░░░░░░█████████████████████▒░░░░░░██▓░░▒██████████████░░█████████████████████████████▓░█▓░░░
//▒░░░▓░████████░░░▒█████████████████░████████▓▒░░░░░▓██░▒▓██░░░░░░░███████████████████░░░░░░░▒█▓▒░██▓░░░░░▓▓████████░▒████████████████▒░░░████████░▓░░░░
//█░░░░▓██████▓███▒░░████████████████░▒█▓████░░░░░░░░░▒███░███▒░░░░▒███████████████████▓░░░░░███▒▓██▓░░░░░░░░░██▓███▒░▓███████████████▒░▒█▓█▓███▓▓▓█░░░░▓
//███▒░░░░░░░░░░░░░░░░█░░█████████████░░░░░░░░░░░░████████████░░███████████████████████████▒░████████████░░░░░░░░░░░░█████████████░░█░░░░░░░░░░░░░░░░░███
//██████▒░░░░░░░░░░░░░█░░░▓██████████████░░░░░░██████████████████░▒█░░░███░░░█░░░███░░░█▓░██████████████████░░░░░░███████████████░░░█░░░░░░░░░░░░░░██████
//███████████████░░░░░█░░░░░██████████████████████░░░█████████████████████░░░░░░░█████████████████████░░░██████████████████████░░░░░█░░░░░███████████████
//█████████████████▓▒▓█░░░░░░░▒█████████████▒░░░░░░░░███████████████████████▒░░▓██████████████████████░░░░░░░░▒█████████████▒░░░░░░░█▓▒▒█████████████████
//████████████████████░░░░░░░░░░███████████░░░░░░░░░░████████████████████████▓████████████████████████░░░░░░░░░░▓██████████░░░░░░░░░░████████████████████
//████████████████████░░░░░░░░░░░░███████░░░░░░░░░░░░█████████████████████████████████████████████████░░░░░░░░░░░░███████░░░░░░░░░░░░▓███████████████████
//██████████████████░░░░░░░░░░░░░░░████▓░░░░░░░░░░░░░█████████████████████████████████████████████████░░░░░░░░░░░░░░████░░░░░░░░░░░░░░░██████████████████
//██████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░████████▒░░░░░▒█████████████████████▒░░░░░░████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██████████████████
//██████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████▓░██████████▒░░░░░░░░░░░░░░░░██████████░▒█████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██████████████████
//███████████████████▓░░░░░░░░░░░░░░░░░░░░░░░░░░░░███████▒░█████████████████████████████████████░░███████░░░░░░░░░░░░░░░░░░░░░░░░░░░░▒███████████████████
//███████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░███████▒░███░░███████████████████████████▒░███░░███████░░░░░░░░░░░░░░░░░░░░░░░░░▓██████████████████████
//████████████████████████▒░░░░░░░░░░░░░░░░░░░░░░████████▒░███░░░░░░░░▓█████▓▓▓██████░░░░░░░░███░░████████░░░░░░░░░░░░░░░░░░░░░░▒████████████████████████
//██████████████████████████░░░░░░░░░░░░░░░░░░░░▒████████▒░█████▒░░░░░░███▓░░░░░████░░░░░░░█████░░████████▓░░░░░░░░░░░░░░░░░░░░██████████████████████████
//█████████████████████████████░░░░░░░░░░░░░░░░████▓░████▒░███████░░░░░░▓█░░░░░░░█▓░░░░░░███████░░████░▒████░░░░░░░░░░░░░░░░█████████████████████████████
//██████████████████████████████░░░░░░░░░░░░░░█████▓░██████░▒████████▒░░▓██░░░░░███░░░████████▓░██████░▒█████░░░░░░░░░░░░░░██████████████████████████████
//████████████████████████████████░░░░░░░░░░███████▓░██████░▒█████████████████████████████████▓░██████░▒███████░░░░░░░░░░████████████████████████████████
//█████████████████████████████████▒▒▒▒▒▒▒▓████████▓░██████░▒█████████████████████████████████▓░██████░▒█████████▒▒▒▒▒▒▒█████████████████████████████████
//█████████████████████████████████████████████████▓░██████▓▒░███████████████████████████████▒░▓██████░▒█████████████████████████████████████████████████
//███████████████████████████████████████████████████░▒█████▒░█████████░▓█████████▓░▓████████░░█████▓░███████████████████████████████████████████████████
//███████████████████████████████████████████████████░▒█████▒░███████▒░░░░███████░░░░░███████░░█████▓░███████████████████████████████████████████████████
//███████████████████████████████████████████████████░▒█████▓░███████▓░░░░███████░░░░▒███████░░█████▓░███████████████████████████████████████████████████
//███████████████████████████████████████████████████░▒███████░░███████████████████████████▒░███████▓░███████████████████████████████████████████████████
//███████████████████████████████████████████████████░▒████████▒░██████████▒░░░░██████████▒░████████▓░███████████████████████████████████████████████████
//███████████████████████████████████████████████████░▒████████▒░██████████░░░░░██████████░░████████▓░███████████████████████████████████████████████████
//███████████████████████████████████████████████████░▒██████████░▒██████████░██████████▒░██████████▓░███████████████████████████████████████████████████
//███████████████████████████████████████████████████░▓███████████▓░███████████████████░▒████████████░▓██████████████████████████████████████████████████
//█████████████████████████████████████████████████▓░████████████████▒░█████████████░░████████████████░▒█████████████████████████████████████████████████
//█████████████████████████████████████████████████▓░█████████████████▓░░░███████░░░▓█████████████████░▒█████████████████████████████████████████████████
//█████████████████████████████████████████████████▓░█████████████████████░░░░░░░█████████████████████░▒█████████████████████████████████████████████████
//█████████████████████████████████████████████████▓░█████████████████████████████████████████████████░▒█████████████████████████████████████████████████
//█████████████████████████████████████████████████▓░█████████████████████████████████████████████████░▒█████████████████████████████████████████████████
//█████████████████████████████████████████████████▓░█████████████████████████████████████████████████░▒█████████████████████████████████████████████████
//█████████████████████████████████████████████████▓░█████████████████████████████████████████████████░▒█████████████████████████████████████████████████
//█████████████████████████████████████████████████▓░█████████████████████████████████████████████████░▒█████████████████████████████████████████████████
//█████████████████████████████████████████████████▓░█████████████████████████████████████████████████░▒█████████████████████████████████████████████████
//████████████████████████████████████████████████░░███████████████████████████████████████████████████░░████████████████████████████████████████████████
//████████████████████████████████████████████████░░███████████████████████████████████████████████████░░████████████████████████████████████████████████
//████████████████████████████████████████████████░░███████████████████████████████████████████████████░░████████████████████████████████████████████████
//████████████████████████████████████████████████░░███████████████████████████████████████████████████░░████████████████████████████████████████████████
//████████████████████████████████████████████████░░███████████████████████████████████████████████████░░████████████████████████████████████████████████
//████████████████████████████████████████████████░░███████████████████████████████████████████████████░░████████████████████████████████████████████████
//████████████████████████████████████████████████░░███████████████████████████████████████████████████░░████████████████████████████████████████████████
//████████████████████████████████████████████████░░███████████████████████████████████████████████████░░████████████████████████████████████████████████
//████████████████████████████████████████████████░░███████████████████████████████████████████████████░░████████████████████████████████████████████████
//████████████████████████████████████████████████░░█████████████████████████████████████████████████████░▒██████████████████████████████████████████████
//████████████████████████████████████████████████░░█████████████████████████████████████████████████████░▒██████████████████████████████████████████████
//██████████████████████████████████████████████▓░███████████████████████████████████████████████████████░▒██████████████████████████████████████████████
//██████████████████████████████████████████████▓░████████████████████████████████████████████████████████▒░█████████████████████████████████████████████
//██████████████████████████████████████████████▓░████████████████████████████████████████████████████████░░█████████████████████████████████████████████
//██████████████████████████████████████████████▓░████████████████████████████████████████████████████████░░█████████████████████████████████████████████
//██████████████████████████████████████████████▓░███░░░░░████████████████████████████████████████████████░░█████████████████████████████████████████████
//██████████████████████████████████████████████▓░█▓░████▓░░░░░░██████████████████████████████████████████░░█████████████████████████████████████████████
//██████████████████████████████████████████████▓░███████████████████▒░░░░░███████████████████████████████░░█████████████████████████████████████████████
//██████████████████████████████████████████████▓░█████████████████████████░░░░░░█████████████████████████░░█████████████████████████████████████████████
//████████████████████████████████████████████████░░░████████████████████████████░░░░░░░░░████████████████░░█████████████████████████████████████████████
//███████████████████████████████████████████████████░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓████████████████▒░░░░░░░░░▒▓▓▓▓▓░░█████████████████████████████████████████████
//██████████████████████████████████████████████████████░░░░░░░░░░░░░░░░░░███████████▒▒▒▒▒███████████░░░░░███████████████████████████████████████████████
//██████████████████████████████████████████████████████████▒░░░░░░░░░░░░░██████████░░░░░░░░░░░░░░███████████████████████████████████████████████████████
//█████████████████████████████████████████████████████████░░░░░░░░░░░░░░░██████████░░░░░░░░░░░░░░░██████████████████████████████████████████████████████
//█████████████████████████████████████████████████████████░░░░░░░░░░░░░▓████████████▒░░░░░░░░░░░░░██████████████████████████████████████████████████████
//████████████████████████████████████████████████████████░░░░░░░░░░░░░░▓████████████▒░░░░░░░░░░░░░░▓████████████████████████████████████████████████████
//███████████████████████████████████████████████████████▒░░░░░░░░░░░░░░▓████████████▒░░░░░░░░░░░░░░░████████████████████████████████████████████████████
//███████████████████████████████████████████████████████▒░░▒█░░░░▒█░░░░▓████████████▒░░░░█▒░░░░█▓░░░████████████████████████████████████████████████████
//███████████████████████████████████████████████████████▓░░▒█░░░░░█░░░░▓████████████▓░░░░█▒░░░░█▓░░▒████████████████████████████████████████████████████
//█████████████████████████████████████████████████████████░▒█░░░░▓█░░░████████████████▒░░█▓░░░░██░██████████████████████████████████████████████████████

← 返回列表