The Matrix Indicator for ThinkorSwim

Can someone add a label indicating the accumulation zone & distribution zone? I can't tell which part of the code it is & the commented out description says the title of a flower chart changes but idk what that is.
Ruby:
AddLabel(yes, " ", if pUP then color.orange else if pDown then color.cyan else color.gray);
 
Last edited:
Converted from the Matrix Series indicator on TradingView. Brought to you by @diazlaz

Some context about this indicator (found on wisestocktrader):


hbax9rA.png


thinkScript Code

Code:
#Matrix Series for ThinkorSwim V1.0
#
#CREDITS
# glaz
# https://www.tradingview.com/script/2X2cVLhb-Matrix-Series/
#
#CHANGELOG
# 2019.12.06 1.0 @diazlaz - Initial Port
#
#LINKS
# https://www.wisestocktrader.com/indicators/2739-flower-indicator
# https://www.wisestocktrader.com/indicators/1087-matrix-series
#
#
#DESCRIPTION
#Please use the following AFL on your exisitng AMIBROKER Chart & get a edge in
#identifying Accumulation/Distribution zone of any market.
#Each levels can act like support & resistance
#( watch for +/- 200 levels & the dots when appear on the chart )
#Title of the Flower Chart will go RED if we are entering in a Distribution
#phase & Green for Accumulation.
#This is a modified RENKO chart & should be used with MPLITE & any Momentum
#indicator combination for best results.
#
#There’re 3 ways to use it. I usually get entry position when :
#1. Candle upward before / after cross the zero line
#2. Candle downward but real candle is sideways. This will be best when price is in oversold area.
#3. Candle downward and begin to change from big to small. It is usually followed by significant movement.
#When down candle with the red real candle is occur, it almost certainly bearish signal.
#FYI, I use it in daily chart.

declare lower;

#INPUTS
input Smoother = 5;
input SupResPeriod = 50;
input SupResPercentage = 100;
input PricePeriod = 16;
input ob = 200;
input os = -200;
input showColorBars = no; #COLOR BARS
input showDynamics = no; #Dynamic zones
input showOBOS = yes; #Show OB/OS

#LOGIC
def nn = Smoother;
def ys1 = (high + low + close * 2) / 4;
def rk3 = ExpAverage(ys1, nn);
def rk4 = StDev(ys1, nn);
def rk5 = (ys1 - rk3) * 200 / rk4;
def rk6 = ExpAverage(rk5, nn);
def up = ExpAverage(rk6, nn);
def down = ExpAverage(up, nn);
def Oo = If(up < down, up, down);
def Hh = Oo;
def Ll = If(up < down, down, up);
def Cc = Ll;


def Lookback = SupResPeriod;
def PerCent = SupResPercentage;
def Pds = PricePeriod;

def C3 = CCI(length = Pds);

def Osc = C3;
def Value1 = Osc;
def Value2 = Highest(Value1, Lookback);
def Value3 = Lowest(Value1, Lookback);
def Value4 = Value2 - Value3;
def Value5 = Value4 * (PerCent / 100);
def ResistanceLine = Value3 + Value5;
def SupportLine = Value2 - Value5;

#CUSTOM CANDLES
def cUpO;
def cUpH;
def cUpL;
def cUpC;
if up > down
then {
    cUpO = oo;
    cUpH = hh;
    cUpL = ll;
    cUpC = cc;
} else {
    cUpO = Double.NaN;
    cUpH = Double.NaN;
    cUpL = Double.NaN;
    cUpC = Double.NaN;
}

def cDnO;
def cDnH;
def cDnL;
def cDnC;
if up < down
then {
    cDnO = Oo;
    cDnH = Hh;
    cDnL = Ll;
    cDnC = Cc;
} else {
    cdnO = Double.NaN;
    cdnH = Double.NaN;
    cdnL = Double.NaN;
    cdnC = Double.NaN;
}

AddChart(high = cUpH, low = cUpL, open = cUpC, close = cUpO, type = ChartType.CANDLE, COLOR.GREEN);
AddChart(high = cDnH, low = cDnL, open = cDnO, close = cDnC, type = ChartType.CANDLE, COLOR.RED);
AddChart(high = cUpH, low = cUpL, open = cUpO, close = cUpC, type = ChartType.CANDLE, growcolor = COLOR.GREEN);
AddChart(high = cDnH, low = cDnL, open = cDnC, close = cDnO, type = ChartType.CANDLE, growcolor = COLOR.RED);

#COLORBARS
AssignPriceColor(if showColorBars then
 if Oo > Cc then COLOR.RED else if up > down then COLOR.GREEN
 else COLOR.RED
else
  COLOR.CURRENT
);

#PLOTS
plot pResistanceLine = ResistanceLine;
pResistanceLine.SetHiding(!showDynamics);

plot pSupportLine = SupportLine;
pSupportLine.SetHiding(!showDynamics);

def UpShape = if up > ob and up > down then highest(up,1) + 20 else if up > ob and up < down then highest(down,1) + 20 else Double.NaN;

def DownShape = if down < os and up > down then lowest(down,1) - 20 else if
 down < os and up < down then lowest(up,1) - 20 else Double.NaN;

def sState = if !isNan(UpShape) then 100 else if !isNan(DownShape) then -100 else sState[1];

plot pUP = UpShape;
pUP.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
pUP.SetDefaultColor(Color.CYAN);
pUP.SetLineWeight(1);

plot pDown = DownShape;
pDown.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
pDown.SetDefaultColor(Color.CYAN);
pDown.SetLineWeight(1);
;

plot pOB = OB;
pOB.SetHiding(!showOBOS);

plot pOS = OS;
pOS.SetHiding(!showOBOS);
trying to add MTF .dont seem to get it right
can we add MTF ?
 
Last edited by a moderator:
This should allow you to have this be MTF at the input agg

snip.jpg
Ruby:
#Matrix Series for ThinkorSwim V1.0
#
#CREDITS
# glaz
# https://www.tradingview.com/script/2X2cVLhb-Matrix-Series/
#
#CHANGELOG
# 2019.12.06 1.0 @diazlaz - Initial Port
#
#LINKS
# https://www.wisestocktrader.com/indicators/2739-flower-indicator
# https://www.wisestocktrader.com/indicators/1087-matrix-series
#
#
#DESCRIPTION
#Please use the following AFL on your exisitng AMIBROKER Chart & get a edge in
#identifying Accumulation/Distribution zone of any market.
#Each levels can act like support & resistance
#( watch for +/- 200 levels & the dots when appear on the chart )
#Title of the Flower Chart will go RED if we are entering in a Distribution
#phase & Green for Accumulation.
#This is a modified RENKO chart & should be used with MPLITE & any Momentum
#indicator combination for best results.
#
#There’re 3 ways to use it. I usually get entry position when :
#1. Candle upward before / after cross the zero line
#2. Candle downward but real candle is sideways. This will be best when price is in oversold area.
#3. Candle downward and begin to change from big to small. It is usually followed by significant movement.
#When down candle with the red real candle is occur, it almost certainly bearish signal.
#FYI, I use it in daily chart.

declare lower;

#INPUTS
input Smoother = 5;
input SupResPeriod = 50;
input SupResPercentage = 100;
input PricePeriod = 16;
input ob = 200;
input os = -200;
input showColorBars = no; #COLOR BARS
input showDynamics = no; #Dynamic zones
input showOBOS = yes; #Show OB/OS

input agg=aggregationPeriod.HOUR;
#LOGIC
def nn = Smoother;
def ys1 = (high(period=agg) + low(period=agg) + close(period=agg) * 2) / 4;
def rk3 = ExpAverage(ys1, nn);
def rk4 = StDev(ys1, nn);
def rk5 = (ys1 - rk3) * 200 / rk4;
def rk6 = ExpAverage(rk5, nn);
def up = ExpAverage(rk6, nn);
def down = ExpAverage(up, nn);
def Oo = If(up < down, up, down);
def Hh = Oo;
def Ll = If(up < down, down, up);
def Cc = Ll;


def Lookback = SupResPeriod;
def PerCent = SupResPercentage;
def Pds = PricePeriod;

def C3 = CCI(length = Pds);

def Osc = C3;
def Value1 = Osc;
def Value2 = Highest(Value1, Lookback);
def Value3 = Lowest(Value1, Lookback);
def Value4 = Value2 - Value3;
def Value5 = Value4 * (PerCent / 100);
def ResistanceLine = Value3 + Value5;
def SupportLine = Value2 - Value5;

#CUSTOM CANDLES
def cUpO;
def cUpH;
def cUpL;
def cUpC;
if up > down
then {
    cUpO = oo;
    cUpH = hh;
    cUpL = ll;
    cUpC = cc;
} else {
    cUpO = Double.NaN;
    cUpH = Double.NaN;
    cUpL = Double.NaN;
    cUpC = Double.NaN;
}

def cDnO;
def cDnH;
def cDnL;
def cDnC;
if up < down
then {
    cDnO = Oo;
    cDnH = Hh;
    cDnL = Ll;
    cDnC = Cc;
} else {
    cdnO = Double.NaN;
    cdnH = Double.NaN;
    cdnL = Double.NaN;
    cdnC = Double.NaN;
}

AddChart(high = cUpH, low = cUpL, open = cUpC, close = cUpO, type = ChartType.CANDLE, COLOR.GREEN);
AddChart(high = cDnH, low = cDnL, open = cDnO, close = cDnC, type = ChartType.CANDLE, COLOR.RED);
AddChart(high = cUpH, low = cUpL, open = cUpO, close = cUpC, type = ChartType.CANDLE, growcolor = COLOR.GREEN);
AddChart(high = cDnH, low = cDnL, open = cDnC, close = cDnO, type = ChartType.CANDLE, growcolor = COLOR.RED);

#COLORBARS
AssignPriceColor(if showColorBars then
 if Oo > Cc then COLOR.RED else if up > down then COLOR.GREEN
 else COLOR.RED
else
  COLOR.CURRENT
);

#PLOTS
plot pResistanceLine = ResistanceLine;
pResistanceLine.SetHiding(!showDynamics);

plot pSupportLine = SupportLine;
pSupportLine.SetHiding(!showDynamics);

def UpShape = if up > ob and up > down then highest(up,1) + 20 else if up > ob and up < down then highest(down,1) + 20 else Double.NaN;

def DownShape = if down < os and up > down then lowest(down,1) - 20 else if
 down < os and up < down then lowest(up,1) - 20 else Double.NaN;

def sState = if !isNan(UpShape) then 100 else if !isNan(DownShape) then -100 else sState[1];

plot pUP = UpShape;
pUP.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
pUP.SetDefaultColor(Color.CYAN);
pUP.SetLineWeight(1);

plot pDown = DownShape;
pDown.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
pDown.SetDefaultColor(Color.CYAN);
pDown.SetLineWeight(1);
;

plot pOB = OB;
pOB.SetHiding(!showOBOS);

plot pOS = OS;
pOS.SetHiding(!showOBOS);
 
Last edited:
@Tek What would be the condition for alerts?
Hey Ben, I was looking to add an alert if a bar crosses over/under 170/-170 that would sound just once at the first bar over. I messed around not knowing what I'm doing and came up with this:

Code:
#Added Alert
def LNMLN = cUpH crosses above 170;
def LNMLS = cDnL crosses below -170;
Alert(LNMLN, "LEAVING NO MANS LAND", Alert.Bar, Sound.Ding);
Alert(LNMLS, "LEAVING NO MANS LAND", Alert.Bar, Sound.Ding);

Isn't working and seemed to want to ding on every bar over the line when it actually did work once lol.
 
Hey Ben, I was looking to add an alert if a bar crosses over/under 170/-170 that would sound just once at the first bar over. I messed around not knowing what I'm doing and came up with this:

Code:
#Added Alert
def LNMLN = cUpH crosses above 170;
def LNMLS = cDnL crosses below -170;
Alert(LNMLN, "LEAVING NO MANS LAND", Alert.Bar, Sound.Ding);
Alert(LNMLS, "LEAVING NO MANS LAND", Alert.Bar, Sound.Ding);

Isn't working and seemed to want to ding on every bar over the line when it actually did work once lol.

Did you see a fluctuation? Maybe it was going above and below 170/-170 a couple of times.
 
Did you see a fluctuation? Maybe it was going above and below 170/-170 a couple of times.
All day yesterday it only went off once. I tested it today and it seems to be working now. I'm still getting multiple dings pretty much everytime (rapid succession w/2 or 3 popups) but not worried about it- it'll wake me up. Actually I'm more surprised that I wrote something that works lol. I wasn't sure if CUpH/CDnL were the right inputs into that def, just took a wild guess...
 
The Matrix indicator is opaque to me. It is complete mystery to me as to how it accomplishes what it does. But I have it as lower short term indicator on a 3 minute 1 day Chart for futures. It correlates quite significantly with John Carter's TTM Squeeze indicator, which is a go to intraday indicator for confirming expansion and contraction in order flow. If someone could take the time to line by line explain the code for a non-coder I would have more confidence in employing it and incorporating it into my tool of signals.
There is some notion that somehow this was adapted from a Renko constructed code? or am I mistaken.
What, pray tell, is the mathematical defintion of this introductory input section from the indicator.
input Smoother = 5;
input SupResPeriod = 50;
input SupResPercentage = 100;
input PricePeriod = 16;
Further more pray tell from the indicator coding

#LOGIC
def nn = Smoother;
def ys1 = (high + low + close * 2) / 4;
def rk3 = ExpAverage(ys1, nn);
def rk4 = StDev(ys1, nn);
def rk5 = (ys1 - rk3) * 200 / rk4;
def rk6 = ExpAverage(rk5, nn);
def up = ExpAverage(rk6, nn);
def down = ExpAverage(up, nn);
def Oo = If(up < down, up, down);
def Hh = Oo;
def Ll = If(up < down, down, up);
def Cc = Ll;
___ It is very opaque and while I understand the individual employment of the ExpAve, Stnd Dev. I have NO, repeat No ability to discern the computer essential Logic of this internal Kernal..
For example def Oo =if(up<down,up,down) .. Q. Really? come On! I am befuddled.
Someone care to take pity on a poor autodidactic self-taught isolated Neanderthal that happened on a computer.. All kidding aside, I feel defeated in trying to really follow the logic here even though the indicator prints nice signals, that do correlate with other signals, I do not feel confident enough to risk my $ on when the code is so mysterious... Best regards to all the Thread followers. Most Humbly MagicQuotes
 

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