Creator Message: https://www.tradingview.com/script/SoKhpII2-kirill-channel/
This indicator shows overbought and oversold zones. Can be used on all time frames. Indicator creator use 15m - 30m.
CSS:
#// © GASANOV_KIRILL
#// v 2.0.1
#https://www.tradingview.com/v/SoKhpII2/
#indicator(title='Kirill Channel', shorttitle='KiC', overlay=true)
# Converted and mod by Sam4Cok@Samer800 - 03/2023
input show_label = no; # "Show difference"
input ShowCloud = yes;
input ShowBand1 = yes;
input ShowBand2 = yes;
input ShowBand3 = yes;
input Fibonacci_Keltner_Band = no;
#// alma
input alma_source = close;
input alma_period = 200; # 'Window Size'
input alma_offset = 0.80; # 'Offset'
input alma_sigma = 5.5; # 'Sigma'
input FirstBorderOffset = 4; # 'First border offset'
input SecondBorderOffsetPercent = 0.7; # 'Second border offset (%)'
input ThirdBorderOffsetPercent = 1.4; # 'Third border offset (%)'
#// keltner
input kc_period = 100; # 'Keltner period'
input kc_mult = 4; # 'Keltner mult.'
input kc_atr_period = 50; # 'Keltner atr period'
input kc_ma_period = 70; # 'Keltner ma period'
#// fibonacci
input fib_ma_period = 25; # 'Fibonacci ma period'
input fib_atr_period = 25; # 'Fibonacci atr period'
input fib_ratio_mult = 3.5; # 'Fibonacci ration'
input fib_smooth_period = 100; # 'Fibonacci smooth period'
input border_kc_lerp = 0.95; # 'Border kc lerp'
input border_fib_lerp = 0.45; # 'Border fib lerp'
#//PROPERTIES -----------------------------------------------------
def na = Double.NaN;
def get_kc_lerp = border_kc_lerp;
def border_second = SecondBorderOffsetPercent;
def border_third = ThirdBorderOffsetPercent;
def band = Fibonacci_Keltner_Band;
#---- Color
DefineGlobalColor("Trend", CreateColor(255,102,255));
DefineGlobalColor("Top0" , CreateColor(68,61,0));
DefineGlobalColor("Top1" , CreateColor(127,114,0));
DefineGlobalColor("Top2" , CreateColor(186,167,0));
DefineGlobalColor("Top3" , CreateColor(245,220,0));
DefineGlobalColor("Btm0" , CreateColor(4,30,75));
DefineGlobalColor("Btm1" , CreateColor(6,52,131));
DefineGlobalColor("Btm2" , CreateColor(9,75,187));
DefineGlobalColor("Btm3" , CreateColor(12,97,243));
DefineGlobalColor("maroon", CreateColor(136,14,79));
DefineGlobalColor("orange", CreateColor(255,152,0));
DefineGlobalColor("green" , CreateColor(76,175,80));
DefineGlobalColor("red" , CreateColor(255,82,82));
#// FUNCTIONS -------------------------------------------------------------------
#pine_alma(series, windowsize, offset, sigma) =>
Script alma_template {
input series = close;
input windowsize = 9;
input offset = 0.8;
input sigma = 5.5;
def m = offset * (windowsize - 1);
def s = windowsize / sigma;
def norm;
def sum;
norm = fold i = 0 to windowsize with p do
p + exp(-1 * power(i - m, 2) / (2 * power(s, 2)));
sum = fold i1 = 0 to windowsize with p1 do
p1 + GetValue(series, windowsize - i1 - 1) * exp(-1 * power(i1 - m, 2) / (2 * power(s, 2)));
def pine_alma = sum / norm;
plot out = pine_alma;
}
#// percent difference from base value to other value
#do_percent_diff(base_value, other_value) =>
script do_percent_diff {
input base_value = high;
input other_value = low;
def do_percent_diff = ((other_value * 100) / base_value) - 100;
plot out = do_percent_diff;
}
#// create new coord for line based on percentage
#do_offset_line(main_line, percent) =>
script do_offset_line {
input main_line = close;
input percent = 1;
def do_percent = percent / 100;
def do_offset_line = main_line * (1 + do_percent);
plot out = do_offset_line;
}
#// interpolates values
#do_lerp(value_a, value_b, t) =>
script do_lerp {
input value_a = high;
input value_b = low;
input t = 0;
def do_lerp = (1 - t) * value_a + t * value_b;
plot out = do_lerp;
}
#// normalize value between range min-max
#do_normalize(min, max, value) =>
script do_normalize {
input min = 0;
input max = 100;
input value = close;
def do_normalize = (value - min) / (max - min);
plot out = do_normalize;
}
#// MAIN ------------------------------------------------
#// Fibonacci
def fib_ma = ExpAverage(close, fib_ma_period);
def fib_tr1 = Max(high - low, AbsValue(high - close[1]));
def fib_tr = Max(fib_tr1, AbsValue(low - close[1]));
def fib_atr = Average(fib_tr, fib_atr_period);
#// green or red
def fib_ratio = fib_atr * fib_ratio_mult;
def fib_top = fib_ma + (fib_ratio);
def fib_bottom = fib_ma - (fib_ratio);
def fib_top_smoothed = HullMovingAvg(fib_top, fib_smooth_period);
def fib_bottom_smoothed = HullMovingAvg(fib_bottom, fib_smooth_period);
#// Keltner channel
def kc_ma = ExpAverage(alma_source, kc_period);
def kc_range_ma = ATR(LENGTH=kc_atr_period);
def kc_top = kc_ma + kc_range_ma * kc_mult;
def kc_bottom = kc_ma - kc_range_ma * kc_mult;
#// Ma based on kc_top/bottom and hma
def kc_top_ma = HullMovingAvg(kc_top, kc_ma_period);
def kc_bottom_ma = HullMovingAvg(kc_bottom, kc_ma_period);
#// Main trend line
def alma_main = alma_template(alma_source, alma_period);
#// Calculate alma borders (top,bottom)
def alma_top_raw = do_offset_line(alma_main, FirstBorderOffset);
def alma_bottom_raw = do_offset_line(alma_main, -FirstBorderOffset);
#// Lerp borders with kc
def kc_lerp = get_kc_lerp;
def _alma_top = alma_top_raw;
def _alma_bottom = alma_bottom_raw;
#// kc lerp
def alma_top1 = do_lerp(_alma_top, kc_top_ma, kc_lerp);
def alma_bottom1 = do_lerp(_alma_bottom, kc_bottom_ma, kc_lerp);
#// Second pass ------------------------------------------------------------------
#// price calculations
def normalized_price_top1 = do_normalize(alma_main, alma_top1, close);
def normalized_price_btm1 = 1 - do_normalize(alma_bottom1, alma_main, close);
def normalized_price_top = if normalized_price_top1 < 1 then 0 else normalized_price_top1;
def normalized_price_bottom = if normalized_price_btm1 < 1 then 0 else normalized_price_btm1;
#// fibonacci lerp values
def fib_lerp_top = normalized_price_top * border_fib_lerp;
def fib_lerp_bottom = normalized_price_bottom * border_fib_lerp;
#// apply fibonacci to border
def alma_top0 = do_lerp(alma_top1, fib_top_smoothed, border_fib_lerp);
def alma_bottom0 = do_lerp(alma_bottom1, fib_bottom_smoothed, border_fib_lerp);
#// construct additional border layers
def alma_top2 = do_offset_line(alma_top0, border_second);
def alma_top3 = do_offset_line(alma_top0, border_third);
def alma_bottom2 = do_offset_line(alma_bottom0, -border_second);
def alma_bottom3 = do_offset_line(alma_bottom0, -border_third);
#// THIRD PASS ------------------------------------------------
#// Percent from main line.
def normalized_price_top_for = do_normalize(alma_bottom0, alma_top0, close);
#// clamp normalized value
def normalized_price_top_for_diff = ExpAverage(if normalized_price_top_for < 0 then 0 else
if normalized_price_top_for > 1 then 1 else normalized_price_top_for, kc_period);
def normalized_price_bottom_for_diff = 1 - normalized_price_top_for_diff;
def difference_percent_top = do_percent_diff(alma_main, alma_top2);
def difference_percent_bottom = do_percent_diff(alma_main, alma_bottom2);
def difference_percent_overall = difference_percent_top - difference_percent_bottom;
def mult_diff_overall = if difference_percent_overall / 10 < 1 then 1 else difference_percent_overall / 10;
def additional_percent_offset_top = normalized_price_top_for_diff * ((difference_percent_top / 10) * mult_diff_overall);
def additional_percent_offset_bottom = normalized_price_bottom_for_diff * ((difference_percent_bottom / 10) * mult_diff_overall);
def border_second_offset_top = border_second + additional_percent_offset_top / 2;
def border_third_offset_top = border_third + additional_percent_offset_top;
def border_second_offset_bottom = -border_second + additional_percent_offset_bottom / 2;
def border_third_offset_bottom = -border_third + additional_percent_offset_bottom;
#// calculate new alma borders
def alma_top = ExpAverage(alma_top0, 9);
def alma_top_2 = do_offset_line(alma_top, border_second_offset_top);
def alma_top_3 = do_offset_line(alma_top, border_third_offset_top);
def alma_bottom = alma_bottom0;
def alma_bottom_2 = do_offset_line(alma_bottom, border_second_offset_bottom);
def alma_bottom_3 = do_offset_line(alma_bottom, border_third_offset_bottom);
#// PLOT --------------------------------------
#//main lines
plot TrendLine = alma_main; # 'Trend line'
TrendLine.SetDefaultColor(GlobalColor("Trend"));
TrendLine.SetLineWeight(2);
#//borders
plot Bordertop1 = if !ShowBand1 then na else alma_top; # 'Border top 1'
plot Bordertop2 = if !ShowBand2 then na else alma_top_2; # 'Border top 2'
plot Bordertop3 = if !ShowBand3 then na else alma_top_3; # 'Border top 3'
plot Borderbtm1 = if !ShowBand1 then na else alma_bottom; # 'Border bottom 1'
plot Borderbtm2 = if !ShowBand2 then na else alma_bottom_2; # 'Border bottom 2'
plot Borderbtm3 = if !ShowBand3 then na else alma_bottom_3; # 'Border bottom 3'
AddCloud(if !ShowCloud then na else Bordertop3, Bordertop2, GlobalColor("Top1"));
AddCloud(if !ShowCloud then na else Bordertop2, Bordertop1, GlobalColor("Top0"));
AddCloud(if !ShowCloud then na else Borderbtm1, Borderbtm2, GlobalColor("Btm0"));
AddCloud(if !ShowCloud then na else Borderbtm2, Borderbtm3, GlobalColor("Btm1"));
Bordertop1.SetDefaultColor(GlobalColor("Top1"));
Bordertop2.SetDefaultColor(GlobalColor("Top2"));
Bordertop3.SetDefaultColor(GlobalColor("Top3"));
Borderbtm1.SetDefaultColor(GlobalColor("Btm1"));
Borderbtm2.SetDefaultColor(GlobalColor("Btm2"));
Borderbtm3.SetDefaultColor(GlobalColor("Btm3"));
Bordertop1.SetLineWeight(2);
Bordertop3.SetLineWeight(2);
Borderbtm1.SetLineWeight(2);
Borderbtm3.SetLineWeight(2);
#// keltner
def kctop = kc_top; # 'KC+'
def kcbtm = kc_bottom; # 'KC-'
def kcTopMa = if !band then na else kc_top_ma; # 'KC+ HMA'
def kcBtmMa = if !band then na else kc_bottom_ma; # 'KC- HMA'
#// fibonacci
def fibTop = fib_top; # 'Fib+'
def fibBtm = fib_bottom; # 'Fib-'
def fibMed = (fib_top_smoothed + fib_bottom_smoothed) / 2;
def fibTopSmoothed = if !band then na else fib_top_smoothed; # 'Fib+ Smooth'
def fibBtmSmoothed = if !band then na else fib_bottom_smoothed; # 'Fib- Smooth'
plot fibMed2 = if !band then na else fibMed + (fib_top_smoothed-fibMed) * 0.618;
plot fibMed1 = if !band then na else fibMed + (fib_top_smoothed-fibMed) * 0.382;
plot fibMedSmoothed = if !band then na else fibMed;
plot fibMed_1 = if !band then na else fibMed - (fib_top_smoothed-fibMed) * 0.382;
plot fibMed_2 = if !band then na else fibMed - (fib_top_smoothed-fibMed) * 0.618;
#AddCloud(fibTopSmoothed, fibBtmSmoothed, CreateColor(40,40,40));
#AddCloud(kcTopMa, kcBtmMa, CreateColor(40,40,40));
AddCloud(fibTopSmoothed, kcTopMa, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(fibBtmSmoothed, kcBtmMa, Color.DARK_GREEN, Color.DARK_RED, yes);
#kcTopMa.SetDefaultColor(GlobalColor("maroon"));
#kcBtmMa.SetDefaultColor(GlobalColor("orange"));
fibMedSmoothed.SetDefaultColor(Color.WHITE);
#fibTopSmoothed.SetDefaultColor(GlobalColor("red"));
#fibBtmSmoothed.SetDefaultColor(GlobalColor("green"));
fibMed2.SetDefaultColor(Color.DARK_GRAY);
fibMed1.SetDefaultColor(Color.DARK_GRAY);
#kcTopMa.SetStyle(Curve.MEDIUM_DASH);
#kcBtmMa.SetStyle(Curve.MEDIUM_DASH);
#fibTopSmoothed.SetStyle(Curve.MEDIUM_DASH);
#fibBtmSmoothed.SetStyle(Curve.MEDIUM_DASH);
fibMed_2.SetDefaultColor(Color.DARK_GRAY);
fibMed_1.SetDefaultColor(Color.DARK_GRAY);
AddLabel(show_label, "Percent:" + " Top " + Round(difference_percent_top, 2) + "%", Color.WHITE);
AddLabel(show_label, " Botm " + Round(difference_percent_bottom, 2) + "%", Color.WHITE);
AddLabel(show_label, " Ovr All " + Round(difference_percent_overall,2) + "%", Color.WHITE);
#---- END CODE
Last edited by a moderator: