Can someone help me add Keltner Channels to this HMA?

khpro59

Expert Trader
VIP
Beautiful People,

Considering all Keltner channels have a middle moving average, is it possible to use this HMA script for the moving average portion of the Keltner channels and have it go 2x ATR below and above that via Keltner Channels?

First I started with Keltner Channels and trying to add this Adaptive Hull Moving Average script as the moving average, but I could not figure out how to do so. Then I realized maybe I just add Keltner Channels to the Adaptive HMA, maybe that would be easier... but I still cannot get it to work.

I really just want bands above and below the HMA acting as its potential range, standard deviations or ATR (keltner) would be fine, from there I should be able to figure out whatever anyone comes up with.

Really appreciate the help and insight as always.


Code:
#// @Loxx
#indicator('PA-Adaptive Hull Parabolic [Loxx]', overlay=true)
# Converted by Sam4Cok@Samer800    - 12/2023
input src = close;#, "Source", group = "Basic Settings")
input Power = 1;#, "Power", group = "Basic Settings")
input PhaseAccumulationCycles = 1.0;#, "Phase Accumulation Cycles", group = "Basic Settings")
input PhaseAccumulationPower = 1.0;#, "Phase Accumulation Power", group = "Basic Settings")
input colorBars = yes;#(true, "Color bars", group= "UI Options")
input showSigs = yes;#(true, "Show signals", group= "UI Options")

def na = Double.NaN;
#calcComp(src, period)=>
Script calcComp {
input src = close;
    def out = (
         (0.0962 * src +
         0.5769 * src[2] -
         0.5769 * src[4] -
         0.0962 * src[6]) * (0.075 * src[1] + 0.54));
    plot return = out;
}
#iLwmp(src, len, pow) =>
script iLwmp {
    input src = close;
    input len1 = 10;
    input pow = 1;
    def len = if len1 < 2 then 2 else len1;
    def sumw_ = Power(len, pow);
    def sum_ = sumw_ * src;
    def sum1 = fold i = 1 to len with q=sum_ do
               q + Power(len - i, pow) * GetValue(src, i);
    def sumw1 = fold k = 1 to len with p=sumw_ do
               p + Power(len - k, pow);
    def sum = sum1;
    def sumw = sumw1;
    def iLwmp = sum / sumw;
    plot out = if isNaN(iLwmp) then (sum_/sumw_) else iLwmp;
}
#export paa(float src, float mult, float filt)=>
script paa {
    input src = close;
    input mult = 1;
    input filt = 0;
    def bar_index = AbsValue(BarNumber());
    def pi = Double.Pi;
    def degree = 180.0 / pi;
    def filter = Max(filt, 1);
    def I1;
    def Q1;
    def Phase;
    def period;
    def Smooth = if bar_index > 5 then
                 (4 * src + 3 * src[1] + 2 * src[2] + src[3]) / 10 else Smooth[1];
    def ts = calcComp(Smooth);
    def Detrender = if bar_index > 5 then ts else Detrender[1];
    def qs = calcComp(Detrender);
    def Q1_ = if bar_index > 5 then qs else Q1[1];
    def I1_ = if bar_index > 5 then Detrender[3] else I1[1];
        I1 = 0.15 * I1_ + 0.85 * I1[1];
        Q1 = 0.15 * Q1_ + 0.85 * Q1[1];
    def Phase1 = Phase[1];
    def Phase2 = if AbsValue(I1) > 0 then degree * ATan(AbsValue(Q1 / I1)) else Phase1;
    def Phase3 = if I1 < 0 and Q1 > 0 then 180 - Phase2 else Phase2;
    def Phase4 = if I1 < 0 and Q1 < 0 then 180 + Phase3 else Phase3;
        Phase  = if I1 > 0 and Q1 < 0 then 360 - Phase4 else Phase4;
    def DeltaPhase1 = Phase[1] - Phase;
    def DeltaPhase2 = if Phase[1] < 90 and Phase > 270 then
                      360 + Phase[1] - Phase else DeltaPhase1;
    def DeltaPhase3 = Max(Min(DeltaPhase2, 60), 7);
    def DeltaPhase = DeltaPhase3;
    def PhaseSum;
    def preSum;
    def count;
    if (PhaseSum[1] < (mult * 360) and count[1] < 4500) {
        preSum = GetValue(DeltaPhase, count[1]);
        PhaseSum = PhaseSum[1] + (if isNaN(preSum) then 0 else preSum);
        count = count[1] + 1;
    } else {
        preSum = 0;
        PhaseSum = PhaseSum[1];
        count = 0;
    }
    def InstPeriod = if count > 0 then count else InstPeriod[1];
    def alpha = 2.0 / (1.0 + filter);
    def period1 = period[1] + alpha * (InstPeriod - period[1]);
        period = if Floor(period1) < 1 then 1 else Floor(period1);
    def paa = Floor(period);
    plot return = if isNaN(paa) then 1 else paa;
}
def paa_ = paa(src, PhaseAccumulationCycles, PhaseAccumulationPower);
def HmaLength = if paa_ < 2 then 2 else paa_;
def HalfPrd    = HmaLength / 2;
def HullPrd    = Sqrt(HmaLength);
def HalfPeriod = Floor(HalfPrd);
def HullPeriod = Floor(HullPrd);
def iLwmpHalf_ = iLwmp(src, HalfPeriod, Power);
def iLwmpHma_  = iLwmp(src, HmaLength, Power);
def iLwmpHalf  = iLwmpHalf_;
def iLwmpHma = iLwmpHma_;
def iLwmSrc  = (2.0 * iLwmpHalf) - iLwmpHma;
def hullout_ = iLwmp(iLwmSrc, HullPeriod, Power);
def hullout = hullout_;
def sig = hullout[1];
def colorout = hullout > sig;
def goLong  = Crosses(hullout, sig, CrossingDirection.ABOVE);
def goShort = Crosses(hullout, sig, CrossingDirection.BELOW);

AssignPriceColor(if !colorBars then Color.CURRENT else
                 if colorout then Color.GREEN else Color.RED);

plot hullLine = hullout;
hullLine.SetLineWeight(2);
hullLine.AssignValueColor(if colorout then Color.GREEN else Color.RED);

AddChartBubble(goLong, low, "L", Color.CYAN, no);
AddChartBubble(goShort, high, "S", GetColor(2));

#-- END of CODE
 
Solution
Beautiful People,

Considering all Keltner channels have a middle moving average, is it possible to use this HMA script for the moving average portion of the Keltner channels and have it go 2x ATR below and above that via Keltner Channels?

First I started with Keltner Channels and trying to add this Adaptive Hull Moving Average script as the moving average, but I could not figure out how to do so. Then I realized maybe I just add Keltner Channels to the Adaptive HMA, maybe that would be easier... but I still cannot get it to work.

I really just want bands above and below the HMA acting as its potential range, standard deviations or ATR (keltner) would be fine, from there I should be able to figure out whatever anyone comes up...
Beautiful People,

Considering all Keltner channels have a middle moving average, is it possible to use this HMA script for the moving average portion of the Keltner channels and have it go 2x ATR below and above that via Keltner Channels?

First I started with Keltner Channels and trying to add this Adaptive Hull Moving Average script as the moving average, but I could not figure out how to do so. Then I realized maybe I just add Keltner Channels to the Adaptive HMA, maybe that would be easier... but I still cannot get it to work.

I really just want bands above and below the HMA acting as its potential range, standard deviations or ATR (keltner) would be fine, from there I should be able to figure out whatever anyone comes up with.

Really appreciate the help and insight as always.


Code:
#// @Loxx
#indicator('PA-Adaptive Hull Parabolic [Loxx]', overlay=true)
# Converted by Sam4Cok@Samer800    - 12/2023
input src = close;#, "Source", group = "Basic Settings")
input Power = 1;#, "Power", group = "Basic Settings")
input PhaseAccumulationCycles = 1.0;#, "Phase Accumulation Cycles", group = "Basic Settings")
input PhaseAccumulationPower = 1.0;#, "Phase Accumulation Power", group = "Basic Settings")
input colorBars = yes;#(true, "Color bars", group= "UI Options")
input showSigs = yes;#(true, "Show signals", group= "UI Options")

def na = Double.NaN;
#calcComp(src, period)=>
Script calcComp {
input src = close;
    def out = (
         (0.0962 * src +
         0.5769 * src[2] -
         0.5769 * src[4] -
         0.0962 * src[6]) * (0.075 * src[1] + 0.54));
    plot return = out;
}
#iLwmp(src, len, pow) =>
script iLwmp {
    input src = close;
    input len1 = 10;
    input pow = 1;
    def len = if len1 < 2 then 2 else len1;
    def sumw_ = Power(len, pow);
    def sum_ = sumw_ * src;
    def sum1 = fold i = 1 to len with q=sum_ do
               q + Power(len - i, pow) * GetValue(src, i);
    def sumw1 = fold k = 1 to len with p=sumw_ do
               p + Power(len - k, pow);
    def sum = sum1;
    def sumw = sumw1;
    def iLwmp = sum / sumw;
    plot out = if isNaN(iLwmp) then (sum_/sumw_) else iLwmp;
}
#export paa(float src, float mult, float filt)=>
script paa {
    input src = close;
    input mult = 1;
    input filt = 0;
    def bar_index = AbsValue(BarNumber());
    def pi = Double.Pi;
    def degree = 180.0 / pi;
    def filter = Max(filt, 1);
    def I1;
    def Q1;
    def Phase;
    def period;
    def Smooth = if bar_index > 5 then
                 (4 * src + 3 * src[1] + 2 * src[2] + src[3]) / 10 else Smooth[1];
    def ts = calcComp(Smooth);
    def Detrender = if bar_index > 5 then ts else Detrender[1];
    def qs = calcComp(Detrender);
    def Q1_ = if bar_index > 5 then qs else Q1[1];
    def I1_ = if bar_index > 5 then Detrender[3] else I1[1];
        I1 = 0.15 * I1_ + 0.85 * I1[1];
        Q1 = 0.15 * Q1_ + 0.85 * Q1[1];
    def Phase1 = Phase[1];
    def Phase2 = if AbsValue(I1) > 0 then degree * ATan(AbsValue(Q1 / I1)) else Phase1;
    def Phase3 = if I1 < 0 and Q1 > 0 then 180 - Phase2 else Phase2;
    def Phase4 = if I1 < 0 and Q1 < 0 then 180 + Phase3 else Phase3;
        Phase  = if I1 > 0 and Q1 < 0 then 360 - Phase4 else Phase4;
    def DeltaPhase1 = Phase[1] - Phase;
    def DeltaPhase2 = if Phase[1] < 90 and Phase > 270 then
                      360 + Phase[1] - Phase else DeltaPhase1;
    def DeltaPhase3 = Max(Min(DeltaPhase2, 60), 7);
    def DeltaPhase = DeltaPhase3;
    def PhaseSum;
    def preSum;
    def count;
    if (PhaseSum[1] < (mult * 360) and count[1] < 4500) {
        preSum = GetValue(DeltaPhase, count[1]);
        PhaseSum = PhaseSum[1] + (if isNaN(preSum) then 0 else preSum);
        count = count[1] + 1;
    } else {
        preSum = 0;
        PhaseSum = PhaseSum[1];
        count = 0;
    }
    def InstPeriod = if count > 0 then count else InstPeriod[1];
    def alpha = 2.0 / (1.0 + filter);
    def period1 = period[1] + alpha * (InstPeriod - period[1]);
        period = if Floor(period1) < 1 then 1 else Floor(period1);
    def paa = Floor(period);
    plot return = if isNaN(paa) then 1 else paa;
}
def paa_ = paa(src, PhaseAccumulationCycles, PhaseAccumulationPower);
def HmaLength = if paa_ < 2 then 2 else paa_;
def HalfPrd    = HmaLength / 2;
def HullPrd    = Sqrt(HmaLength);
def HalfPeriod = Floor(HalfPrd);
def HullPeriod = Floor(HullPrd);
def iLwmpHalf_ = iLwmp(src, HalfPeriod, Power);
def iLwmpHma_  = iLwmp(src, HmaLength, Power);
def iLwmpHalf  = iLwmpHalf_;
def iLwmpHma = iLwmpHma_;
def iLwmSrc  = (2.0 * iLwmpHalf) - iLwmpHma;
def hullout_ = iLwmp(iLwmSrc, HullPeriod, Power);
def hullout = hullout_;
def sig = hullout[1];
def colorout = hullout > sig;
def goLong  = Crosses(hullout, sig, CrossingDirection.ABOVE);
def goShort = Crosses(hullout, sig, CrossingDirection.BELOW);

AssignPriceColor(if !colorBars then Color.CURRENT else
                 if colorout then Color.GREEN else Color.RED);

plot hullLine = hullout;
hullLine.SetLineWeight(2);
hullLine.AssignValueColor(if colorout then Color.GREEN else Color.RED);

AddChartBubble(goLong, low, "L", Color.CYAN, no);
AddChartBubble(goShort, high, "S", GetColor(2));

#-- END of CODE

is this what you want?
i added the keltner to the end of your study

Code:
#keltner_mod_avg

#https://usethinkscript.com/threads/can-someone-help-me-add-keltner-channels-to-this-hma.17909/
#Can someone help me add Keltner Channels to this HMA?
#khpro59  2/9

#Considering all Keltner channels have a middle moving average, is it possible to use this HMA script for the moving average portion of the Keltner channels and have it go 2x ATR below and above that via Keltner Channels?

#First I started with Keltner Channels and trying to add this Adaptive Hull Moving Average script as the moving average, but I could not figure out how to do so. Then I realized maybe I just add Keltner Channels to the Adaptive HMA, maybe that would be easier... but I still cannot get it to work.

#I really just want bands above and below the HMA acting as its potential range, standard deviations or ATR (keltner) would be fine, from there I should be able to figure out whatever anyone comes up with.


#// @Loxx
#indicator('PA-Adaptive Hull Parabolic [Loxx]', overlay=true)
# Converted by Sam4Cok@Samer800    - 12/2023
input src = close;#, "Source", group = "Basic Settings")
input Power = 1;#, "Power", group = "Basic Settings")
input PhaseAccumulationCycles = 1.0;#, "Phase Accumulation Cycles", group = "Basic Settings")
input PhaseAccumulationPower = 1.0;#, "Phase Accumulation Power", group = "Basic Settings")
input colorBars = yes;#(true, "Color bars", group= "UI Options")
input showSigs = yes;#(true, "Show signals", group= "UI Options")

def na = Double.NaN;
#calcComp(src, period)=>
Script calcComp {
input src = close;
    def out = (
         (0.0962 * src +
         0.5769 * src[2] -
         0.5769 * src[4] -
         0.0962 * src[6]) * (0.075 * src[1] + 0.54));
    plot return = out;
}
#iLwmp(src, len, pow) =>
script iLwmp {
    input src = close;
    input len1 = 10;
    input pow = 1;
    def len = if len1 < 2 then 2 else len1;
    def sumw_ = Power(len, pow);
    def sum_ = sumw_ * src;
    def sum1 = fold i = 1 to len with q=sum_ do
               q + Power(len - i, pow) * GetValue(src, i);
    def sumw1 = fold k = 1 to len with p=sumw_ do
               p + Power(len - k, pow);
    def sum = sum1;
    def sumw = sumw1;
    def iLwmp = sum / sumw;
    plot out = if isNaN(iLwmp) then (sum_/sumw_) else iLwmp;
}
#export paa(float src, float mult, float filt)=>
script paa {
    input src = close;
    input mult = 1;
    input filt = 0;
    def bar_index = AbsValue(BarNumber());
    def pi = Double.Pi;
    def degree = 180.0 / pi;
    def filter = Max(filt, 1);
    def I1;
    def Q1;
    def Phase;
    def period;
    def Smooth = if bar_index > 5 then
                 (4 * src + 3 * src[1] + 2 * src[2] + src[3]) / 10 else Smooth[1];
    def ts = calcComp(Smooth);
    def Detrender = if bar_index > 5 then ts else Detrender[1];
    def qs = calcComp(Detrender);
    def Q1_ = if bar_index > 5 then qs else Q1[1];
    def I1_ = if bar_index > 5 then Detrender[3] else I1[1];
        I1 = 0.15 * I1_ + 0.85 * I1[1];
        Q1 = 0.15 * Q1_ + 0.85 * Q1[1];
    def Phase1 = Phase[1];
    def Phase2 = if AbsValue(I1) > 0 then degree * ATan(AbsValue(Q1 / I1)) else Phase1;
    def Phase3 = if I1 < 0 and Q1 > 0 then 180 - Phase2 else Phase2;
    def Phase4 = if I1 < 0 and Q1 < 0 then 180 + Phase3 else Phase3;
        Phase  = if I1 > 0 and Q1 < 0 then 360 - Phase4 else Phase4;
    def DeltaPhase1 = Phase[1] - Phase;
    def DeltaPhase2 = if Phase[1] < 90 and Phase > 270 then
                      360 + Phase[1] - Phase else DeltaPhase1;
    def DeltaPhase3 = Max(Min(DeltaPhase2, 60), 7);
    def DeltaPhase = DeltaPhase3;
    def PhaseSum;
    def preSum;
    def count;
    if (PhaseSum[1] < (mult * 360) and count[1] < 4500) {
        preSum = GetValue(DeltaPhase, count[1]);
        PhaseSum = PhaseSum[1] + (if isNaN(preSum) then 0 else preSum);
        count = count[1] + 1;
    } else {
        preSum = 0;
        PhaseSum = PhaseSum[1];
        count = 0;
    }
    def InstPeriod = if count > 0 then count else InstPeriod[1];
    def alpha = 2.0 / (1.0 + filter);
    def period1 = period[1] + alpha * (InstPeriod - period[1]);
        period = if Floor(period1) < 1 then 1 else Floor(period1);
    def paa = Floor(period);
    plot return = if isNaN(paa) then 1 else paa;
}
def paa_ = paa(src, PhaseAccumulationCycles, PhaseAccumulationPower);
def HmaLength = if paa_ < 2 then 2 else paa_;
def HalfPrd    = HmaLength / 2;
def HullPrd    = Sqrt(HmaLength);
def HalfPeriod = Floor(HalfPrd);
def HullPeriod = Floor(HullPrd);
def iLwmpHalf_ = iLwmp(src, HalfPeriod, Power);
def iLwmpHma_  = iLwmp(src, HmaLength, Power);
def iLwmpHalf  = iLwmpHalf_;
def iLwmpHma = iLwmpHma_;
def iLwmSrc  = (2.0 * iLwmpHalf) - iLwmpHma;
def hullout_ = iLwmp(iLwmSrc, HullPeriod, Power);
def hullout = hullout_;
def sig = hullout[1];
def colorout = hullout > sig;
def goLong  = Crosses(hullout, sig, CrossingDirection.ABOVE);
def goShort = Crosses(hullout, sig, CrossingDirection.BELOW);

AssignPriceColor(if !colorBars then Color.CURRENT else
                 if colorout then Color.GREEN else Color.RED);

plot hullLine = hullout;
hullLine.SetLineWeight(2);
hullLine.AssignValueColor(if colorout then Color.GREEN else Color.RED);

AddChartBubble(goLong, low, "L", Color.CYAN, no);
AddChartBubble(goShort, high, "S", GetColor(2));

#-- END of CODE








# keltner ch
# TD Ameritrade IP Company, Inc. (c) 2007-2024

#declare weak_volume_dependency;

input displace = 0;
input factor = 1.5;
input length = 20;
input price = close;
input averageType = AverageType.SIMPLE;
input trueRangeAverageType = AverageType.SIMPLE;

def shift = factor * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
def average = MovingAverage(averageType, price, length);


input show_k_lines = yes;
#plot Avg = if show_k_lines then average[-displace] else na;
#Avg.SetDefaultColor(GetColor(1));
#plot Upper_Band = if show_k_lines then (average[-displace] + shift[-displace]) else na;
#Upper_Band.SetDefaultColor(GetColor(8));
#plot Lower_Band = if show_k_lines then (average[-displace] - shift[-displace]) else na;
#Lower_Band.SetDefaultColor(GetColor(5));


plot Upper_Band = if show_k_lines then (hullout + shift[-displace]) else na;
Upper_Band.SetDefaultColor(GetColor(8));
plot Lower_Band = if show_k_lines then (hullout - shift[-displace]) else na;
Lower_Band.SetDefaultColor(GetColor(8));

#
 

Attachments

  • img1.JPG
    img1.JPG
    160.6 KB · Views: 102
Solution
is this what you want?
i added the keltner to the end of your study

Code:
#keltner_mod_avg

#https://usethinkscript.com/threads/can-someone-help-me-add-keltner-channels-to-this-hma.17909/
#Can someone help me add Keltner Channels to this HMA?
#khpro59  2/9

#Considering all Keltner channels have a middle moving average, is it possible to use this HMA script for the moving average portion of the Keltner channels and have it go 2x ATR below and above that via Keltner Channels?

#First I started with Keltner Channels and trying to add this Adaptive Hull Moving Average script as the moving average, but I could not figure out how to do so. Then I realized maybe I just add Keltner Channels to the Adaptive HMA, maybe that would be easier... but I still cannot get it to work.

#I really just want bands above and below the HMA acting as its potential range, standard deviations or ATR (keltner) would be fine, from there I should be able to figure out whatever anyone comes up with.


#// @Loxx
#indicator('PA-Adaptive Hull Parabolic [Loxx]', overlay=true)
# Converted by Sam4Cok@Samer800    - 12/2023
input src = close;#, "Source", group = "Basic Settings")
input Power = 1;#, "Power", group = "Basic Settings")
input PhaseAccumulationCycles = 1.0;#, "Phase Accumulation Cycles", group = "Basic Settings")
input PhaseAccumulationPower = 1.0;#, "Phase Accumulation Power", group = "Basic Settings")
input colorBars = yes;#(true, "Color bars", group= "UI Options")
input showSigs = yes;#(true, "Show signals", group= "UI Options")

def na = Double.NaN;
#calcComp(src, period)=>
Script calcComp {
input src = close;
    def out = (
         (0.0962 * src +
         0.5769 * src[2] -
         0.5769 * src[4] -
         0.0962 * src[6]) * (0.075 * src[1] + 0.54));
    plot return = out;
}
#iLwmp(src, len, pow) =>
script iLwmp {
    input src = close;
    input len1 = 10;
    input pow = 1;
    def len = if len1 < 2 then 2 else len1;
    def sumw_ = Power(len, pow);
    def sum_ = sumw_ * src;
    def sum1 = fold i = 1 to len with q=sum_ do
               q + Power(len - i, pow) * GetValue(src, i);
    def sumw1 = fold k = 1 to len with p=sumw_ do
               p + Power(len - k, pow);
    def sum = sum1;
    def sumw = sumw1;
    def iLwmp = sum / sumw;
    plot out = if isNaN(iLwmp) then (sum_/sumw_) else iLwmp;
}
#export paa(float src, float mult, float filt)=>
script paa {
    input src = close;
    input mult = 1;
    input filt = 0;
    def bar_index = AbsValue(BarNumber());
    def pi = Double.Pi;
    def degree = 180.0 / pi;
    def filter = Max(filt, 1);
    def I1;
    def Q1;
    def Phase;
    def period;
    def Smooth = if bar_index > 5 then
                 (4 * src + 3 * src[1] + 2 * src[2] + src[3]) / 10 else Smooth[1];
    def ts = calcComp(Smooth);
    def Detrender = if bar_index > 5 then ts else Detrender[1];
    def qs = calcComp(Detrender);
    def Q1_ = if bar_index > 5 then qs else Q1[1];
    def I1_ = if bar_index > 5 then Detrender[3] else I1[1];
        I1 = 0.15 * I1_ + 0.85 * I1[1];
        Q1 = 0.15 * Q1_ + 0.85 * Q1[1];
    def Phase1 = Phase[1];
    def Phase2 = if AbsValue(I1) > 0 then degree * ATan(AbsValue(Q1 / I1)) else Phase1;
    def Phase3 = if I1 < 0 and Q1 > 0 then 180 - Phase2 else Phase2;
    def Phase4 = if I1 < 0 and Q1 < 0 then 180 + Phase3 else Phase3;
        Phase  = if I1 > 0 and Q1 < 0 then 360 - Phase4 else Phase4;
    def DeltaPhase1 = Phase[1] - Phase;
    def DeltaPhase2 = if Phase[1] < 90 and Phase > 270 then
                      360 + Phase[1] - Phase else DeltaPhase1;
    def DeltaPhase3 = Max(Min(DeltaPhase2, 60), 7);
    def DeltaPhase = DeltaPhase3;
    def PhaseSum;
    def preSum;
    def count;
    if (PhaseSum[1] < (mult * 360) and count[1] < 4500) {
        preSum = GetValue(DeltaPhase, count[1]);
        PhaseSum = PhaseSum[1] + (if isNaN(preSum) then 0 else preSum);
        count = count[1] + 1;
    } else {
        preSum = 0;
        PhaseSum = PhaseSum[1];
        count = 0;
    }
    def InstPeriod = if count > 0 then count else InstPeriod[1];
    def alpha = 2.0 / (1.0 + filter);
    def period1 = period[1] + alpha * (InstPeriod - period[1]);
        period = if Floor(period1) < 1 then 1 else Floor(period1);
    def paa = Floor(period);
    plot return = if isNaN(paa) then 1 else paa;
}
def paa_ = paa(src, PhaseAccumulationCycles, PhaseAccumulationPower);
def HmaLength = if paa_ < 2 then 2 else paa_;
def HalfPrd    = HmaLength / 2;
def HullPrd    = Sqrt(HmaLength);
def HalfPeriod = Floor(HalfPrd);
def HullPeriod = Floor(HullPrd);
def iLwmpHalf_ = iLwmp(src, HalfPeriod, Power);
def iLwmpHma_  = iLwmp(src, HmaLength, Power);
def iLwmpHalf  = iLwmpHalf_;
def iLwmpHma = iLwmpHma_;
def iLwmSrc  = (2.0 * iLwmpHalf) - iLwmpHma;
def hullout_ = iLwmp(iLwmSrc, HullPeriod, Power);
def hullout = hullout_;
def sig = hullout[1];
def colorout = hullout > sig;
def goLong  = Crosses(hullout, sig, CrossingDirection.ABOVE);
def goShort = Crosses(hullout, sig, CrossingDirection.BELOW);

AssignPriceColor(if !colorBars then Color.CURRENT else
                 if colorout then Color.GREEN else Color.RED);

plot hullLine = hullout;
hullLine.SetLineWeight(2);
hullLine.AssignValueColor(if colorout then Color.GREEN else Color.RED);

AddChartBubble(goLong, low, "L", Color.CYAN, no);
AddChartBubble(goShort, high, "S", GetColor(2));

#-- END of CODE








# keltner ch
# TD Ameritrade IP Company, Inc. (c) 2007-2024

#declare weak_volume_dependency;

input displace = 0;
input factor = 1.5;
input length = 20;
input price = close;
input averageType = AverageType.SIMPLE;
input trueRangeAverageType = AverageType.SIMPLE;

def shift = factor * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
def average = MovingAverage(averageType, price, length);


input show_k_lines = yes;
#plot Avg = if show_k_lines then average[-displace] else na;
#Avg.SetDefaultColor(GetColor(1));
#plot Upper_Band = if show_k_lines then (average[-displace] + shift[-displace]) else na;
#Upper_Band.SetDefaultColor(GetColor(8));
#plot Lower_Band = if show_k_lines then (average[-displace] - shift[-displace]) else na;
#Lower_Band.SetDefaultColor(GetColor(5));


plot Upper_Band = if show_k_lines then (hullout + shift[-displace]) else na;
Upper_Band.SetDefaultColor(GetColor(8));
plot Lower_Band = if show_k_lines then (hullout - shift[-displace]) else na;
Lower_Band.SetDefaultColor(GetColor(8));

#
Per your screenshot, yes this is exactly what I wanted. Will have to test it out on some charts but I believe you got it down. Can’t wait to review to see what I was doing wrong…I think I was overthinking it

Thank you so very much for doing this for me, and have a great weekend Halycon,
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
302 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top