MACD ReLoaded For ThinkOrSwim

serendipity2020

Member
Plus
Author states:
A different approach to the MACD

Classic MACD uses exponential moving averages.
In this version users can apply 11 different types of moving averages which they can benefit from their smoothness and vice versa sharpnesses...

sOCKtDu.png


Hello @samer800
Would you be able to convert MACD Reloaded TV indicator?
https://www.tradingview.com/script/PhtqdGBM-MACD-ReLoaded/
Appreciate your help!
 
Last edited by a moderator:

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

Hello @samer800

Would you be able to convert MACD Reloaded TV indicator?
https://www.tradingview.com/script/PhtqdGBM-MACD-ReLoaded/

This is alternate approach to Gerald Appel's classical Moving Average Convergence Divergence.

Appreciate your help!
check the below:

CSS:
#//@version=4
#// This source code is subject to the terms of the Mozilla Public License 2.0
#// © KivancOzbilgic
#//developer: Gerald Appel
#//author: @kivancozbilgic
#study("MACD ReLoaded","MACDRe", overlay=false, resolution="")
# Converted by Sam4Cok@Samer800    - 05/2024
declare lower;

input colorBars = yes;
input timeframe = {Default "Chart", "Manual"};
input manualTimeframe = AggregationPeriod.FIFTEEN_MIN;
input displayOptions = { "Histogram", "Lines", Default "Histogram & Lines"};
input MovAvgType = { "SMA", "EMA", "WMA", "DEMA", "TMA", default "VAR", "WWMA", "ZLEMA", "TSF", "HULL", "TILL"};
input Source = FundamentalType.CLOSE; #, title="Source")
input fastLength  = 12; #, "Short Moving Average Length", minval=1)
input slowLength = 26; #, "Long Moving Average Length", minval=1)
input signalLength = 9; #, "Trigger Length", minval=1)
input tillsonT3Factor = 0.7; #, "TILLSON T3 Volume Factor", step=0.1)


def na = Double.NaN;
def last = IsNaN(close);
def showHistogram = displayOptions==displayOptions."Histogram" or displayOptions==displayOptions."Histogram & Lines";
def showLines = displayOptions==displayOptions."Lines" or displayOptions==displayOptions."Histogram & Lines";

def src;
Switch (timeframe) {
Case "Manual":
    src = Fundamental(FundamentalType = Source, Period = manualTimeframe);
Default :
    src = Fundamental(FundamentalType = Source);
}

#-- Colors
DefineGlobalColor("exUp",CreateColor(0, 230, 118));
DefineGlobalColor("Up",  CreateColor(178, 223, 219));
DefineGlobalColor("exDn",CreateColor(239, 83, 80));
DefineGlobalColor("Dn",  CreateColor(255, 205, 210));
DefineGlobalColor("macd",  CreateColor(66, 107, 230));
DefineGlobalColor("signal",  CreateColor(230, 0, 0));
#--- Functions
#pine_linreg(src, len, offset=0) =>
script linreg {
    input src = close;
    input len = 100;
    input offset = 0;
    def na = Double.NaN;
    def bar_index = IsNaN(close);
    def x_sum = if bar_index then na else
                fold i = 0 to len with p do
                 p + i;
    def xx_sum = if bar_index then na else
                fold ii = 0 to len with pp do
                 pp + ii * ii;
    def y_sum = Sum(src, len);
    def xy_sum = fold j = 0 to len with q do
                  q  + j * GetValue(src, len - j - 1);
    def slope = (len * xy_sum - x_sum * y_sum) / (len * xx_sum - x_sum * x_sum);
    def intercept = (y_sum - slope * x_sum) / len;
    def linreg = intercept + slope * (len - offset - 1);
    plot out = linreg;
}
script f_var {
 input src = close;
 input length = 20;
    def alpha = 2/(length + 1);
    def ud1 = if src > src[1] then src - src[1] else 0;
    def dd1 = if src < src[1] then src[1] - src else 0;
    def UD  = sum(ud1, 9);
    def DD  = sum(dd1, 9);
    def vCMO = (UD - DD) / (UD + DD);
    def CMO = if isNaN(vCMO) then 0.0 else AbsValue(vCMO);
    def VAR = (alpha * CMO * src)+(1 - alpha * CMO) * if(isNaN(VAR[1]), 0, VAR[1]);
    plot out = if Length ==1 then src else var;
}
#Wwma_Func(src, length) =>
script Wwma_Func {
    input src = close;
    input length = 2;
    def alpha = 1 / length;
    def WWMA = alpha * src + (1 - alpha) * if(isNaN(WWMA[1]), 0, WWMA[1]);
    plot return = WWMA;
}
#Zlema_Func(src, length) =>
script Zlema_Func {
    input src = close;
    input length = 2;
    def zxLag = if length / 2 == Round(length / 2, 0) then length / 2 else (length - 1) / 2;
    def zxEMAData = src + (src - src[zxLag]);
    def ZLEMA = ExpAverage(zxEMAData, length);
    plot return = ZLEMA;
}
#Tsf_Func(src, length) =>
script Tsf_Func {
    input src = close;
    input length = 2;
    def lrc = Inertia(src, length);
    def lrc1 = linreg(src, length, 1);
    def lrs = lrc - lrc1;
    def TSF = Inertia(src, length) + lrs;
    plot retur = TSF;
}
#Till_Func(src, length) =>
script Till_Func {
    input src = close;
    input length = 2;
    input T3a1 = 0.7;
    def T3e1 = ExpAverage(src, length);
    def T3e2 = ExpAverage(T3e1,length);
    def T3e3 = ExpAverage(T3e2,length);
    def T3e4 = ExpAverage(T3e3,length);
    def T3e5 = ExpAverage(T3e4,length);
    def T3e6 = ExpAverage(T3e5,length);
    def T3c1 = -T3a1*T3a1*T3a1;
    def T3c2 = 3 * T3a1 * T3a1 + 3 * T3a1 * T3a1 * T3a1;
    def T3c3 =-6 * T3a1 * T3a1 - 3 * T3a1 - 3 * T3a1 * T3a1 * T3a1;
    def T3c4 = 1 + 3 * T3a1 + T3a1 * T3a1 * T3a1 + 3 * T3a1 * T3a1;
    def T3 = T3c1 * T3e6 + T3c2 * T3e5 + T3c3 * T3e4 + T3c4 * T3e3;
    plot retur = T3;
}
#ma(src, length, type) =>
script getMA {
    input src = close;
    input length = 80;
    input type   = "SMA";
    input T3a1 = 0.7;
    def ma =
     if type == "SMA"   then Average(src, length) else
     if type == "EMA"   then ExpAverage(src, length) else
     if type == "WMA"   then WMA(src, length) else
     if type == "DEMA"  then DEMA(src, length) else
     if type == "TMA"   then MovAvgTriangular(src, length) else
     if type == "VAR"   then f_var(src, length) else
     if type == "WWMA"  then WWMA_Func(src, length) else
     if type == "ZLEMA" then Zlema_Func(src, length) else
     if type == "TSF"   then Tsf_Func(src, length) else
     if type == "TILL"  then Till_Func(src, length, T3a1) else
     if type == "HULL"  then HullMovingAvg(src, length) else Average(src, length);
    plot result = ma;
}
def MA12 = getMA(src, fastLength, MovAvgType, tillsonT3Factor);
def MA26 = getMA(src, slowLength, MovAvgType, tillsonT3Factor);
def src2 = MA12 - MA26;
def MATR = getMA(src2, signalLength, MovAvgType, tillsonT3Factor);
def hist = src2 - MATR;

#-- Plots
plot MACDRe = if showLines and !last[-1] then src2 else na;      # "MACDRe"
plot Trigger = if showLines and !last then MATR else na;     # "TRIGGER"
plot histo = if showhistogram and !last then hist else na; # "Histogram"
MACDRe.SetLineWeight(2);
Trigger.SetLineWeight(2);
MACDRe.SetDefaultColor(GlobalColor("macd"));
Trigger.SetDefaultColor(GlobalColor("signal"));
histo.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
histo.AssignValueColor(if hist>=0 then (if hist[1] < hist then GlobalColor("exUp") else GlobalColor("Up")) else
                                       (if hist[1] < hist then GlobalColor("Dn") else GlobalColor("exDn")));

AssignPriceColor(if !colorBars then Color.CURRENT else if hist>=0 then
                    (if hist[1] < hist then GlobalColor("exUp") else GlobalColor("Up")) else
                    (if hist[1] < hist then GlobalColor("Dn") else GlobalColor("exDn")));

#-- END of CODE
 
Author states:
A different approach to the MACD

Classic MACD uses exponential moving averages.
In this version users can apply 11 different types of moving averages which they can benefit from their smoothness and vice versa sharpnesses...

sOCKtDu.png


Hello @samer800
Would you be able to convert MACD Reloaded TV indicator?
https://www.tradingview.com/script/PhtqdGBM-MACD-ReLoaded/
Appreciate your help!
Any way to just have the colored bars with same settings without the lower indicator window?

check the below:

CSS:
#//@version=4
#// This source code is subject to the terms of the Mozilla Public License 2.0
#// © KivancOzbilgic
#//developer: Gerald Appel
#//author: @kivancozbilgic
#study("MACD ReLoaded","MACDRe", overlay=false, resolution="")
# Converted by Sam4Cok@Samer800    - 05/2024
declare lower;

input colorBars = yes;
input timeframe = {Default "Chart", "Manual"};
input manualTimeframe = AggregationPeriod.FIFTEEN_MIN;
input displayOptions = { "Histogram", "Lines", Default "Histogram & Lines"};
input MovAvgType = { "SMA", "EMA", "WMA", "DEMA", "TMA", default "VAR", "WWMA", "ZLEMA", "TSF", "HULL", "TILL"};
input Source = FundamentalType.CLOSE; #, title="Source")
input fastLength  = 12; #, "Short Moving Average Length", minval=1)
input slowLength = 26; #, "Long Moving Average Length", minval=1)
input signalLength = 9; #, "Trigger Length", minval=1)
input tillsonT3Factor = 0.7; #, "TILLSON T3 Volume Factor", step=0.1)


def na = Double.NaN;
def last = IsNaN(close);
def showHistogram = displayOptions==displayOptions."Histogram" or displayOptions==displayOptions."Histogram & Lines";
def showLines = displayOptions==displayOptions."Lines" or displayOptions==displayOptions."Histogram & Lines";

def src;
Switch (timeframe) {
Case "Manual":
    src = Fundamental(FundamentalType = Source, Period = manualTimeframe);
Default :
    src = Fundamental(FundamentalType = Source);
}

#-- Colors
DefineGlobalColor("exUp",CreateColor(0, 230, 118));
DefineGlobalColor("Up",  CreateColor(178, 223, 219));
DefineGlobalColor("exDn",CreateColor(239, 83, 80));
DefineGlobalColor("Dn",  CreateColor(255, 205, 210));
DefineGlobalColor("macd",  CreateColor(66, 107, 230));
DefineGlobalColor("signal",  CreateColor(230, 0, 0));
#--- Functions
#pine_linreg(src, len, offset=0) =>
script linreg {
    input src = close;
    input len = 100;
    input offset = 0;
    def na = Double.NaN;
    def bar_index = IsNaN(close);
    def x_sum = if bar_index then na else
                fold i = 0 to len with p do
                 p + i;
    def xx_sum = if bar_index then na else
                fold ii = 0 to len with pp do
                 pp + ii * ii;
    def y_sum = Sum(src, len);
    def xy_sum = fold j = 0 to len with q do
                  q  + j * GetValue(src, len - j - 1);
    def slope = (len * xy_sum - x_sum * y_sum) / (len * xx_sum - x_sum * x_sum);
    def intercept = (y_sum - slope * x_sum) / len;
    def linreg = intercept + slope * (len - offset - 1);
    plot out = linreg;
}
script f_var {
 input src = close;
 input length = 20;
    def alpha = 2/(length + 1);
    def ud1 = if src > src[1] then src - src[1] else 0;
    def dd1 = if src < src[1] then src[1] - src else 0;
    def UD  = sum(ud1, 9);
    def DD  = sum(dd1, 9);
    def vCMO = (UD - DD) / (UD + DD);
    def CMO = if isNaN(vCMO) then 0.0 else AbsValue(vCMO);
    def VAR = (alpha * CMO * src)+(1 - alpha * CMO) * if(isNaN(VAR[1]), 0, VAR[1]);
    plot out = if Length ==1 then src else var;
}
#Wwma_Func(src, length) =>
script Wwma_Func {
    input src = close;
    input length = 2;
    def alpha = 1 / length;
    def WWMA = alpha * src + (1 - alpha) * if(isNaN(WWMA[1]), 0, WWMA[1]);
    plot return = WWMA;
}
#Zlema_Func(src, length) =>
script Zlema_Func {
    input src = close;
    input length = 2;
    def zxLag = if length / 2 == Round(length / 2, 0) then length / 2 else (length - 1) / 2;
    def zxEMAData = src + (src - src[zxLag]);
    def ZLEMA = ExpAverage(zxEMAData, length);
    plot return = ZLEMA;
}
#Tsf_Func(src, length) =>
script Tsf_Func {
    input src = close;
    input length = 2;
    def lrc = Inertia(src, length);
    def lrc1 = linreg(src, length, 1);
    def lrs = lrc - lrc1;
    def TSF = Inertia(src, length) + lrs;
    plot retur = TSF;
}
#Till_Func(src, length) =>
script Till_Func {
    input src = close;
    input length = 2;
    input T3a1 = 0.7;
    def T3e1 = ExpAverage(src, length);
    def T3e2 = ExpAverage(T3e1,length);
    def T3e3 = ExpAverage(T3e2,length);
    def T3e4 = ExpAverage(T3e3,length);
    def T3e5 = ExpAverage(T3e4,length);
    def T3e6 = ExpAverage(T3e5,length);
    def T3c1 = -T3a1*T3a1*T3a1;
    def T3c2 = 3 * T3a1 * T3a1 + 3 * T3a1 * T3a1 * T3a1;
    def T3c3 =-6 * T3a1 * T3a1 - 3 * T3a1 - 3 * T3a1 * T3a1 * T3a1;
    def T3c4 = 1 + 3 * T3a1 + T3a1 * T3a1 * T3a1 + 3 * T3a1 * T3a1;
    def T3 = T3c1 * T3e6 + T3c2 * T3e5 + T3c3 * T3e4 + T3c4 * T3e3;
    plot retur = T3;
}
#ma(src, length, type) =>
script getMA {
    input src = close;
    input length = 80;
    input type   = "SMA";
    input T3a1 = 0.7;
    def ma =
     if type == "SMA"   then Average(src, length) else
     if type == "EMA"   then ExpAverage(src, length) else
     if type == "WMA"   then WMA(src, length) else
     if type == "DEMA"  then DEMA(src, length) else
     if type == "TMA"   then MovAvgTriangular(src, length) else
     if type == "VAR"   then f_var(src, length) else
     if type == "WWMA"  then WWMA_Func(src, length) else
     if type == "ZLEMA" then Zlema_Func(src, length) else
     if type == "TSF"   then Tsf_Func(src, length) else
     if type == "TILL"  then Till_Func(src, length, T3a1) else
     if type == "HULL"  then HullMovingAvg(src, length) else Average(src, length);
    plot result = ma;
}
def MA12 = getMA(src, fastLength, MovAvgType, tillsonT3Factor);
def MA26 = getMA(src, slowLength, MovAvgType, tillsonT3Factor);
def src2 = MA12 - MA26;
def MATR = getMA(src2, signalLength, MovAvgType, tillsonT3Factor);
def hist = src2 - MATR;

#-- Plots
plot MACDRe = if showLines and !last[-1] then src2 else na;      # "MACDRe"
plot Trigger = if showLines and !last then MATR else na;     # "TRIGGER"
plot histo = if showhistogram and !last then hist else na; # "Histogram"
MACDRe.SetLineWeight(2);
Trigger.SetLineWeight(2);
MACDRe.SetDefaultColor(GlobalColor("macd"));
Trigger.SetDefaultColor(GlobalColor("signal"));
histo.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
histo.AssignValueColor(if hist>=0 then (if hist[1] < hist then GlobalColor("exUp") else GlobalColor("Up")) else
                                       (if hist[1] < hist then GlobalColor("Dn") else GlobalColor("exDn")));

AssignPriceColor(if !colorBars then Color.CURRENT else if hist>=0 then
                    (if hist[1] < hist then GlobalColor("exUp") else GlobalColor("Up")) else
                    (if hist[1] < hist then GlobalColor("Dn") else GlobalColor("exDn")));

#-- END of CODE
Any way to just have the colored bars with same settings without the lower indicator window?
 
Any way to just have the colored bars with same settings without the lower indicator window?


Any way to just have the colored bars with same settings without the lower indicator window?
check the below:

CSS:
#//@version=4
#// This source code is subject to the terms of the Mozilla Public License 2.0
#// © KivancOzbilgic
#//developer: Gerald Appel
#//author: @kivancozbilgic
#study("MACD ReLoaded","MACDRe", overlay=false, resolution="")
# Converted by Sam4Cok@Samer800    - 05/2024
# -- Upper Study by Sam4Cok@Samer800     - 05/2024

input colorBars = yes;
input timeframe = {Default "Chart", "Manual"};
input manualTimeframe = AggregationPeriod.FIFTEEN_MIN;
input MovAvgType = { "SMA", "EMA", "WMA", "DEMA", "TMA", default "VAR", "WWMA", "ZLEMA", "TSF", "HULL", "TILL"};
input Source = FundamentalType.CLOSE; #, title="Source")
input fastLength  = 12; #, "Short Moving Average Length", minval=1)
input slowLength = 26; #, "Long Moving Average Length", minval=1)
input signalLength = 9; #, "Trigger Length", minval=1)
input tillsonT3Factor = 0.7; #, "TILLSON T3 Volume Factor", step=0.1)

def na = Double.NaN;

def src;
Switch (timeframe) {
Case "Manual":
    src = Fundamental(FundamentalType = Source, Period = manualTimeframe);
Default :
    src = Fundamental(FundamentalType = Source);
}

#-- Colors
DefineGlobalColor("exUp",CreateColor(0, 230, 118));
DefineGlobalColor("Up",  CreateColor(178, 223, 219));
DefineGlobalColor("exDn",CreateColor(239, 83, 80));
DefineGlobalColor("Dn",  CreateColor(255, 205, 210));
DefineGlobalColor("macd",  CreateColor(66, 107, 230));
DefineGlobalColor("signal",  CreateColor(230, 0, 0));
#--- Functions
#pine_linreg(src, len, offset=0) =>
script linreg {
    input src = close;
    input len = 100;
    input offset = 0;
    def na = Double.NaN;
    def bar_index = IsNaN(close);
    def x_sum = if bar_index then na else
                fold i = 0 to len with p do
                 p + i;
    def xx_sum = if bar_index then na else
                fold ii = 0 to len with pp do
                 pp + ii * ii;
    def y_sum = Sum(src, len);
    def xy_sum = fold j = 0 to len with q do
                  q  + j * GetValue(src, len - j - 1);
    def slope = (len * xy_sum - x_sum * y_sum) / (len * xx_sum - x_sum * x_sum);
    def intercept = (y_sum - slope * x_sum) / len;
    def linreg = intercept + slope * (len - offset - 1);
    plot out = linreg;
}
script f_var {
 input src = close;
 input length = 20;
    def alpha = 2/(length + 1);
    def ud1 = if src > src[1] then src - src[1] else 0;
    def dd1 = if src < src[1] then src[1] - src else 0;
    def UD  = sum(ud1, 9);
    def DD  = sum(dd1, 9);
    def vCMO = (UD - DD) / (UD + DD);
    def CMO = if isNaN(vCMO) then 0.0 else AbsValue(vCMO);
    def VAR = (alpha * CMO * src)+(1 - alpha * CMO) * if(isNaN(VAR[1]), 0, VAR[1]);
    plot out = if Length ==1 then src else var;
}
#Wwma_Func(src, length) =>
script Wwma_Func {
    input src = close;
    input length = 2;
    def alpha = 1 / length;
    def WWMA = alpha * src + (1 - alpha) * if(isNaN(WWMA[1]), 0, WWMA[1]);
    plot return = WWMA;
}
#Zlema_Func(src, length) =>
script Zlema_Func {
    input src = close;
    input length = 2;
    def zxLag = if length / 2 == Round(length / 2, 0) then length / 2 else (length - 1) / 2;
    def zxEMAData = src + (src - src[zxLag]);
    def ZLEMA = ExpAverage(zxEMAData, length);
    plot return = ZLEMA;
}
#Tsf_Func(src, length) =>
script Tsf_Func {
    input src = close;
    input length = 2;
    def lrc = Inertia(src, length);
    def lrc1 = linreg(src, length, 1);
    def lrs = lrc - lrc1;
    def TSF = Inertia(src, length) + lrs;
    plot retur = TSF;
}
#Till_Func(src, length) =>
script Till_Func {
    input src = close;
    input length = 2;
    input T3a1 = 0.7;
    def T3e1 = ExpAverage(src, length);
    def T3e2 = ExpAverage(T3e1,length);
    def T3e3 = ExpAverage(T3e2,length);
    def T3e4 = ExpAverage(T3e3,length);
    def T3e5 = ExpAverage(T3e4,length);
    def T3e6 = ExpAverage(T3e5,length);
    def T3c1 = -T3a1*T3a1*T3a1;
    def T3c2 = 3 * T3a1 * T3a1 + 3 * T3a1 * T3a1 * T3a1;
    def T3c3 =-6 * T3a1 * T3a1 - 3 * T3a1 - 3 * T3a1 * T3a1 * T3a1;
    def T3c4 = 1 + 3 * T3a1 + T3a1 * T3a1 * T3a1 + 3 * T3a1 * T3a1;
    def T3 = T3c1 * T3e6 + T3c2 * T3e5 + T3c3 * T3e4 + T3c4 * T3e3;
    plot retur = T3;
}
#ma(src, length, type) =>
script getMA {
    input src = close;
    input length = 80;
    input type   = "SMA";
    input T3a1 = 0.7;
    def ma =
     if type == "SMA"   then Average(src, length) else
     if type == "EMA"   then ExpAverage(src, length) else
     if type == "WMA"   then WMA(src, length) else
     if type == "DEMA"  then DEMA(src, length) else
     if type == "TMA"   then MovAvgTriangular(src, length) else
     if type == "VAR"   then f_var(src, length) else
     if type == "WWMA"  then WWMA_Func(src, length) else
     if type == "ZLEMA" then Zlema_Func(src, length) else
     if type == "TSF"   then Tsf_Func(src, length) else
     if type == "TILL"  then Till_Func(src, length, T3a1) else
     if type == "HULL"  then HullMovingAvg(src, length) else Average(src, length);
    plot result = ma;
}
def MA12 = getMA(src, fastLength, MovAvgType, tillsonT3Factor);
def MA26 = getMA(src, slowLength, MovAvgType, tillsonT3Factor);
def src2 = MA12 - MA26;
def MATR = getMA(src2, signalLength, MovAvgType, tillsonT3Factor);
def hist = src2 - MATR;

AssignPriceColor(if !colorBars then Color.CURRENT else if hist>=0 then
                    (if hist[1] < hist then GlobalColor("exUp") else GlobalColor("Up")) else
                    (if hist[1] < hist then GlobalColor("Dn") else GlobalColor("exDn")));

#-- END of CODE
 
check the below:

CSS:
#//@version=4
#// This source code is subject to the terms of the Mozilla Public License 2.0
#// © KivancOzbilgic
#//developer: Gerald Appel
#//author: @kivancozbilgic
#study("MACD ReLoaded","MACDRe", overlay=false, resolution="")
# Converted by Sam4Cok@Samer800    - 05/2024
# -- Upper Study by Sam4Cok@Samer800     - 05/2024

input colorBars = yes;
input timeframe = {Default "Chart", "Manual"};
input manualTimeframe = AggregationPeriod.FIFTEEN_MIN;
input MovAvgType = { "SMA", "EMA", "WMA", "DEMA", "TMA", default "VAR", "WWMA", "ZLEMA", "TSF", "HULL", "TILL"};
input Source = FundamentalType.CLOSE; #, title="Source")
input fastLength  = 12; #, "Short Moving Average Length", minval=1)
input slowLength = 26; #, "Long Moving Average Length", minval=1)
input signalLength = 9; #, "Trigger Length", minval=1)
input tillsonT3Factor = 0.7; #, "TILLSON T3 Volume Factor", step=0.1)

def na = Double.NaN;

def src;
Switch (timeframe) {
Case "Manual":
    src = Fundamental(FundamentalType = Source, Period = manualTimeframe);
Default :
    src = Fundamental(FundamentalType = Source);
}

#-- Colors
DefineGlobalColor("exUp",CreateColor(0, 230, 118));
DefineGlobalColor("Up",  CreateColor(178, 223, 219));
DefineGlobalColor("exDn",CreateColor(239, 83, 80));
DefineGlobalColor("Dn",  CreateColor(255, 205, 210));
DefineGlobalColor("macd",  CreateColor(66, 107, 230));
DefineGlobalColor("signal",  CreateColor(230, 0, 0));
#--- Functions
#pine_linreg(src, len, offset=0) =>
script linreg {
    input src = close;
    input len = 100;
    input offset = 0;
    def na = Double.NaN;
    def bar_index = IsNaN(close);
    def x_sum = if bar_index then na else
                fold i = 0 to len with p do
                 p + i;
    def xx_sum = if bar_index then na else
                fold ii = 0 to len with pp do
                 pp + ii * ii;
    def y_sum = Sum(src, len);
    def xy_sum = fold j = 0 to len with q do
                  q  + j * GetValue(src, len - j - 1);
    def slope = (len * xy_sum - x_sum * y_sum) / (len * xx_sum - x_sum * x_sum);
    def intercept = (y_sum - slope * x_sum) / len;
    def linreg = intercept + slope * (len - offset - 1);
    plot out = linreg;
}
script f_var {
 input src = close;
 input length = 20;
    def alpha = 2/(length + 1);
    def ud1 = if src > src[1] then src - src[1] else 0;
    def dd1 = if src < src[1] then src[1] - src else 0;
    def UD  = sum(ud1, 9);
    def DD  = sum(dd1, 9);
    def vCMO = (UD - DD) / (UD + DD);
    def CMO = if isNaN(vCMO) then 0.0 else AbsValue(vCMO);
    def VAR = (alpha * CMO * src)+(1 - alpha * CMO) * if(isNaN(VAR[1]), 0, VAR[1]);
    plot out = if Length ==1 then src else var;
}
#Wwma_Func(src, length) =>
script Wwma_Func {
    input src = close;
    input length = 2;
    def alpha = 1 / length;
    def WWMA = alpha * src + (1 - alpha) * if(isNaN(WWMA[1]), 0, WWMA[1]);
    plot return = WWMA;
}
#Zlema_Func(src, length) =>
script Zlema_Func {
    input src = close;
    input length = 2;
    def zxLag = if length / 2 == Round(length / 2, 0) then length / 2 else (length - 1) / 2;
    def zxEMAData = src + (src - src[zxLag]);
    def ZLEMA = ExpAverage(zxEMAData, length);
    plot return = ZLEMA;
}
#Tsf_Func(src, length) =>
script Tsf_Func {
    input src = close;
    input length = 2;
    def lrc = Inertia(src, length);
    def lrc1 = linreg(src, length, 1);
    def lrs = lrc - lrc1;
    def TSF = Inertia(src, length) + lrs;
    plot retur = TSF;
}
#Till_Func(src, length) =>
script Till_Func {
    input src = close;
    input length = 2;
    input T3a1 = 0.7;
    def T3e1 = ExpAverage(src, length);
    def T3e2 = ExpAverage(T3e1,length);
    def T3e3 = ExpAverage(T3e2,length);
    def T3e4 = ExpAverage(T3e3,length);
    def T3e5 = ExpAverage(T3e4,length);
    def T3e6 = ExpAverage(T3e5,length);
    def T3c1 = -T3a1*T3a1*T3a1;
    def T3c2 = 3 * T3a1 * T3a1 + 3 * T3a1 * T3a1 * T3a1;
    def T3c3 =-6 * T3a1 * T3a1 - 3 * T3a1 - 3 * T3a1 * T3a1 * T3a1;
    def T3c4 = 1 + 3 * T3a1 + T3a1 * T3a1 * T3a1 + 3 * T3a1 * T3a1;
    def T3 = T3c1 * T3e6 + T3c2 * T3e5 + T3c3 * T3e4 + T3c4 * T3e3;
    plot retur = T3;
}
#ma(src, length, type) =>
script getMA {
    input src = close;
    input length = 80;
    input type   = "SMA";
    input T3a1 = 0.7;
    def ma =
     if type == "SMA"   then Average(src, length) else
     if type == "EMA"   then ExpAverage(src, length) else
     if type == "WMA"   then WMA(src, length) else
     if type == "DEMA"  then DEMA(src, length) else
     if type == "TMA"   then MovAvgTriangular(src, length) else
     if type == "VAR"   then f_var(src, length) else
     if type == "WWMA"  then WWMA_Func(src, length) else
     if type == "ZLEMA" then Zlema_Func(src, length) else
     if type == "TSF"   then Tsf_Func(src, length) else
     if type == "TILL"  then Till_Func(src, length, T3a1) else
     if type == "HULL"  then HullMovingAvg(src, length) else Average(src, length);
    plot result = ma;
}
def MA12 = getMA(src, fastLength, MovAvgType, tillsonT3Factor);
def MA26 = getMA(src, slowLength, MovAvgType, tillsonT3Factor);
def src2 = MA12 - MA26;
def MATR = getMA(src2, signalLength, MovAvgType, tillsonT3Factor);
def hist = src2 - MATR;

AssignPriceColor(if !colorBars then Color.CURRENT else if hist>=0 then
                    (if hist[1] < hist then GlobalColor("exUp") else GlobalColor("Up")) else
                    (if hist[1] < hist then GlobalColor("Dn") else GlobalColor("exDn")));

#-- END of CODE
Wow this is great and helps alot....thank you SO MUCH!
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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