Madrid Trend Squeeze ported from TradingView

K

Ken_Adams

New member
Hey Guys,
n
Found this indicator on TradingView and ported it over today. First time I have done it. No idea if this squeeze is different than any other one out there. Here is the authors notes.
Be aware, my colors are different then his.

https://www.tradingview.com/script/9bUUSzM3-Madrid-Trend-Squeeze/
This study spots the points that are most profitable in the trend with a code color and shape. This also shows trend divergences and possible reversal or reentry points

Keeping the parameters simple, this study only needs one parameter, the length of the base moving average, which by default is set to 34.

There are seven colors used for the study

Green : Uptrend in general
Lime : Spots the current uptrend leg
Aqua : The maximum profitability of the leg in a long trade
The Squeeze happens when Green+Lime+Aqua are aligned (the larger the values the better)

Maroon : Downtrend in general
Red : Spots the current downtrend leg
Fuchsia: The maximum profitability of the leg in a short trade
The Squeeze happens when Maroon+Red+Fuchsia are aligned (the larger the values the better)

Yellow : The trend has come to a pause and it is either a reversal warning or a continuation. These are the entry, re-entry or closing position points.

When either the fuchsia or the aqua colors disappear or shrinks meaningfully it could mean a possible leg exhaustion that will have to be confirmed with the subsequent bars.
When the squeeze color appears without the intermediate color (fuchsia+yellow, fuchsia+maroon, aqua+yellow, aqua+green) it could mean this is just a shake off move, a pump/dump move, a buy the dip or a sell the peak move or a gap.

In the example there are three divergences spotted, the first one between march 2009 and september 2010 when the peaks in the indicator made a lower low, meanwhile the price made a higher high, this is a negative divergence and a trend reversal. On the second example, between april 2013 and July 2013 the indicator made a higher high meanwhile the price made a double bottom , this is a positive divergence and a reversal to the upside.

Code:
#study("Madrid Trend Squeeze", shorttitle=" MTrendSqueeze")
# Madrid : Squeeze Trend : 02/Aug/2015 : 11:41 : 2.0
#This Study determines the range where the trend is more profitable.
#http://madridjourneyonws.blogspot.com/

#Ported from Tradingview
#by Ken_Adams on 4/22/20



#start of code

declare lower;
declare zerobase;

input len = 21;
input src = close;
input ref = 13
;
input sqzLen = 5
;
input hline = 0;


def ma = MovAvgExponential(src, len)
;


def closema = close - ma;
plot closema1 = closema;
closema1.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
closema1.SetLineWeight(3);
closema1.AssignValueColor(if closema >= 0 then Color.PINK else Color.MAGENTA);



def sqzma = MovAvgExponential(src, sqzLen) - ma;
plot sqzma1 = sqzma;
sqzma1.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
sqzma1.SetLineWeight(3);
sqzma1.AssignValueColor(if sqzma >= 0 then Color.cyan else Color.RED);




def refma = MovAvgExponential(src, ref) - ma;
plot refma1 = refma;
refma1.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
refma1.SetLineWeight(3);
refma1.AssignValueColor(if refma >= 0 and closema < refma or refma < 0 and closema > refma then Color.YELLOW else color.black);

plot refma2 = refma;
refma2.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
refma2.SetLineWeight(3);
refma2.AssignValueColor(if refma >= 0 then Color.GREEN else Color.dark_orange);

#end of code
 
Last edited:
D

diazlaz

Well-known member
2019 Donor
VIP
Hi @Ken_Adams,

Nice work on your port ;)

Trading View:


ToS:


thanks again and welcome!
 
K

Ken_Adams

New member
@diazlaz Thanks

It was a good one to learn on. Easy enough to get it, hard enough to learn.

One thing, tried to add IronRod's SMIs but had scaling issues. Suggestions?


Next one I'm trying to port...
https://www.tradingview.com/v/tVtxISLu/
So far it has been difficult...
 
B

Bhai

New member
Nice work.

but I feel like the candle bars doesn't depict the 3 colors stated in original content.

I agree the colors are different but 3 colors appear either above or below zero lines. Some how it's not showing up in TOS.

Something you can look.
 
K

Ken_Adams

New member
@Bhai, you have to really zoom in. I was thinking about adding a bubble or arrow with the “yellow.”
 
D

diazlaz

Well-known member
2019 Donor
VIP
D

DeusMecanicus

Member
I think your original port had the plots in the wrong order, it caused some plots to block others. I made a quick adjustment and reverted to the original colors for anyone interested.


Code:
#study("Madrid Trend Squeeze", shorttitle=" MTrendSqueeze")
# Madrid : Squeeze Trend : 02/Aug/2015 : 11:41 : 2.0
#This Study determines the range where the trend is more profitable.
#http://madridjourneyonws.blogspot.com/

#Ported from Tradingview
#by Ken_Adams on 4/22/20
#DeusMecanicus edit on 4/29/20 - Original colors and plot rearrangement


#start of code

declare lower;
declare zerobase;

input len = 34;
input src = close;
input ref = 13
;
input sqzLen = 5
;
input hline = 0;


def ma = MovAvgExponential(src, len)
;


def closema = close - ma;
def refma = MovAvgExponential(src, ref) - ma;
def sqzma = MovAvgExponential(src, sqzLen) - ma;

plot refma1 = refma;
refma1.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
refma1.SetLineWeight(3);
refma1.AssignValueColor(if refma >= 0 and closema < refma or refma < 0 and closema > refma then Color.yellow else if refma >= 0 then Color.dark_green else color.dark_red);

plot sqzma1 = sqzma;
sqzma1.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
sqzma1.SetLineWeight(3);
sqzma1.AssignValueColor(if sqzma >= 0 then Color.green else Color.red);

plot closema1 = closema;
closema1.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
closema1.SetLineWeight(3);
closema1.AssignValueColor(if closema >= 0 then Color.cyan else Color.magenta);



#end of code
 
ccurtin

ccurtin

New member
VIP
Nice. If you prefer a white screen vs dark (like me), I change every Color.yellow to Color.light_orange for visibility. The RBG of light orange is 250, 181, 127 or similar if you need to change a dot or another shape in the code.
 
Prison Mike

Prison Mike

Member
Code:
#study("Stop Light Madrid Trend Squeeze", shorttitle=" SLMTrendSqueeze")
# Madrid : Squeeze Trend : 02/Aug/2015 : 11:41 : 2.0
#This Study determines the range where the trend is more profitable.
#http://madridjourneyonws.blogspot.com/

#Ported from Tradingview
#by Ken_Adams on 4/22/20
#DeusMecanicus edit on 4/29/20 - Original colors and plot rearrangement
# PrisonMike converted to MTF StopLight Squeeze

declare lower;
input AP1 = AggregationPeriod.four_hours;
input AP2 = AggregationPeriod.day;
input AP3 = AggregationPeriod.two_days;
input AP4 = AggregationPeriod.four_days;
input AP5 = AggregationPeriod.WEEK;
input AP6 = AggregationPeriod.MONTH;
input vote = 3;

def price1 = CLOSE(period = AP1);
def price2 = CLOSE(period = AP2);
def price3 = CLOSE(period = AP3);
def price4 = CLOSE(period = AP4);
def price5 = CLOSE(period = AP5);
def price6 = CLOSE(period = AP6);

def len = 34;
def ref = 13;
def sqzLen = 5;
def hline = 0;
def ma1 = MovAvgExponential(price1, len);
def ma2 = MovAvgExponential(price2, len);
def ma3 = MovAvgExponential(price3, len);
def ma4 = MovAvgExponential(price4, len);
def ma5 = MovAvgExponential(price5, len);
def ma6 = MovAvgExponential(price6, len);


#1 Day
def closema = price1 - ma1;
def refma = MovAvgExponential(price1, ref) - ma1;
def sqzma = MovAvgExponential(price1, sqzLen) - ma1;

def squeeze1 =  refma >= 0 and closema < refma or refma < 0 and closema > refma ;

#2 Two Day
def closema2 = price2 - ma2;
def refma2 = MovAvgExponential(price2, ref) - ma2;
def sqzma2 = MovAvgExponential(price2, sqzLen) - ma2;

def squeeze2 =  refma2 >= 0 and closema2 < refma2 or refma2 < 0 and closema2 > refma2 ;

#3 Three Day
def closema3 = price3 - ma3;
def refma3 = MovAvgExponential(price3, ref) - ma3;
def sqzma3 = MovAvgExponential(price3, sqzLen) - ma3;

def squeeze3=  refma3 >= 0 and closema3 < refma3 or refma3 < 0 and closema3 > refma3 ;


#4 Four Day
def closema4 = price4 - ma4;
def refma4 = MovAvgExponential(price4, ref) - ma4;
def sqzma4 = MovAvgExponential(price4, sqzLen) - ma4;

def squeeze4 =  refma4 >= 0 and closema4 < refma4 or refma4 < 0 and closema4 > refma4 ;

#5 Week
def closema5 = price5 - ma5;
def refma5 = MovAvgExponential(price5, ref) - ma5;
def sqzma5 = MovAvgExponential(price5, sqzLen) - ma5;

def squeeze5 =  refma5 >= 0 and closema5 < refma5 or refma5 < 0 and closema5 > refma5 ;

#6 Month
def closema6 = price6 - ma6;
def refma6 = MovAvgExponential(price6, ref) - ma6;
def sqzma6 = MovAvgExponential(price6, sqzLen) - ma6;

def squeeze6=  refma6 >= 0 and closema6 < refma6 or refma6 < 0 and closema6 > refma6;


def Top_Plot = (squeeze1 + squeeze2 + squeeze3+squeeze4 + squeeze5 + squeeze5) >= Vote;


plot MTF_Sqz = 7;
MTF_Sqz.SetPaintingStrategy(PaintingStrategy.POINTS);
MTF_Sqz.AssignValueColor(if Top_Plot == 1 then Color.BLACK else Color.DARK_RED);
MTF_Sqz.SetLineWeight(5);

plot Sqeezy1 = if squeeze1 == 1 then squeeze1 + 5 else 6;
plot Sqeezy2 = if squeeze2 == 1 then squeeze2 + 4 else 5;
plot Sqeezy3 = if squeeze3 == 1 then squeeze3 + 3 else 4;
plot Sqeezy4 = if squeeze4== 1 then squeeze4 + 2 else 3;
plot Sqeezy5 = if squeeze5 == 1 then squeeze5 + 1 else 2;
plot Sqeezy6 = if squeeze6 == 1 then squeeze6 + 0 else 1;


Sqeezy1.SetPaintingStrategy(PaintingStrategy.POINTS);
Sqeezy1.AssignValueColor(if squeeze1 == 1 then Color.red else Color.green);
Sqeezy1.SetLineWeight(3);
Sqeezy2.SetPaintingStrategy(PaintingStrategy.POINTS);
Sqeezy2.AssignValueColor(if squeeze2 == 1 then Color.red else Color.green);
Sqeezy2.SetLineWeight(3);
Sqeezy3.SetPaintingStrategy(PaintingStrategy.POINTS);
Sqeezy3.AssignValueColor(if squeeze3 == 1 then Color.red else Color.green);
Sqeezy3.SetLineWeight(3);
Sqeezy4.SetPaintingStrategy(PaintingStrategy.POINTS);
Sqeezy4.AssignValueColor(if squeeze4 == 1 then Color.red else Color.green);
Sqeezy4.SetLineWeight(3);
Sqeezy5.SetPaintingStrategy(PaintingStrategy.POINTS);
Sqeezy5.AssignValueColor(if squeeze5 == 1 then Color.red else Color.green);
Sqeezy5.SetLineWeight(3);
Sqeezy6.SetPaintingStrategy(PaintingStrategy.POINTS);
Sqeezy6.AssignValueColor(if squeeze6 == 1 then Color.red else Color.green);
Sqeezy3.SetLineWeight(3);
 
V

VicD

Member
Gents, I need your help. So I'm working on the column and decided to hack the TTMSqueeze column to make it. So I got it to display magenta, cyan, red and light green. But I need a logic for yellow. Anyone can suggest how i would add that?

Code:
#Watch list Column for Madrid Trend Squeeze, current period, current trend

#study("Madrid Trend Squeeze", shorttitle=" MTrendSqueeze")
# Madrid : Squeeze Trend : 02/Aug/2015 : 11:41 : 2.0
#This Study determines the range where the trend is more profitable.
#http://madridjourneyonws.blogspot.com/

#Ported from Tradingview
#by Ken_Adams on 4/22/20
#DeusMecanicus edit on 4/29/20 - Original colors and plot rearrangement


#start of code

declare lower;
declare zerobase;

input len = 34;
input src = close;
input ref = 13;
input sqzLen = 5;
input hline = 0;


def ma = MovAvgExponential(src, len);
def ZeroLine = 0;
def oversold = -.4;
def overbought = .4 ;


def closema = close - ma;
def refma = MovAvgExponential(src, ref) - ma;
def sqzma = MovAvgExponential(src, sqzLen) - ma;

def refma1 = refma;


def sqzma1 = sqzma;


def closema1 = closema;

plot hist = if refma>= 0 then
if refma1> refma1[1] then 2 else 1
else if refma1 < refma1[1] then -2 else -1;

assignBackgroundColor(if sqzma1 >= 0 then
if closema1 > sqzma1 then color.CYAN else color.light_green
else if closema1 < sqzma1 then color.magenta else color.red);


#hist.assignvaluecolor(if closema1 >= 0 then
#if closema1 > sqzma1 then color.CYAN else color.light_green
#else if closema1 < sqzma1 then color.magenta else color.red);
 

Similar threads

Top