Repaints MTF MACD Overlay Cypher For ThinkOrSwim

Repaints

TraderZen

Member
MACD diverges after an agresive breakout or breakdown.
Some traders change the fast and slow periods but that causes early reversal signals.
This is an alternative approach.

Approach: MTF MACD Overlay Cypher.
Features:
1) Overlays 1,5 and 15 bar MACDs.
2) Calculates and shows Combined Resultant-MACD line and prompts.

Notes:
White area shows momentum.
Clouds can be turned on/off.
Resultant MACD Line can be turned on/off
1 bar - Cyan/Magenta
5 bar - Green/Red
15 bar - Uptick/DownTick
Squares = Prompts on the Resultant Line.
Resultant Channel = Shade of Blue/Share of Magenta

TTwCQ6U.jpg


vKKQHpt.jpg


Code:
# MTF_MACD_Overlay_Cypher

declare lower;

input ShowClouds = Yes;
input ShowSignalLine = Yes;
input ShowVerticalLines = No;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;

input nightSessionFromMidnight = 0100; # 0100;
Input PreMkt = 730;
input firstHourTrading = 930;
input mainSession = 1030;
input nightSessionFromMainSessionEnd = 1615;
input MainSessionEnd = 1600; # RB Code
input paintBars =  no;

def isNightSessionFromMidnight = SecondsFromTime(nightSessionFromMidnight) >= 0 and SecondsTillTime(firstHourTrading) > 0;
def isDaySessionFromStart = secondsFromTime(FirstHourTrading) >= 0 and SecondsTillTime(MainSession) >= 0;
def isFirstHourTrading = SecondsFromTime(firstHourTrading) >= 0 and SecondsTillTime(mainSession) > 0;
def isPreMkt = SecondsFromTime(PreMkt) >= 0 and SecondsTillTime(FirstHourTrading) > 0;
def isMainSession = SecondsFromTime(MainSession) >= 0 and SecondsTillTime(MainSessionEnd) > 0;

def newNightSessionFromMidnight = isNightSessionFromMidnight and !isNightSessionFromMidnight[1];
def newMainSessionFromSessionStart = isDaySessionFromStart and !isDaySessionFromStart[1]; # RB Code

def C_Val = if IspreMkt then close else if IsDaySessionFromStart then Close else if isMainSession then close else double.nan;

script f_MACD {
    input DataPoint = close;
    input fastLength = 12;
    input slowLength = 26;
    input MACDLength = 9;
    input averageType = AverageType.EXPONENTIAL;
    input showBreakoutSignals = no;
    plot Value = MovingAverage(averageType, DataPoint, fastLength) - MovingAverage(averageType, DataPoint, slowLength);
    plot Avg = MovingAverage(averageType, Value, MACDLength);
    plot Diff = Value - Avg;
   
    }


def MACD_1_value = f_MACD(DataPoint = c_val, fastLength = FastLength, slowLength = SlowLength, MACDLength = MACDLength).value;
def MACD_1_Avg = f_MACD(DataPoint = c_val, fastLength = FastLength, slowLength = SlowLength, MACDLength = MACDLength).Avg;
def macd_1_diff = f_MACD(DataPoint = c_val, fastLength = FastLength, slowLength = SlowLength, MACDLength = MACDLength).diff;

def MACD_5_Value = f_MACD(DataPoint = c_Val, fastLength = FastLength*5, slowLength = SlowLength*5, MACDLength = MACDLength*5).value;
def MACD_5_Avg = f_MACD(DataPoint = c_Val, fastLength = FastLength*5, slowLength = SlowLength*5, MACDLength = MACDLength*5).Avg;
def macd_5_diff = f_MACD(DataPoint = c_val, fastLength = FastLength*5, slowLength = SlowLength*5, MACDLength = MACDLength*5).diff;

def MACD_15_Value = f_MACD(DataPoint = c_Val, fastLength = FastLength*15, slowLength = SlowLength*15, MACDLength = MACDLength*15).value;
def MACD_15_Avg = f_MACD(DataPoint = c_Val, fastLength = FastLength*15, slowLength = SlowLength*15, MACDLength = MACDLength*15).Avg;
def macd_15_diff = f_MACD(DataPoint = c_val, fastLength = FastLength*15, slowLength = SlowLength*15, MACDLength = MACDLength*15).diff;

Plot Hz = 0;
Plot MACD_1_Value_P = MACD_1_Value;
Plot MACD_1_Avg_P = MACD_1_Avg;
Plot MACD_5_Value_P = MACD_5_Value;
Plot MACD_5_Avg_P = MACD_5_Avg;
Plot MACD_15_Value_P = MACD_15_Value;
Plot MACD_15_Avg_P = MACD_15_Avg;
MACD_1_Value_P.hide();
MACD_1_Avg_P.hide();
MACD_5_Value_P.hide();
MACD_5_Avg_P.hide();
MACD_15_Value_P.hide();
MACD_15_Avg_P.hide();


plot T_Value = if showSignalLine then (macd_1_value + macd_5_value + macd_15_value) else Double.nan;
PLot T_Avg =   if showSignalLine then macd_1_avg + macd_5_avg + macd_15_avg else double.nan;
plot T_Diff = (macd_1_diff + macd_5_diff + macd_15_diff);

T_diff.assignValueColor(color.white);

plot T_valueC = if ShowClouds then  T_value else double.nan;
plot T_AvgC = if showClouds then T_Avg else double.nan;
plot T_DiffC = if showClouds then T_Diff else double.nan;
plot MACD_15_ValueC = if ShowClouds then MACD_15_Value else double.nan;
plot MACD_5_ValueC = if ShowClouds then MACD_5_Value else double.nan;
plot MACD_1_ValueC = if ShowClouds then MACD_1_Value else double.nan;
plot MACD_15_AvgC = if ShowClouds then MACD_15_Avg else double.nan;
plot MACD_5_AvgC = if ShowClouds then MACD_5_Avg else double.nan;
plot MACD_1_AvgC = if ShowClouds then MACD_1_Avg else double.nan;

T_valueC.Hide();
T_AvgC.Hide();
T_DiffC.Hide();
MACD_15_ValueC.Hide();
MACD_5_ValueC.Hide();
MACD_1_ValueC.Hide();
MACD_15_AvgC.Hide();
MACD_5_AvgC.Hide();
MACD_1_AvgC.Hide();


#Addcloud(T_value, T_Avg, GetColor(6), GetColor(5));
Addcloud(T_valueC, T_AvgC, CreateColor(51,153,255), CreateColor(255,51,153));
Addcloud(T_DiffC,Hz, Color.White,Color.White,yes);
AddCloud(MACD_15_Value,MACD_15_AVGC,color.uptick,color.downtick);
AddCloud(MACD_5_ValueC,MACD_5_AVGC,color.green,color.red);
AddCloud(MACD_1_ValueC,MACD_1_AvgC,Color.Cyan,Color.Magenta);

Def x = T_value;

#Condition set-1
Def up_1 = if x crosses above min(macd_1_value, min( macd_5_value, macd_15_value)) then x else double.nan;
plot Up1 = up_1;
up1.SetPaintingStrategy(PaintingStrategy.SQUARES);
up1.AssignValueColor(color.green);
up1.SetLineWeight(5);
Def Dn_3 = if x crosses below min(macd_1_value,min(macd_5_value,macd_15_value)) then x else double.nan;
plot DN3 = if (Dn_3 != Dn_3[1] ) then Dn_3 else double.nan;
dn3.SetPaintingStrategy(PaintingStrategy.SQUARES);
dn3.AssignValueColor(color.red);
dn3.SetLineWeight(5);

#Condition set-2
Def up_3 = if x crosses above max(macd_1_value,max(macd_5_value,macd_15_value)) then x else double.nan;
plot up3 = up_3;
up3.SetPaintingStrategy(PaintingStrategy.SQUARES);
up3.AssignValueColor(color.green);
up3.SetLineWeight(5);
Def Dn_1 = if x crosses below max(macd_1_value,max(macd_5_value,macd_15_value)) then x else double.nan;
plot DN1 = Dn_1;
dn1.SetPaintingStrategy(PaintingStrategy.SQUARES);
dn1.AssignValueColor(color.red);
dn1.SetLineWeight(5);

#Condition set-3
Def Dn_2 = if x crosses below MovingAverage(averageType.weighted, x,5) then x else double.nan;
plot DN2 = Dn_2;
dn2.SetPaintingStrategy(PaintingStrategy.SQUARES);
dn2.AssignValueColor(color.red);
dn2.SetLineWeight(5);
Def Up_2 = if x crosses above MovingAverage(averageType.weighted, x,5) then x else double.nan;
plot UP2 = UP_2;
UP2.SetPaintingStrategy(PaintingStrategy.SQUARES);
UP2.AssignValueColor(color.green);
UP2.SetLineWeight(5);


T_Value.assignvalueColor( if x > MovingAverage(averageType.weighted, x,5) then Color.Dark_green else
                    if X < MovingAverage(averageType.weighted, x,5) then color.Dark_red else
                    if x < min(macd_1_value,min(macd_5_value,macd_15_value)) then color.Dark_red else
                    if x > max(macd_1_value,max(macd_5_value,macd_15_value)) then color.Dark_green else    
                   color.yellow);


T_value.SetPaintingStrategy(PaintingStrategy.LINE);
T_value.setLineWeight(2);


T_Avg.assignvalueColor( if T_AVg > MovingAverage(averageType.weighted, T_AVg,5) then getcolor(6) else
                    if T_AVg < MovingAverage(averageType.weighted,T_Avg ,5) then getcolor(5) else
                    if T_AVg < min(macd_1_Avg,min(macd_5_Avg,macd_15_Avg)) then getcolor(5) else
                    if T_AVg > max(macd_1_Avg,max(macd_5_Avg,macd_15_Avg)) then getcolor(6) else    
                   color.yellow);

T_Avg.SetPaintingStrategy(PaintingStrategy.LINE);
HZ.AssignValueColor(Color.White);


Def up_signal = if ( x crosses above min(macd_1_value, min( macd_5_value, macd_15_value)) or
                      x crosses above max(macd_1_value,max(macd_5_value,macd_15_value)) or  
                      x crosses above MovingAverage(averageType.weighted, x,5)) then 1 else double.nan;
AddVerticalLine( showVerticalLines and Up_Signal == 1,"", Color.UpTick, Curve.SHORT_DASH);


def dn_Signal = if ( x crosses below min(macd_1_value, min( macd_5_value, macd_15_value)) or
                      x crosses below max(macd_1_value,max(macd_5_value,macd_15_value)) or  
                      x crosses below MovingAverage(averageType.weighted, x,5)) then 1 else double.nan;

AddVerticalLine( showVerticalLines and dn_signal == 1,"", Color.DOWNTICK, Curve.SHORT_DASH);

#plot Dot = if macd_1_value crosses below movingAverage(AverageType.Weighted, macd_1_value,3) then  macd_1_value else double.NaN;
#Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
#Dot.AssignValueColor(color.light_red);
#Dot.SetLineWeight(2);

#plot Dot2 = if macd_1_value crosses above movingAverage(AverageType.Weighted, macd_1_value,3) then macd_1_value else double.NaN;
#Dot2.SetPaintingStrategy(PaintingStrategy.points);
#Dot2.AssignValueColor(color.light_green);
#Dot2.SetLineWeight(2);

#End
 
MACD diverges after an agresive breakout or breakdown.
Some traders change the fast and slow periods but that causes early reversal signals.
This is an alternative approach.

Approach: MTF MACD Overlay Cypher.
Features:
1) Overlays 1,5 and 15 bar MACDs.
2) Calculates and shows Combined Resultant-MACD line and prompts.

Notes:
White area shows momentum.
Clouds can be turned on/off.
Resultant MACD Line can be turned on/off
1 bar - Cyan/Magenta
5 bar - Green/Red
15 bar - Uptick/DownTick
Squares = Prompts on the Resultant Line.
Resultant Channel = Shade of Blue/Share of Magenta

TTwCQ6U.jpg


vKKQHpt.jpg


Code:
# MTF_MACD_Overlay_Cypher

declare lower;

input ShowClouds = Yes;
input ShowSignalLine = Yes;
input ShowVerticalLines = No;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;

input nightSessionFromMidnight = 0100; # 0100;
Input PreMkt = 730;
input firstHourTrading = 930;
input mainSession = 1030;
input nightSessionFromMainSessionEnd = 1615;
input MainSessionEnd = 1600; # RB Code
input paintBars =  no;

def isNightSessionFromMidnight = SecondsFromTime(nightSessionFromMidnight) >= 0 and SecondsTillTime(firstHourTrading) > 0;
def isDaySessionFromStart = secondsFromTime(FirstHourTrading) >= 0 and SecondsTillTime(MainSession) >= 0;
def isFirstHourTrading = SecondsFromTime(firstHourTrading) >= 0 and SecondsTillTime(mainSession) > 0;
def isPreMkt = SecondsFromTime(PreMkt) >= 0 and SecondsTillTime(FirstHourTrading) > 0;
def isMainSession = SecondsFromTime(MainSession) >= 0 and SecondsTillTime(MainSessionEnd) > 0;

def newNightSessionFromMidnight = isNightSessionFromMidnight and !isNightSessionFromMidnight[1];
def newMainSessionFromSessionStart = isDaySessionFromStart and !isDaySessionFromStart[1]; # RB Code

def C_Val = if IspreMkt then close else if IsDaySessionFromStart then Close else if isMainSession then close else double.nan;

script f_MACD {
    input DataPoint = close;
    input fastLength = 12;
    input slowLength = 26;
    input MACDLength = 9;
    input averageType = AverageType.EXPONENTIAL;
    input showBreakoutSignals = no;
    plot Value = MovingAverage(averageType, DataPoint, fastLength) - MovingAverage(averageType, DataPoint, slowLength);
    plot Avg = MovingAverage(averageType, Value, MACDLength);
    plot Diff = Value - Avg;
  
    }


def MACD_1_value = f_MACD(DataPoint = c_val, fastLength = FastLength, slowLength = SlowLength, MACDLength = MACDLength).value;
def MACD_1_Avg = f_MACD(DataPoint = c_val, fastLength = FastLength, slowLength = SlowLength, MACDLength = MACDLength).Avg;
def macd_1_diff = f_MACD(DataPoint = c_val, fastLength = FastLength, slowLength = SlowLength, MACDLength = MACDLength).diff;

def MACD_5_Value = f_MACD(DataPoint = c_Val, fastLength = FastLength*5, slowLength = SlowLength*5, MACDLength = MACDLength*5).value;
def MACD_5_Avg = f_MACD(DataPoint = c_Val, fastLength = FastLength*5, slowLength = SlowLength*5, MACDLength = MACDLength*5).Avg;
def macd_5_diff = f_MACD(DataPoint = c_val, fastLength = FastLength*5, slowLength = SlowLength*5, MACDLength = MACDLength*5).diff;

def MACD_15_Value = f_MACD(DataPoint = c_Val, fastLength = FastLength*15, slowLength = SlowLength*15, MACDLength = MACDLength*15).value;
def MACD_15_Avg = f_MACD(DataPoint = c_Val, fastLength = FastLength*15, slowLength = SlowLength*15, MACDLength = MACDLength*15).Avg;
def macd_15_diff = f_MACD(DataPoint = c_val, fastLength = FastLength*15, slowLength = SlowLength*15, MACDLength = MACDLength*15).diff;

Plot Hz = 0;
Plot MACD_1_Value_P = MACD_1_Value;
Plot MACD_1_Avg_P = MACD_1_Avg;
Plot MACD_5_Value_P = MACD_5_Value;
Plot MACD_5_Avg_P = MACD_5_Avg;
Plot MACD_15_Value_P = MACD_15_Value;
Plot MACD_15_Avg_P = MACD_15_Avg;
MACD_1_Value_P.hide();
MACD_1_Avg_P.hide();
MACD_5_Value_P.hide();
MACD_5_Avg_P.hide();
MACD_15_Value_P.hide();
MACD_15_Avg_P.hide();


plot T_Value = if showSignalLine then (macd_1_value + macd_5_value + macd_15_value) else Double.nan;
PLot T_Avg =   if showSignalLine then macd_1_avg + macd_5_avg + macd_15_avg else double.nan;
plot T_Diff = (macd_1_diff + macd_5_diff + macd_15_diff);

T_diff.assignValueColor(color.white);

plot T_valueC = if ShowClouds then  T_value else double.nan;
plot T_AvgC = if showClouds then T_Avg else double.nan;
plot T_DiffC = if showClouds then T_Diff else double.nan;
plot MACD_15_ValueC = if ShowClouds then MACD_15_Value else double.nan;
plot MACD_5_ValueC = if ShowClouds then MACD_5_Value else double.nan;
plot MACD_1_ValueC = if ShowClouds then MACD_1_Value else double.nan;
plot MACD_15_AvgC = if ShowClouds then MACD_15_Avg else double.nan;
plot MACD_5_AvgC = if ShowClouds then MACD_5_Avg else double.nan;
plot MACD_1_AvgC = if ShowClouds then MACD_1_Avg else double.nan;

T_valueC.Hide();
T_AvgC.Hide();
T_DiffC.Hide();
MACD_15_ValueC.Hide();
MACD_5_ValueC.Hide();
MACD_1_ValueC.Hide();
MACD_15_AvgC.Hide();
MACD_5_AvgC.Hide();
MACD_1_AvgC.Hide();


#Addcloud(T_value, T_Avg, GetColor(6), GetColor(5));
Addcloud(T_valueC, T_AvgC, CreateColor(51,153,255), CreateColor(255,51,153));
Addcloud(T_DiffC,Hz, Color.White,Color.White,yes);
AddCloud(MACD_15_Value,MACD_15_AVGC,color.uptick,color.downtick);
AddCloud(MACD_5_ValueC,MACD_5_AVGC,color.green,color.red);
AddCloud(MACD_1_ValueC,MACD_1_AvgC,Color.Cyan,Color.Magenta);

Def x = T_value;

#Condition set-1
Def up_1 = if x crosses above min(macd_1_value, min( macd_5_value, macd_15_value)) then x else double.nan;
plot Up1 = up_1;
up1.SetPaintingStrategy(PaintingStrategy.SQUARES);
up1.AssignValueColor(color.green);
up1.SetLineWeight(5);
Def Dn_3 = if x crosses below min(macd_1_value,min(macd_5_value,macd_15_value)) then x else double.nan;
plot DN3 = if (Dn_3 != Dn_3[1] ) then Dn_3 else double.nan;
dn3.SetPaintingStrategy(PaintingStrategy.SQUARES);
dn3.AssignValueColor(color.red);
dn3.SetLineWeight(5);

#Condition set-2
Def up_3 = if x crosses above max(macd_1_value,max(macd_5_value,macd_15_value)) then x else double.nan;
plot up3 = up_3;
up3.SetPaintingStrategy(PaintingStrategy.SQUARES);
up3.AssignValueColor(color.green);
up3.SetLineWeight(5);
Def Dn_1 = if x crosses below max(macd_1_value,max(macd_5_value,macd_15_value)) then x else double.nan;
plot DN1 = Dn_1;
dn1.SetPaintingStrategy(PaintingStrategy.SQUARES);
dn1.AssignValueColor(color.red);
dn1.SetLineWeight(5);

#Condition set-3
Def Dn_2 = if x crosses below MovingAverage(averageType.weighted, x,5) then x else double.nan;
plot DN2 = Dn_2;
dn2.SetPaintingStrategy(PaintingStrategy.SQUARES);
dn2.AssignValueColor(color.red);
dn2.SetLineWeight(5);
Def Up_2 = if x crosses above MovingAverage(averageType.weighted, x,5) then x else double.nan;
plot UP2 = UP_2;
UP2.SetPaintingStrategy(PaintingStrategy.SQUARES);
UP2.AssignValueColor(color.green);
UP2.SetLineWeight(5);


T_Value.assignvalueColor( if x > MovingAverage(averageType.weighted, x,5) then Color.Dark_green else
                    if X < MovingAverage(averageType.weighted, x,5) then color.Dark_red else
                    if x < min(macd_1_value,min(macd_5_value,macd_15_value)) then color.Dark_red else
                    if x > max(macd_1_value,max(macd_5_value,macd_15_value)) then color.Dark_green else   
                   color.yellow);


T_value.SetPaintingStrategy(PaintingStrategy.LINE);
T_value.setLineWeight(2);


T_Avg.assignvalueColor( if T_AVg > MovingAverage(averageType.weighted, T_AVg,5) then getcolor(6) else
                    if T_AVg < MovingAverage(averageType.weighted,T_Avg ,5) then getcolor(5) else
                    if T_AVg < min(macd_1_Avg,min(macd_5_Avg,macd_15_Avg)) then getcolor(5) else
                    if T_AVg > max(macd_1_Avg,max(macd_5_Avg,macd_15_Avg)) then getcolor(6) else   
                   color.yellow);

T_Avg.SetPaintingStrategy(PaintingStrategy.LINE);
HZ.AssignValueColor(Color.White);


Def up_signal = if ( x crosses above min(macd_1_value, min( macd_5_value, macd_15_value)) or
                      x crosses above max(macd_1_value,max(macd_5_value,macd_15_value)) or 
                      x crosses above MovingAverage(averageType.weighted, x,5)) then 1 else double.nan;
AddVerticalLine( showVerticalLines and Up_Signal == 1,"", Color.UpTick, Curve.SHORT_DASH);


def dn_Signal = if ( x crosses below min(macd_1_value, min( macd_5_value, macd_15_value)) or
                      x crosses below max(macd_1_value,max(macd_5_value,macd_15_value)) or 
                      x crosses below MovingAverage(averageType.weighted, x,5)) then 1 else double.nan;

AddVerticalLine( showVerticalLines and dn_signal == 1,"", Color.DOWNTICK, Curve.SHORT_DASH);

#plot Dot = if macd_1_value crosses below movingAverage(AverageType.Weighted, macd_1_value,3) then  macd_1_value else double.NaN;
#Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
#Dot.AssignValueColor(color.light_red);
#Dot.SetLineWeight(2);

#plot Dot2 = if macd_1_value crosses above movingAverage(AverageType.Weighted, macd_1_value,3) then macd_1_value else double.NaN;
#Dot2.SetPaintingStrategy(PaintingStrategy.points);
#Dot2.AssignValueColor(color.light_green);
#Dot2.SetLineWeight(2);

#End
On 8/12 the /ES showed a divergence for most of the afternoon. This indicator follows the /ES futures better and would have keep you in the trade longer.
 
On 8/12 the /ES showed a divergence for most of the afternoon. This indicator follows the /ES futures better and would have keep you in the trade longer.
Exactly - This indicator begins calculations at the pre-market and it amplifies the signal without distorting it - for a better visual cue.
 
Is it better for this indicator to work during market hours only or can it be used for after hours and market hours continuously. What inputs should be changed for it to plot continuously for after hours and market hours. Thanks.
 
Is it better for this indicator to work during market hours only or can it be used for after hours and market hours continuously. What inputs should be changed for it to plot continuously for after hours and market hours. Thanks.
Here you go -- basically line 30 - C_val is always equal to close in this case.

Code:
# MTF_MACD_Overlay_Cypher

declare lower;

input ShowClouds = Yes;
input ShowSignalLine = Yes;
input ShowVerticalLines = No;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;

input nightSessionFromMidnight = 0100; # 0100;
Input PreMkt = 730;
input firstHourTrading = 930;
input mainSession = 1030;
input nightSessionFromMainSessionEnd = 1615;
input MainSessionEnd = 1600; # RB Code
input paintBars =  no;

def isNightSessionFromMidnight = SecondsFromTime(nightSessionFromMidnight) >= 0 and SecondsTillTime(firstHourTrading) > 0;
def isDaySessionFromStart = secondsFromTime(FirstHourTrading) >= 0 and SecondsTillTime(MainSession) >= 0;
def isFirstHourTrading = SecondsFromTime(firstHourTrading) >= 0 and SecondsTillTime(mainSession) > 0;
def isPreMkt = SecondsFromTime(PreMkt) >= 0 and SecondsTillTime(FirstHourTrading) > 0;
def isMainSession = SecondsFromTime(MainSession) >= 0 and SecondsTillTime(MainSessionEnd) > 0;

def newNightSessionFromMidnight = isNightSessionFromMidnight and !isNightSessionFromMidnight[1];
def newMainSessionFromSessionStart = isDaySessionFromStart and !isDaySessionFromStart[1]; # RB Code

#def C_Val = if IspreMkt then close else if IsDaySessionFromStart then Close else if isMainSession then close else double.nan;
def C_Val = close ;

script f_MACD {
    input DataPoint = close;
    input fastLength = 12;
    input slowLength = 26;
    input MACDLength = 9;
    input averageType = AverageType.EXPONENTIAL;
    input showBreakoutSignals = no;
    plot Value = MovingAverage(averageType, DataPoint, fastLength) - MovingAverage(averageType, DataPoint, slowLength);
    plot Avg = MovingAverage(averageType, Value, MACDLength);
    plot Diff = Value - Avg;
    
    }


def MACD_1_value = f_MACD(DataPoint = c_val, fastLength = FastLength, slowLength = SlowLength, MACDLength = MACDLength).value;
def MACD_1_Avg = f_MACD(DataPoint = c_val, fastLength = FastLength, slowLength = SlowLength, MACDLength = MACDLength).Avg;
def macd_1_diff = f_MACD(DataPoint = c_val, fastLength = FastLength, slowLength = SlowLength, MACDLength = MACDLength).diff;

def MACD_5_Value = f_MACD(DataPoint = c_Val, fastLength = FastLength*5, slowLength = SlowLength*5, MACDLength = MACDLength*5).value;
def MACD_5_Avg = f_MACD(DataPoint = c_Val, fastLength = FastLength*5, slowLength = SlowLength*5, MACDLength = MACDLength*5).Avg;
def macd_5_diff = f_MACD(DataPoint = c_val, fastLength = FastLength*5, slowLength = SlowLength*5, MACDLength = MACDLength*5).diff;

def MACD_15_Value = f_MACD(DataPoint = c_Val, fastLength = FastLength*15, slowLength = SlowLength*15, MACDLength = MACDLength*15).value;
def MACD_15_Avg = f_MACD(DataPoint = c_Val, fastLength = FastLength*15, slowLength = SlowLength*15, MACDLength = MACDLength*15).Avg;
def macd_15_diff = f_MACD(DataPoint = c_val, fastLength = FastLength*15, slowLength = SlowLength*15, MACDLength = MACDLength*15).diff;

Plot Hz = 0;
Plot MACD_1_Value_P = MACD_1_Value;
Plot MACD_1_Avg_P = MACD_1_Avg;
Plot MACD_5_Value_P = MACD_5_Value;
Plot MACD_5_Avg_P = MACD_5_Avg;
Plot MACD_15_Value_P = MACD_15_Value;
Plot MACD_15_Avg_P = MACD_15_Avg;
MACD_1_Value_P.hide();
MACD_1_Avg_P.hide();
MACD_5_Value_P.hide();
MACD_5_Avg_P.hide();
MACD_15_Value_P.hide();
MACD_15_Avg_P.hide();


plot T_Value = if showSignalLine then (macd_1_value + macd_5_value + macd_15_value) else Double.nan;
PLot T_Avg =   if showSignalLine then (macd_1_avg + macd_5_avg + macd_15_avg) else double.nan;
plot T_Diff = (macd_1_diff + macd_5_diff + macd_15_diff);

T_diff.assignValueColor(color.white);

plot T_valueC = if ShowClouds then  T_value else double.nan;
plot T_AvgC = if showClouds then T_Avg else double.nan;
plot T_DiffC = if showClouds then T_Diff else double.nan;
plot MACD_15_ValueC = if ShowClouds then MACD_15_Value else double.nan;
plot MACD_5_ValueC = if ShowClouds then MACD_5_Value else double.nan;
plot MACD_1_ValueC = if ShowClouds then MACD_1_Value else double.nan;
plot MACD_15_AvgC = if ShowClouds then MACD_15_Avg else double.nan;
plot MACD_5_AvgC = if ShowClouds then MACD_5_Avg else double.nan;
plot MACD_1_AvgC = if ShowClouds then MACD_1_Avg else double.nan;

T_valueC.Hide();
T_AvgC.Hide();
T_DiffC.Hide();
MACD_15_ValueC.Hide();
MACD_5_ValueC.Hide();
MACD_1_ValueC.Hide();
MACD_15_AvgC.Hide();
MACD_5_AvgC.Hide();
MACD_1_AvgC.Hide();


#Addcloud(T_value, T_Avg, GetColor(6), GetColor(5));
Addcloud(T_value, T_Avg, CreateColor(51,153,255), CreateColor(255,51,153));
Addcloud(T_DiffC,Hz, Color.White,Color.White,yes);
AddCloud(MACD_15_Value,MACD_15_AVGC,color.uptick,color.downtick);
AddCloud(MACD_5_ValueC,MACD_5_AVGC,color.green,color.red);
AddCloud(MACD_1_ValueC,MACD_1_AvgC,Color.Cyan,Color.Magenta);

Def x = T_value;

#Condition set-1
Def up_1 = if x crosses above min(macd_1_value, min( macd_5_value, macd_15_value)) then x else double.nan;
plot Up1 = up_1;
up1.SetPaintingStrategy(PaintingStrategy.SQUARES);
up1.AssignValueColor(color.green);
up1.SetLineWeight(5);
Def Dn_3 = if x crosses below min(macd_1_value,min(macd_5_value,macd_15_value)) then x else double.nan;
plot DN3 = if (Dn_3 != Dn_3[1] ) then Dn_3 else double.nan;
dn3.SetPaintingStrategy(PaintingStrategy.SQUARES);
dn3.AssignValueColor(color.red);
dn3.SetLineWeight(5);

#Condition set-2
Def up_3 = if x crosses above max(macd_1_value,max(macd_5_value,macd_15_value)) then x else double.nan;
plot up3 = up_3;
up3.SetPaintingStrategy(PaintingStrategy.SQUARES);
up3.AssignValueColor(color.green);
up3.SetLineWeight(5);
Def Dn_1 = if x crosses below max(macd_1_value,max(macd_5_value,macd_15_value)) then x else double.nan;
plot DN1 = Dn_1;
dn1.SetPaintingStrategy(PaintingStrategy.SQUARES);
dn1.AssignValueColor(color.red);
dn1.SetLineWeight(5);

#Condition set-3
Def Dn_2 = if x crosses below MovingAverage(averageType.weighted, x,5) then x else double.nan;
plot DN2 = Dn_2;
dn2.SetPaintingStrategy(PaintingStrategy.SQUARES);
dn2.AssignValueColor(color.red);
dn2.SetLineWeight(5);
Def Up_2 = if x crosses above MovingAverage(averageType.weighted, x,5) then x else double.nan;
plot UP2 = UP_2;
UP2.SetPaintingStrategy(PaintingStrategy.SQUARES);
UP2.AssignValueColor(color.green);
UP2.SetLineWeight(5);


T_Value.assignvalueColor( if x > MovingAverage(averageType.weighted, x,5) then Color.Dark_green else
                    if X < MovingAverage(averageType.weighted, x,5) then color.Dark_red else
                    if x < min(macd_1_value,min(macd_5_value,macd_15_value)) then color.Dark_red else
                    if x > max(macd_1_value,max(macd_5_value,macd_15_value)) then color.Dark_green else     
                   color.yellow);


T_value.SetPaintingStrategy(PaintingStrategy.LINE);
T_value.setLineWeight(2);


T_Avg.assignvalueColor( if T_AVg > MovingAverage(averageType.weighted, T_AVg,5) then getcolor(6) else
                    if T_AVg < MovingAverage(averageType.weighted,T_Avg ,5) then getcolor(5) else
                    if T_AVg < min(macd_1_Avg,min(macd_5_Avg,macd_15_Avg)) then getcolor(5) else
                    if T_AVg > max(macd_1_Avg,max(macd_5_Avg,macd_15_Avg)) then getcolor(6) else     
                   color.yellow);

T_Avg.SetPaintingStrategy(PaintingStrategy.LINE);
HZ.AssignValueColor(Color.White);


Def up_signal = if ( x crosses above min(macd_1_value, min( macd_5_value, macd_15_value)) or
                      x crosses above max(macd_1_value,max(macd_5_value,macd_15_value)) or   
                      x crosses above MovingAverage(averageType.weighted, x,5)) then 1 else double.nan;
AddVerticalLine( showVerticalLines and Up_Signal == 1,"", Color.UpTick, Curve.SHORT_DASH);


def dn_Signal = if ( x crosses below min(macd_1_value, min( macd_5_value, macd_15_value)) or
                      x crosses below max(macd_1_value,max(macd_5_value,macd_15_value)) or   
                      x crosses below MovingAverage(averageType.weighted, x,5)) then 1 else double.nan;

AddVerticalLine( showVerticalLines and dn_signal == 1,"", Color.DOWNTICK, Curve.SHORT_DASH);

#plot Dot = if macd_1_value crosses below movingAverage(AverageType.Weighted, macd_1_value,3) then  macd_1_value else double.NaN;
#Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
#Dot.AssignValueColor(color.light_red);
#Dot.SetLineWeight(2);

#plot Dot2 = if macd_1_value crosses above movingAverage(AverageType.Weighted, macd_1_value,3) then macd_1_value else double.NaN;
#Dot2.SetPaintingStrategy(PaintingStrategy.points);
#Dot2.AssignValueColor(color.light_green);
#Dot2.SetLineWeight(2);

#End
 

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
381 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