script FRAMA muncul lebih dulu, dengan bentuk bar
// This work is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
// https://creativecommons.org/licenses/by-nc-sa/4.0/
// © BigBeluga (Modified to Real-Time Oscillator / iMACD Style with Candles)
//@version=5
indicator("iFRAMA Oscillator Candles [BigBeluga Mod]", overlay=false, max_labels_count = 500)
// INPUTS --------------------------------------------------------------------------------------------------------{
int N = input.int (26, title="Length", minval=2, step = 2, group = "Channel")
float distance = input.float (1.5, "Bands Distance", step = 0.01, minval = 0.3, group = "Channel")
// Colors
group = "Colors"
color color1 = input.color(#27e27b, "Bullish", group = group, inline = "1")
color color2 = input.color(#f23645, "Bearish", group = group, inline = "1")
color color3 = input.color(#a2b5ca, "Neutral", group = group)
var color current_color = color(na)
// UDTs ----------------------------------------------------------------------------------------------------------------{
type vars
float N1
float N2
float N3
float HH
float LL
float Dimen
float alpha
v = vars.new(0., 0., 0., 0., 0., 0., 0.)
// CALCULATIONS ----------------------------------------------------------------------------------------------{
series float volatility = ta.sma(high - low, 200)
series float price = hl2
// Calculate N3 for the fractal dimension
v.N3 := (ta.highest(high, N) - ta.lowest(low, N)) / N
// Loop to calculate N1
v.HH := high
v.LL := low
for count = 0 to N / 2 - 1
if high[count] > v.HH
v.HH := high[count]
if low[count] < v.LL
v.LL := low[count]
v.N1 := (v.HH - v.LL) / (N / 2)
// Loop to calculate N2
v.HH := high[N / 2]
v.LL := low[N / 2]
for count = N / 2 to N - 1
if high[count] > v.HH
v.HH := high[count]
if low[count] < v.LL
v.LL := low[count]
v.N2 := (v.HH - v.LL) / (N / 2)
// Calculate the fractal dimension & alpha
if (v.N1 > 0 and v.N2 > 0 and v.N3 > 0)
v.Dimen := (math.log(v.N1 + v.N2) - math.log(v.N3)) / math.log(2)
v.alpha := math.exp(-4.6 * (v.Dimen - 1))
v.alpha := math.max(math.min(v.alpha, 1), 0.01)
// Calculate FRAMA
var float Filt = na
Filt := na(Filt) ? price : v.alpha * price + (1 - v.alpha) * Filt[1]
Filt := ta.sma((bar_index < N + 1) ? price : Filt, 5)
// Deklarasi variabel Filt1 & Filt2
float Filt1 = Filt + volatility * distance
float Filt2 = Filt - volatility * distance
// Logika Perubahan Warna Trend REAL-TIME
break_up = ta.crossover(hlc3, Filt1)
break_dn = ta.crossunder(hlc3, Filt2)
if ta.cross(close, Filt)
current_color := color3
switch
break_up => current_color := color1
break_dn => current_color := color2
// OSCILLATOR (iMACD Style) ----------------------------------------------------------------------------------{
macd_line = close - Filt
signal_line = ta.sma(macd_line, 9)
hist = macd_line - signal_line
// Konstruksi Harga Candlestick untuk Oscillator
float c_open = nz(macd_line[1], macd_line)
float c_close = macd_line
float c_high = math.max(c_open, c_close) + math.abs(hist) * 0.5
float c_low = math.min(c_open, c_close) - math.abs(hist) * 0.5
// PLOT -------------------------------------------------------------------------------------------------------------{
// Zero Line
hline(0, "Zero Line", color=color.new(color.gray, 50), linestyle=hline.style_dashed)
// Plot Signal Line sebagai referensi tipis
plot(signal_line, title="Signal Line", color=color.new(color.white, 50), linewidth=1)
// Plot dalam bentuk Candlestick
plotcandle(c_open, c_high, c_low, c_close, title="iFRAMA Candles", color=current_color, wickcolor=current_color, bordercolor=current_color)
Komentar
Posting Komentar