frama ada bulatan 4 buah
// This work is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
// https://creativecommons.org/licenses/by-nc-sa/4.0/
// © BigBeluga (Modified: Ultra Lightweight iFRAMA 4 Circles with Adjusted Labels)
//@version=5
indicator("iFRAMA 4 Circles Ultra Lightweight", overlay=false)
// 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 (Green)", group = group, inline = "1")
color color2 = input.color(#f23645, "Bearish (Red)", group = group, inline = "1")
color color3 = input.color(#FFFFFF, "Neutral (White)", group = group)
// CALCULATIONS ----------------------------------------------------------------------------------------------{
float volatility = ta.sma(high - low, 200)
float price = hl2
float N3 = (ta.highest(high, N) - ta.lowest(low, N)) / N
float HH1 = high
float LL1 = low
for count = 0 to N / 2 - 1
if high[count] > HH1
HH1 := high[count]
if low[count] < LL1
LL1 := low[count]
float N1 = (HH1 - LL1) / (N / 2)
float HH2 = high[N / 2]
float LL2 = low[N / 2]
for count = N / 2 to N - 1
if high[count] > HH2
HH2 := high[count]
if low[count] < LL2
LL2 := low[count]
float N2 = (HH2 - LL2) / (N / 2)
float Dimen = 0.0
if (N1 > 0 and N2 > 0 and N3 > 0)
Dimen := (math.log(N1 + N2) - math.log(N3)) / math.log(2)
float alpha = math.exp(-4.6 * (Dimen - 1))
alpha := math.max(math.min(alpha, 1), 0.01)
var float Filt = na
Filt := na(Filt) ? price : alpha * price + (1 - alpha) * nz(Filt[1], price)
Filt := ta.sma((bar_index < N + 1) ? price : Filt, 3)
// 4 CIRCLES LOGIC --------------------------------------------------------------------------------------------------{
macd_line = close - Filt
signal_line = ta.sma(macd_line, 9)
float neutral_threshold = volatility * 0.08
int elapsed_ms = int(timenow - time)
int total_sec = math.min(60, math.max(0, int(elapsed_ms / 1000)))
bool show_q1 = total_sec >= 0
bool show_q2 = total_sec >= 15
bool show_q3 = total_sec >= 30
bool show_q4 = total_sec >= 45
float live_macd = close - Filt
color live_color = math.abs(live_macd) < neutral_threshold ? color3 : (live_macd > 0 ? color1 : color2)
color raw_q1 = barstate.islast and total_sec < 15 ? live_color : (math.abs(open - Filt) < neutral_threshold ? color3 : (open - Filt > 0 ? color1 : color2))
color raw_q2 = barstate.islast and total_sec < 30 ? live_color : (math.abs(((open+hl2)/2) - Filt) < neutral_threshold ? color3 : (((open+hl2)/2) - Filt > 0 ? color1 : color2))
color raw_q3 = barstate.islast and total_sec < 45 ? live_color : (math.abs(hl2 - Filt) < neutral_threshold ? color3 : (hl2 - Filt > 0 ? color1 : color2))
color raw_q4 = barstate.islast and total_sec < 60 ? live_color : (math.abs(close - Filt) < neutral_threshold ? color3 : (close - Filt > 0 ? color1 : color2))
float spacing = volatility * 0.25
float circle_top = 3 * spacing
float circle_mid1 = 1 * spacing
float circle_mid2 = -1 * spacing
float circle_bottom = -3 * spacing
// PLOT & LABELS ---------------------------------------------------------------------------------------------{
hline(0, "Zero Line", color=color.new(color.gray, 50), linestyle=hline.style_dashed)
plot(signal_line, title="Signal Line", color=color.new(color.white, 50), linewidth=1)
plot(show_q1 ? circle_top : na, title="Circle A", color=raw_q1, style=plot.style_circles, linewidth=4)
plot(show_q2 ? circle_mid1 : na, title="Circle B", color=raw_q2, style=plot.style_circles, linewidth=4)
plot(show_q3 ? circle_mid2 : na, title="Circle C", color=raw_q3, style=plot.style_circles, linewidth=4)
plot(show_q4 ? circle_bottom : na, title="Circle D", color=raw_q4, style=plot.style_circles, linewidth=4)
// Label Keterangan Waktu per Bulat (Digeser lebih jauh ke kanan dengan bar_index + 3)
var label lbl_q1 = label.new(na, na, text="", xloc=xloc.bar_index, yloc=yloc.price, color=color.new(color.black, 100), textcolor=color.white, style=label.style_none)
var label lbl_q2 = label.new(na, na, text="", xloc=xloc.bar_index, yloc=yloc.price, color=color.new(color.black, 100), textcolor=color.white, style=label.style_none)
var label lbl_q3 = label.new(na, na, text="", xloc=xloc.bar_index, yloc=yloc.price, color=color.new(color.black, 100), textcolor=color.white, style=label.style_none)
var label lbl_q4 = label.new(na, na, text="", xloc=xloc.bar_index, yloc=yloc.price, color=color.new(color.black, 100), textcolor=color.white, style=label.style_none)
if barstate.islast
label.set_xy(lbl_q1, bar_index + 3, circle_top)
label.set_text(lbl_q1, " sampai (45s)")
label.set_textcolor(lbl_q1, raw_q1)
label.set_xy(lbl_q2, bar_index + 3, circle_mid1)
label.set_text(lbl_q2, "sampai (30s)")
label.set_textcolor(lbl_q2, raw_q2)
label.set_xy(lbl_q3, bar_index + 3, circle_mid2)
label.set_text(lbl_q3, "sampai (15s)")
label.set_textcolor(lbl_q3, raw_q3)
label.set_xy(lbl_q4, bar_index + 3, circle_bottom)
label.set_text(lbl_q4, "sampai (0s)")
label.set_textcolor(lbl_q4, raw_q4)
Komentar
Posting Komentar