Gaussian Channel Indicator For ThinkOrSwim

Aye P

New member
Would it be possible to convert this TradingView Script to ToS?
https://www.tradingview.com/script/WpVY7GKW-Gaussian-Channel-DW/

I've been using this Gaussian Channel on higher time frames on TradingView for a few months now, and it would be such a life saver if I could use it on ThinkorSwim. I've tried other Gaussian channels, however i've grown too fond of this script created by DonovanWall.
 
Last edited by a moderator:

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

Would it be possible to convert this TradingView Script to ToS?
https://www.tradingview.com/script/WpVY7GKW-Gaussian-Channel-DW/
FNBlUZr.png

creator messege:
his study is an experiment utilizing the Ehlers Gaussian Filter technique combined with lag reduction techniques and true range to analyze trend activity.
Gaussian filters, as Ehlers explains it, are simply exponential moving averages applied multiple times.
First, beta and alpha are calculated based on the sampling period and number of poles specified. The maximum number of poles available in this script is 9.
Next, the data being analyzed is given a truncation option for reduced lag, which can be enabled with "Reduced Lag Mode".
Then the alpha and source values are used to calculate the filter and filtered true range of the dataset.
Filtered true range with a specified multiplier is then added to and subtracted from the filter, generating a channel.
Lastly, a one pole filter with a N pole alpha is averaged with the filter to generate a faster filter, which can be enabled with "Fast Response Mode".

Custom bar colors are included.

Note: Both the sampling period and number of poles directly affect how much lag the indicator has, and how smooth the output is.
Larger inputs will result in smoother outputs with increased lag, and smaller inputs will have noisier outputs with reduced lag.
For the best results, I recommend not setting the sampling period any lower than the number of poles + 1. Going lower truncates the equation.

Code:

CSS:
#https://www.tradingview.com/script/WpVY7GKW-Gaussian-Channel-DW/
#//@version=4
#study(title="Gaussian Channel [DW]", shorttitle="GC [DW]", overlay=true)
# Request from https://usethinkscript.com/ memeber
# Converted and mod by Sam4Cok@Samer800 - 09/2022
#//------------------------------------------------------
#//Inputs
#//------------------------------------------------------
input BarColor = no;
input ShowChannel = no;
input ShowCloud = yes;
#//Source
input src = hlc3;
#//Poles
input Poles = 4;
#//Period
input SmaplePeriod = 144;    # "Sampling Period"
#//True Range Multiplier
input mult = 1.414;          # "Filtered True Range Multiplier"
#//Lag Reduction
input ReducedLagMode  = no;  # "Reduced Lag Mode"
input FastResponseMode = no; # "Fast Response Mode"

def na = Double.NaN;

########### Color ################
DefineGlobalColor("Exup" , CreateColor(10, 255, 104));
DefineGlobalColor("Weakup" , CreateColor(10, 255, 27));
DefineGlobalColor("up"   , CreateColor(0, 117, 45));
DefineGlobalColor("Exdn" , CreateColor(255, 10, 90));
DefineGlobalColor("weakdn" , CreateColor(255, 10, 17));
DefineGlobalColor("dn" , CreateColor(153, 0, 50)); #

#//Filter function
#f_filt9x (_a, _s, _i) =>
script f_filt9x {
    input _a = close;
    input _s = close;
    input _i = close;
    def na = Double.NaN;
    def _x = (1 - _a);
    def _m2;
    def _m3;
    def _m4;
    def _m5;
    def _m6;
    def _m7;
    def _m8;
    def _m9;
 #   // Initial weight _m1 is a pole number and equal to _i
    _m2 = if IsNaN(_m2[1]) then 0 else
          if _i == 9 then 36 else if _i == 8 then 28 else if _i == 7 then 21 else
          if _i == 6 then 15 else if _i == 5 then 10 else if _i == 4 then 6 else
          if _i == 3 then 3 else if _i == 2 then 1 else 0;
    _m3 = if IsNaN(_m3[1]) then 0 else
          if _i == 9 then 84 else if _i == 8 then 56 else if _i == 7 then 35 else
          if _i == 6 then 20 else if _i == 5 then 10 else if _i == 4 then 4 else
          if _i == 3 then 1 else 0;
    _m4 = if IsNaN(_m4[1]) then 0 else
          if _i == 9 then 126 else if _i == 8 then 70 else if _i == 7 then 35 else
          if _i == 6 then 15 else if _i == 5 then 5  else if _i == 4 then 1 else 0;
    _m5 = if IsNaN(_m5[1]) then 0 else
          if _i == 9 then 126 else if  _i == 8 then 56 else if _i == 7 then 21 else
          if _i == 6 then 6 else if _i == 5 then 1 else 0;
    _m6 = if IsNaN(_m6[1]) then 0 else
          if _i == 9 then 84 else if _i == 8 then 28 else if _i == 7 then 7  else
          if _i == 6 then 1 else 0;
    _m7 = if IsNaN(_m7[1]) then 0 else
          if _i == 9 then 36 else if _i == 8 then 8  else if _i == 7 then 1 else 0;
    _m8 = if IsNaN(_m8[1]) then 0 else
              if _i == 9 then 9 else if _i == 8 then 1 else 0;
    _m9 = if IsNaN(_m9[1]) then 0 else if _i == 9 then 1 else 0;
#    // filter
    def _f = if IsNaN(_f[10*2]) then na else
            Power(_a, _i) * (_s) + _i * _x * (_f[1]) - (if _i >= 2 then
      _m2 * Power(_x, 2)  * (_f[2]) else 0) + (if _i >= 3 then
      _m3 * Power(_x, 3)  * (_f[3]) else 0) - (if _i >= 4 then
      _m4 * Power(_x, 4)  * (_f[4]) else 0) + (if _i >= 5 then
      _m5 * Power(_x, 5)  * (_f[5]) else 0) - (if _i >= 6 then
      _m6 * Power(_x, 6)  * (_f[6]) else 0) + (if _i >= 7 then
      _m7 * Power(_x, 7)  * (_f[7]) else 0) - (if _i >= 8 then
      _m8 * Power(_x, 8)  * (_f[8]) else 0) + (if _i == 9 then
      _m9 * Power(_x, 9)  * (_f[9]) else 0);
    plot return = _f;
}
#//9 var declaration fun
#f_pole (_a, _s, _i) =>
script f_pole {
    input _a = 0;
    input _s = 0;
    input _i = 0;
    def _f1 = f_filt9x(_a, _s, 1);
    def _f2 = (if _i >= 2 then f_filt9x(_a, _s, 2) else 0);
    def _f3 = (if _i >= 3 then f_filt9x(_a, _s, 3) else 0);
    def _f4 = (if _i >= 4 then f_filt9x(_a, _s, 4) else 0);
    def _f5 = (if _i >= 5 then f_filt9x(_a, _s, 5) else 0);
    def _f6 = (if _i >= 6 then f_filt9x(_a, _s, 6) else 0);
    def _f7 = (if _i >= 2 then f_filt9x(_a, _s, 7) else 0);
    def _f8 = (if _i >= 8 then f_filt9x(_a, _s, 8) else 0);
    def _f9 = (if _i == 9 then f_filt9x(_a, _s, 9) else 0);

    def _fn = if _i == 1 then _f1 else if _i == 2 then  _f2 else if _i == 3 then _f3 else
    if _i == 4 then _f4 else if _i == 5 then _f5 else if _i == 6 then _f6 else
    if _i == 7 then _f7 else if _i == 8 then _f8 else if _i == 9 then _f9 else Double.NaN;
    plot filtn = _fn;
    plot filt1 = _f1;
}
# Variables
script g {
    input data = hlc3;
    def w = (2 * Double.Pi / 8);
    def beta =  (1 - Cos(w)) / (Power(1.414, 2.0 / 4) - 1 );
    def alpha = (-beta + Sqrt(beta * beta + 2 * beta));
    def G =      Power(alpha, 4) * data +
                 4 * (1 – alpha) * G[1] – 6 * Power( 1 - alpha, 2 ) * G[2] +
                 4 * Power( 1 - alpha, 3 ) * G[3] - Power( 1 - alpha, 4 ) * G[4];
    plot Line = G;
}
#/------------------------------------------
#//Definitions
#//-----------------------------------------
#//Beta and Alpha Components
def beta  = (1 - Cos(4 * ASin(1) / SmaplePeriod)) / (Power(1.414, 2 / Poles) - 1);
def alpha = - beta + Sqrt(Power(beta, 2) + 2 * beta);

#//Lag
def lag = (SmaplePeriod - 1) / (2 * Poles);
def tr = TrueRange(high, close, low);
#//Data
def srcdata = if ReducedLagMode then src + (src - GetValue(src, lag)) else src;
def trdata  = if ReducedLagMode then tr + tr - GetValue(tr, lag) else tr;

#//Filtered Values
def filtn = f_pole(alpha, srcdata, Poles).filtn;
def filt1 = f_pole(alpha, srcdata, Poles).filt1;
def filtntr = f_pole(alpha, trdata,  Poles).filtn;
def filt1tr = f_pole(alpha, trdata,  Poles).filt1;

#//Lag Reduction
def filt   = if FastResponseMode then (filtn + filt1) / 2 else filtn;
def filttr = if FastResponseMode then (filtntr + filt1tr) / 2 else filtntr;

#//Bands
def hband = filt + filttr * mult;
def lband = filt - filttr * mult;

def fcolor = if filt > filt[1] then 1 else if filt < filt[1] then -1 else 0;
#//line Plots
plot filter = if IsNaN(close) then na else filt;    #"Filter"
filter.SetLineWeight(2);
filter.AssignValueColor(if fcolor > 0 then GlobalColor("Exup") else
                        if fcolor < 0 then GlobalColor("Exdn") else Color.GRAY);
#//Band Plots
plot hbandplot = if ShowChannel and !IsNaN(close) then hband else na;    # "Filtered True Range High Band"
hbandplot.AssignValueColor(if fcolor > 0 then GlobalColor("EXup") else
                           if fcolor < 0 then GlobalColor("Exdn") else Color.GRAY);
plot lbandplot = if ShowChannel and !IsNaN(close) then lband else na;    # "Filtered True Range Low Band"
lbandplot.AssignValueColor(if fcolor > 0 then GlobalColor("Exup") else
                           if fcolor < 0 then GlobalColor("Exdn") else Color.GRAY);

AddCloud(if ShowCloud and !IsNaN(close) and fcolor > 0 then hband else
         if ShowCloud and !IsNaN(close) and fcolor < 0 then lband else na,
         if fcolor > 0 then lband else if fcolor < 0 then hband else na,
          GlobalColor("up"), GlobalColor("dn"));
#//price color Plots

AssignPriceColor(if BarColor then
                 if (src > src[1]) and (src > filt) and (src < hband) then GlobalColor("Exup") else
                 if (src > src[1]) and (src >= hband) then  GlobalColor("weakup") else
                 if (src <= src[1]) and (src > filt) then  GlobalColor("up") else
                 if (src < src[1]) and (src < filt) and (src > lband) then  GlobalColor("Exdn") else
                 if (src < src[1]) and (src <= lband) then  GlobalColor("weakdn") else
                 if (src >= src[1]) and (src < filt) then  GlobalColor("dn") else Color.DARK_GRAY
                 else Color.CURRENT);

#### END
 
Last edited by a moderator:
Would it be possible to convert this TradingView Script to ToS?
https://www.tradingview.com/script/WpVY7GKW-Gaussian-Channel-DW/

I've been using this Gaussian Channel on higher time frames on TradingView for a few months now, and it would be such a life saver if I could use it on ThinkorSwim. I've tried other Gaussian channels, however i've grown too fond of this script created by DonovanWall.
Did You ever get the script for TOS if so can I have it please . Thanks
 
FNBlUZr.png

creator messege:
his study is an experiment utilizing the Ehlers Gaussian Filter technique combined with lag reduction techniques and true range to analyze trend activity.
Gaussian filters, as Ehlers explains it, are simply exponential moving averages applied multiple times.
First, beta and alpha are calculated based on the sampling period and number of poles specified. The maximum number of poles available in this script is 9.
Next, the data being analyzed is given a truncation option for reduced lag, which can be enabled with "Reduced Lag Mode".
Then the alpha and source values are used to calculate the filter and filtered true range of the dataset.
Filtered true range with a specified multiplier is then added to and subtracted from the filter, generating a channel.
Lastly, a one pole filter with a N pole alpha is averaged with the filter to generate a faster filter, which can be enabled with "Fast Response Mode".

Custom bar colors are included.

Note: Both the sampling period and number of poles directly affect how much lag the indicator has, and how smooth the output is.
Larger inputs will result in smoother outputs with increased lag, and smaller inputs will have noisier outputs with reduced lag.
For the best results, I recommend not setting the sampling period any lower than the number of poles + 1. Going lower truncates the equation.

Code:

CSS:
#https://www.tradingview.com/script/WpVY7GKW-Gaussian-Channel-DW/
#//@version=4
#study(title="Gaussian Channel [DW]", shorttitle="GC [DW]", overlay=true)
# Request from https://usethinkscript.com/ memeber
# Converted and mod by Sam4Cok@Samer800 - 09/2022
#//------------------------------------------------------
#//Inputs
#//------------------------------------------------------
input BarColor = no;
input ShowChannel = no;
input ShowCloud = yes;
#//Source
input src = hlc3;
#//Poles
input Poles = 4;
#//Period
input SmaplePeriod = 144;    # "Sampling Period"
#//True Range Multiplier
input mult = 1.414;          # "Filtered True Range Multiplier"
#//Lag Reduction
input ReducedLagMode  = no;  # "Reduced Lag Mode"
input FastResponseMode = no; # "Fast Response Mode"

def na = Double.NaN;

########### Color ################
DefineGlobalColor("Exup" , CreateColor(10, 255, 104));
DefineGlobalColor("Weakup" , CreateColor(10, 255, 27));
DefineGlobalColor("up"   , CreateColor(0, 117, 45));
DefineGlobalColor("Exdn" , CreateColor(255, 10, 90));
DefineGlobalColor("weakdn" , CreateColor(255, 10, 17));
DefineGlobalColor("dn" , CreateColor(153, 0, 50)); #

#//Filter function
#f_filt9x (_a, _s, _i) =>
script f_filt9x {
    input _a = close;
    input _s = close;
    input _i = close;
    def na = Double.NaN;
    def _x = (1 - _a);
    def _m2;
    def _m3;
    def _m4;
    def _m5;
    def _m6;
    def _m7;
    def _m8;
    def _m9;
 #   // Initial weight _m1 is a pole number and equal to _i
    _m2 = if IsNaN(_m2[1]) then 0 else
          if _i == 9 then 36 else if _i == 8 then 28 else if _i == 7 then 21 else
          if _i == 6 then 15 else if _i == 5 then 10 else if _i == 4 then 6 else
          if _i == 3 then 3 else if _i == 2 then 1 else 0;
    _m3 = if IsNaN(_m3[1]) then 0 else
          if _i == 9 then 84 else if _i == 8 then 56 else if _i == 7 then 35 else
          if _i == 6 then 20 else if _i == 5 then 10 else if _i == 4 then 4 else
          if _i == 3 then 1 else 0;
    _m4 = if IsNaN(_m4[1]) then 0 else
          if _i == 9 then 126 else if _i == 8 then 70 else if _i == 7 then 35 else
          if _i == 6 then 15 else if _i == 5 then 5  else if _i == 4 then 1 else 0;
    _m5 = if IsNaN(_m5[1]) then 0 else
          if _i == 9 then 126 else if  _i == 8 then 56 else if _i == 7 then 21 else
          if _i == 6 then 6 else if _i == 5 then 1 else 0;
    _m6 = if IsNaN(_m6[1]) then 0 else
          if _i == 9 then 84 else if _i == 8 then 28 else if _i == 7 then 7  else
          if _i == 6 then 1 else 0;
    _m7 = if IsNaN(_m7[1]) then 0 else
          if _i == 9 then 36 else if _i == 8 then 8  else if _i == 7 then 1 else 0;
    _m8 = if IsNaN(_m8[1]) then 0 else
              if _i == 9 then 9 else if _i == 8 then 1 else 0;
    _m9 = if IsNaN(_m9[1]) then 0 else if _i == 9 then 1 else 0;
#    // filter
    def _f = if IsNaN(_f[10*2]) then na else
            Power(_a, _i) * (_s) + _i * _x * (_f[1]) - (if _i >= 2 then
      _m2 * Power(_x, 2)  * (_f[2]) else 0) + (if _i >= 3 then
      _m3 * Power(_x, 3)  * (_f[3]) else 0) - (if _i >= 4 then
      _m4 * Power(_x, 4)  * (_f[4]) else 0) + (if _i >= 5 then
      _m5 * Power(_x, 5)  * (_f[5]) else 0) - (if _i >= 6 then
      _m6 * Power(_x, 6)  * (_f[6]) else 0) + (if _i >= 7 then
      _m7 * Power(_x, 7)  * (_f[7]) else 0) - (if _i >= 8 then
      _m8 * Power(_x, 8)  * (_f[8]) else 0) + (if _i == 9 then
      _m9 * Power(_x, 9)  * (_f[9]) else 0);
    plot return = _f;
}
#//9 var declaration fun
#f_pole (_a, _s, _i) =>
script f_pole {
    input _a = 0;
    input _s = 0;
    input _i = 0;
    def _f1 = f_filt9x(_a, _s, 1);
    def _f2 = (if _i >= 2 then f_filt9x(_a, _s, 2) else 0);
    def _f3 = (if _i >= 3 then f_filt9x(_a, _s, 3) else 0);
    def _f4 = (if _i >= 4 then f_filt9x(_a, _s, 4) else 0);
    def _f5 = (if _i >= 5 then f_filt9x(_a, _s, 5) else 0);
    def _f6 = (if _i >= 6 then f_filt9x(_a, _s, 6) else 0);
    def _f7 = (if _i >= 2 then f_filt9x(_a, _s, 7) else 0);
    def _f8 = (if _i >= 8 then f_filt9x(_a, _s, 8) else 0);
    def _f9 = (if _i == 9 then f_filt9x(_a, _s, 9) else 0);

    def _fn = if _i == 1 then _f1 else if _i == 2 then  _f2 else if _i == 3 then _f3 else
    if _i == 4 then _f4 else if _i == 5 then _f5 else if _i == 6 then _f6 else
    if _i == 7 then _f7 else if _i == 8 then _f8 else if _i == 9 then _f9 else Double.NaN;
    plot filtn = _fn;
    plot filt1 = _f1;
}
# Variables
script g {
    input data = hlc3;
    def w = (2 * Double.Pi / 8);
    def beta =  (1 - Cos(w)) / (Power(1.414, 2.0 / 4) - 1 );
    def alpha = (-beta + Sqrt(beta * beta + 2 * beta));
    def G =      Power(alpha, 4) * data +
                 4 * (1 – alpha) * G[1] – 6 * Power( 1 - alpha, 2 ) * G[2] +
                 4 * Power( 1 - alpha, 3 ) * G[3] - Power( 1 - alpha, 4 ) * G[4];
    plot Line = G;
}
#/------------------------------------------
#//Definitions
#//-----------------------------------------
#//Beta and Alpha Components
def beta  = (1 - Cos(4 * ASin(1) / SmaplePeriod)) / (Power(1.414, 2 / Poles) - 1);
def alpha = - beta + Sqrt(Power(beta, 2) + 2 * beta);

#//Lag
def lag = (SmaplePeriod - 1) / (2 * Poles);
def tr = TrueRange(high, close, low);
#//Data
def srcdata = if ReducedLagMode then src + (src - GetValue(src, lag)) else src;
def trdata  = if ReducedLagMode then tr + tr - GetValue(tr, lag) else tr;

#//Filtered Values
def filtn = f_pole(alpha, srcdata, Poles).filtn;
def filt1 = f_pole(alpha, srcdata, Poles).filt1;
def filtntr = f_pole(alpha, trdata,  Poles).filtn;
def filt1tr = f_pole(alpha, trdata,  Poles).filt1;

#//Lag Reduction
def filt   = if FastResponseMode then (filtn + filt1) / 2 else filtn;
def filttr = if FastResponseMode then (filtntr + filt1tr) / 2 else filtntr;

#//Bands
def hband = filt + filttr * mult;
def lband = filt - filttr * mult;

def fcolor = if filt > filt[1] then 1 else if filt < filt[1] then -1 else 0;
#//line Plots
plot filter = if IsNaN(close) then na else filt;    #"Filter"
filter.SetLineWeight(2);
filter.AssignValueColor(if fcolor > 0 then GlobalColor("Exup") else
                        if fcolor < 0 then GlobalColor("Exdn") else Color.GRAY);
#//Band Plots
plot hbandplot = if ShowChannel and !IsNaN(close) then hband else na;    # "Filtered True Range High Band"
hbandplot.AssignValueColor(if fcolor > 0 then GlobalColor("EXup") else
                           if fcolor < 0 then GlobalColor("Exdn") else Color.GRAY);
plot lbandplot = if ShowChannel and !IsNaN(close) then lband else na;    # "Filtered True Range Low Band"
lbandplot.AssignValueColor(if fcolor > 0 then GlobalColor("Exup") else
                           if fcolor < 0 then GlobalColor("Exdn") else Color.GRAY);

AddCloud(if ShowCloud and !IsNaN(close) and fcolor > 0 then hband else
         if ShowCloud and !IsNaN(close) and fcolor < 0 then lband else na,
         if fcolor > 0 then lband else if fcolor < 0 then hband else na,
          GlobalColor("up"), GlobalColor("dn"));
#//price color Plots

AssignPriceColor(if BarColor then
                 if (src > src[1]) and (src > filt) and (src < hband) then GlobalColor("Exup") else
                 if (src > src[1]) and (src >= hband) then  GlobalColor("weakup") else
                 if (src <= src[1]) and (src > filt) then  GlobalColor("up") else
                 if (src < src[1]) and (src < filt) and (src > lband) then  GlobalColor("Exdn") else
                 if (src < src[1]) and (src <= lband) then  GlobalColor("weakdn") else
                 if (src >= src[1]) and (src < filt) then  GlobalColor("dn") else Color.DARK_GRAY
                 else Color.CURRENT);

#### END
Awesome script Samer800. How would you add an alert for when the channel changes red to green and vice versa? Also to make it appear in a watchlist? Appreciate it.
 
Last edited:
Awesome script Samer800. How would you add an alert for when the channel changes red to green and vice versa? Also to make it appear in a watchlist? Appreciate it.
add the below at the end of the script for signal. For watchlist not sure if possible since it is complex script.

CSS:
input ShowSignal = yes;
AddChartBubble(ShowSignal and fcolor>0 and fcolor[1]<=0, low, "B", Color.GREEN, no);
AddChartBubble(ShowSignal and fcolor<0 and fcolor[1]>=0, high, "S", Color.RED, yes);
 
Would it be possible to convert this TradingView Script to ToS?
https://www.tradingview.com/script/WpVY7GKW-Gaussian-Channel-DW/

I've been using this Gaussian Channel on higher time frames on TradingView for a few months now, and it would be such a life saver if I could use it on ThinkorSwim. I've tried other Gaussian channels, however i've grown too
View attachment 15833
creator messege:
his study is an experiment utilizing the Ehlers Gaussian Filter technique combined with lag reduction techniques and true range to analyze trend activity.
Gaussian filters, as Ehlers explains it, are simply exponential moving averages applied multiple times.
First, beta and alpha are calculated based on the sampling period and number of poles specified. The maximum number of poles available in this script is 9.
Next, the data being analyzed is given a truncation option for reduced lag, which can be enabled with "Reduced Lag Mode".
Then the alpha and source values are used to calculate the filter and filtered true range of the dataset.
Filtered true range with a specified multiplier is then added to and subtracted from the filter, generating a channel.
Lastly, a one pole filter with a N pole alpha is averaged with the filter to generate a faster filter, which can be enabled with "Fast Response Mode".

Custom bar colors are included.

Note: Both the sampling period and number of poles directly affect how much lag the indicator has, and how smooth the output is.
Larger inputs will result in smoother outputs with increased lag, and smaller inputs will have noisier outputs with reduced lag.
For the best results, I recommend not setting the sampling period any lower than the number of poles + 1. Going lower truncates the equation.

Code:

CSS:
#https://www.tradingview.com/script/WpVY7GKW-Gaussian-Channel-DW/
#//@version=4
#study(title="Gaussian Channel [DW]", shorttitle="GC [DW]", overlay=true)
# Request from https://usethinkscript.com/ memeber
# Converted and mod by Sam4Cok@Samer800 - 09/2022
#//------------------------------------------------------
#//Inputs
#//------------------------------------------------------
input BarColor = no;
input ShowChannel = no;
input ShowCloud = yes;
#//Source
input src = hlc3;
#//Poles
input Poles = 4;
#//Period
input SmaplePeriod = 144;    # "Sampling Period"
#//True Range Multiplier
input mult = 1.414;          # "Filtered True Range Multiplier"
#//Lag Reduction
input ReducedLagMode  = no;  # "Reduced Lag Mode"
input FastResponseMode = no; # "Fast Response Mode"

def na = Double.NaN;

########### Color ################
DefineGlobalColor("Exup" , CreateColor(10, 255, 104));
DefineGlobalColor("Weakup" , CreateColor(10, 255, 27));
DefineGlobalColor("up"   , CreateColor(0, 117, 45));
DefineGlobalColor("Exdn" , CreateColor(255, 10, 90));
DefineGlobalColor("weakdn" , CreateColor(255, 10, 17));
DefineGlobalColor("dn" , CreateColor(153, 0, 50)); #

#//Filter function
#f_filt9x (_a, _s, _i) =>
script f_filt9x {
    input _a = close;
    input _s = close;
    input _i = close;
    def na = Double.NaN;
    def _x = (1 - _a);
    def _m2;
    def _m3;
    def _m4;
    def _m5;
    def _m6;
    def _m7;
    def _m8;
    def _m9;
 #   // Initial weight _m1 is a pole number and equal to _i
    _m2 = if IsNaN(_m2[1]) then 0 else
          if _i == 9 then 36 else if _i == 8 then 28 else if _i == 7 then 21 else
          if _i == 6 then 15 else if _i == 5 then 10 else if _i == 4 then 6 else
          if _i == 3 then 3 else if _i == 2 then 1 else 0;
    _m3 = if IsNaN(_m3[1]) then 0 else
          if _i == 9 then 84 else if _i == 8 then 56 else if _i == 7 then 35 else
          if _i == 6 then 20 else if _i == 5 then 10 else if _i == 4 then 4 else
          if _i == 3 then 1 else 0;
    _m4 = if IsNaN(_m4[1]) then 0 else
          if _i == 9 then 126 else if _i == 8 then 70 else if _i == 7 then 35 else
          if _i == 6 then 15 else if _i == 5 then 5  else if _i == 4 then 1 else 0;
    _m5 = if IsNaN(_m5[1]) then 0 else
          if _i == 9 then 126 else if  _i == 8 then 56 else if _i == 7 then 21 else
          if _i == 6 then 6 else if _i == 5 then 1 else 0;
    _m6 = if IsNaN(_m6[1]) then 0 else
          if _i == 9 then 84 else if _i == 8 then 28 else if _i == 7 then 7  else
          if _i == 6 then 1 else 0;
    _m7 = if IsNaN(_m7[1]) then 0 else
          if _i == 9 then 36 else if _i == 8 then 8  else if _i == 7 then 1 else 0;
    _m8 = if IsNaN(_m8[1]) then 0 else
              if _i == 9 then 9 else if _i == 8 then 1 else 0;
    _m9 = if IsNaN(_m9[1]) then 0 else if _i == 9 then 1 else 0;
#    // filter
    def _f = if IsNaN(_f[10*2]) then na else
            Power(_a, _i) * (_s) + _i * _x * (_f[1]) - (if _i >= 2 then
      _m2 * Power(_x, 2)  * (_f[2]) else 0) + (if _i >= 3 then
      _m3 * Power(_x, 3)  * (_f[3]) else 0) - (if _i >= 4 then
      _m4 * Power(_x, 4)  * (_f[4]) else 0) + (if _i >= 5 then
      _m5 * Power(_x, 5)  * (_f[5]) else 0) - (if _i >= 6 then
      _m6 * Power(_x, 6)  * (_f[6]) else 0) + (if _i >= 7 then
      _m7 * Power(_x, 7)  * (_f[7]) else 0) - (if _i >= 8 then
      _m8 * Power(_x, 8)  * (_f[8]) else 0) + (if _i == 9 then
      _m9 * Power(_x, 9)  * (_f[9]) else 0);
    plot return = _f;
}
#//9 var declaration fun
#f_pole (_a, _s, _i) =>
script f_pole {
    input _a = 0;
    input _s = 0;
    input _i = 0;
    def _f1 = f_filt9x(_a, _s, 1);
    def _f2 = (if _i >= 2 then f_filt9x(_a, _s, 2) else 0);
    def _f3 = (if _i >= 3 then f_filt9x(_a, _s, 3) else 0);
    def _f4 = (if _i >= 4 then f_filt9x(_a, _s, 4) else 0);
    def _f5 = (if _i >= 5 then f_filt9x(_a, _s, 5) else 0);
    def _f6 = (if _i >= 6 then f_filt9x(_a, _s, 6) else 0);
    def _f7 = (if _i >= 2 then f_filt9x(_a, _s, 7) else 0);
    def _f8 = (if _i >= 8 then f_filt9x(_a, _s, 8) else 0);
    def _f9 = (if _i == 9 then f_filt9x(_a, _s, 9) else 0);

    def _fn = if _i == 1 then _f1 else if _i == 2 then  _f2 else if _i == 3 then _f3 else
    if _i == 4 then _f4 else if _i == 5 then _f5 else if _i == 6 then _f6 else
    if _i == 7 then _f7 else if _i == 8 then _f8 else if _i == 9 then _f9 else Double.NaN;
    plot filtn = _fn;
    plot filt1 = _f1;
}
# Variables
script g {
    input data = hlc3;
    def w = (2 * Double.Pi / 8);
    def beta =  (1 - Cos(w)) / (Power(1.414, 2.0 / 4) - 1 );
    def alpha = (-beta + Sqrt(beta * beta + 2 * beta));
    def G =      Power(alpha, 4) * data +
                 4 * (1 – alpha) * G[1] – 6 * Power( 1 - alpha, 2 ) * G[2] +
                 4 * Power( 1 - alpha, 3 ) * G[3] - Power( 1 - alpha, 4 ) * G[4];
    plot Line = G;
}
#/------------------------------------------
#//Definitions
#//-----------------------------------------
#//Beta and Alpha Components
def beta  = (1 - Cos(4 * ASin(1) / SmaplePeriod)) / (Power(1.414, 2 / Poles) - 1);
def alpha = - beta + Sqrt(Power(beta, 2) + 2 * beta);

#//Lag
def lag = (SmaplePeriod - 1) / (2 * Poles);
def tr = TrueRange(high, close, low);
#//Data
def srcdata = if ReducedLagMode then src + (src - GetValue(src, lag)) else src;
def trdata  = if ReducedLagMode then tr + tr - GetValue(tr, lag) else tr;

#//Filtered Values
def filtn = f_pole(alpha, srcdata, Poles).filtn;
def filt1 = f_pole(alpha, srcdata, Poles).filt1;
def filtntr = f_pole(alpha, trdata,  Poles).filtn;
def filt1tr = f_pole(alpha, trdata,  Poles).filt1;

#//Lag Reduction
def filt   = if FastResponseMode then (filtn + filt1) / 2 else filtn;
def filttr = if FastResponseMode then (filtntr + filt1tr) / 2 else filtntr;

#//Bands
def hband = filt + filttr * mult;
def lband = filt - filttr * mult;

def fcolor = if filt > filt[1] then 1 else if filt < filt[1] then -1 else 0;
#//line Plots
plot filter = if IsNaN(close) then na else filt;    #"Filter"
filter.SetLineWeight(2);
filter.AssignValueColor(if fcolor > 0 then GlobalColor("Exup") else
                        if fcolor < 0 then GlobalColor("Exdn") else Color.GRAY);
#//Band Plots
plot hbandplot = if ShowChannel and !IsNaN(close) then hband else na;    # "Filtered True Range High Band"
hbandplot.AssignValueColor(if fcolor > 0 then GlobalColor("EXup") else
                           if fcolor < 0 then GlobalColor("Exdn") else Color.GRAY);
plot lbandplot = if ShowChannel and !IsNaN(close) then lband else na;    # "Filtered True Range Low Band"
lbandplot.AssignValueColor(if fcolor > 0 then GlobalColor("Exup") else
                           if fcolor < 0 then GlobalColor("Exdn") else Color.GRAY);

AddCloud(if ShowCloud and !IsNaN(close) and fcolor > 0 then hband else
         if ShowCloud and !IsNaN(close) and fcolor < 0 then lband else na,
         if fcolor > 0 then lband else if fcolor < 0 then hband else na,
          GlobalColor("up"), GlobalColor("dn"));
#//price color Plots

AssignPriceColor(if BarColor then
                 if (src > src[1]) and (src > filt) and (src < hband) then GlobalColor("Exup") else
                 if (src > src[1]) and (src >= hband) then  GlobalColor("weakup") else
                 if (src <= src[1]) and (src > filt) then  GlobalColor("up") else
                 if (src < src[1]) and (src < filt) and (src > lband) then  GlobalColor("Exdn") else
                 if (src < src[1]) and (src <= lband) then  GlobalColor("weakdn") else
                 if (src >= src[1]) and (src < filt) then  GlobalColor("dn") else Color.DARK_GRAY
                 else Color.CURRENT);

#### END

Hi! I need some help. When I am trying to create an alert of GC in Trading View, there are almost 10 types of actions possible. Is there a way to know the purpose of each of them, and the way to use them. Thankyou! I appreciate help in advance.
fond of this script created by DonovanWall.
 
Last edited by a moderator:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
485 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