Z-Score Heikin-Ashi Transformed for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
3KfhHhv.png

Author Message:
he Z-Score Heikin-Ashi Transformed (𝘡 𝘏-𝘈) indicator is a powerful technical tool that combines the principles of Z-Score and Heikin Ashi to provide traders with a smoothed representation of price movements and a standardized measure of market volatility.

The 𝘡 𝘏-𝘈 indicator applies the Z-Score calculation to price data and then transforms the resulting Z-Scores using the Heikin Ashi technique. Understanding the individual components of Z-Score and Heikin Ashi will provide a foundation for comprehending the methodology and unique features of this indicator.
More Details : https://www.tradingview.com/v/MFW8vsmU/

CODE:

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#https://www.tradingview.com/v/MFW8vsmU/
#// © QuantiLuxe
#indicator("Z-Score Heikin Ashi Transformed", "{?} - ? ?-?", false)
# converted by Sam4Cok@Samer800    - 07/2023
declare lower;
#f_z(src, len) =>
script f_z {
    input src = close;
    input len = 21;
    def mean = Average(src, len);
    def dev = StDev(src, len);
    def f_z = (src - mean) / dev;
    plot out = f_z;
}
input Zperiod = 21;            # 'Z Period'
input showSignals = yes;
input ReversionThreshold = {"1", default "2", "3"};    # "Reversion Threshold"
input showMovAvgLine1 = yes;
input movAvgLength1 = 50;
input showMovAvgLine2 = yes;
input movAvgLength2 = 150;

def na = Double.NaN;
def last = isNaN(close);

def revt;
Switch (ReversionThreshold) {
Case "1" : revt = 1;
Case "2" : revt = 2;
Case "3" : revt = 3;
}
#-- Colors
DefineGlobalColor("colup", CreateColor(255,242,204));
DefineGlobalColor("coldn", CreateColor(111,168,220));
DefineGlobalColor("colema1", Color.CYAN);
DefineGlobalColor("colema2", Color.MAGENTA);
DefineGlobalColor("low", CreateColor(255,214,232));
DefineGlobalColor("dlow", Color.PLUM);

def o_z = f_z(open, Zperiod);
def h_z = f_z(high, Zperiod);
def l_z = f_z(low, Zperiod);
def c_z = f_z(close, Zperiod);

def haClose = (o_z + h_z + l_z + c_z) / 4;
def haOpen = CompoundValue(1, (haOpen[1] + haClose[1]) / 2, (o_z + c_z) / 2);
def haHigh = Max(h_z, Max(haOpen, haClose));
def haLow = Min(l_z, Min(haOpen, haClose));
#def ohlc = (haClose + haOpen + haHigh + haLow) / 4;

def haColor = if haClose > haOpen then 1 else
              if haClose < haOpen then -1 else 0;
def OpenUp = if haColor > 0 then haOpen else na;
def OpenDn = if haColor < 0 then haOpen else na;

# Plot the new Chart
AddChart(high = if haColor > 0 then haHigh else na , low = haLow , open = haClose,  close = OpenUp,
         type = ChartType.CANDLE, growcolor =  GlobalColor("colup"));

AddChart(high = if haColor < 0 then haHigh else na, low = haLow , open = OpenDn,  close = haClose,
         type = ChartType.CANDLE, growcolor =  GlobalColor("coldn"));

plot EMA1 = if showMovAvgLine1 then ExpAverage(haClose, movAvgLength1) else na;
plot EMA2 = if showMovAvgLine2 then ExpAverage(haClose, movAvgLength2) else na;
EMA1.SetDefaultColor(GlobalColor("colema1"));
EMA2.SetDefaultColor(GlobalColor("colema2"));

plot zero = if last then na else 0;    # "Mid Line"
zero.SetStyle(Curve.SHORT_DASH);
zero.SetDefaultColor(Color.DARK_GRAY);

def max = if last then na else 4;
def hh = if last then na else 3;
def lh = if last then na else 2;

DefineGlobalColor("high", Color.DARK_GRAY);
DefineGlobalColor("dhigh", Color.WHITE);
AddCloud(hh, lh, GlobalColor("dhigh"));
AddCloud(max, hh, GlobalColor("high"));

def min = if last then na else -4;
def ll = if last then na else -3;
def hl = if last then na else -2;

AddCloud(hl, ll, GlobalColor("dlow"));
AddCloud(ll, min, GlobalColor("low"));

def dn = haHigh[1] < haHigh[2];
def up = haLow[1] > haLow[2];

plot SigUp = if !showSignals then na else
             if (haHigh > revt and haHigh < haHigh[1] and !dn) then haHigh + 0.75 else na;    # "OB"
plot SigDn = if !showSignals then na else
             if (haLow < -revt and haLow > haLow[1] and !up) then haLow - 0.75 else na;       # "OS"

SigUp.SetPaintingStrategy(PaintingStrategy.SQUARES);
SigDn.SetPaintingStrategy(PaintingStrategy.SQUARES);
SigUp.SetDefaultColor(Color.GREEN);
SigDn.SetDefaultColor(Color.RED);

#--- END of CODE
 
Last edited by a moderator:

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

@samer800// In my experience (just downloaded to my TOS) this provides an Excellent addition to the already existing Z score indicator on TOS. The additional signals in a cloud formation with the Reversal dots are great visual add to the "tool box" for the ardent tape price action reader. It does a great job of summarizing the order flow without the Bid Ask "brownian type movement" that is so popular with the Order Flow Cult movement.. IT PRINTS OUT EVEN ON A TICK CHART!, excuse the capital letters, as unlike the $Tick and $TIKND (which do not print on tick based chart for the futures trade :sick:)the HeikinAshi transformed indicator can be used for both Time based and intraday Tick charts.. Congratulations . Gratitude from MagicQuotes. Best to all on the thread
 
This is the true Z-score in the statistical sense...
 
Last edited by a moderator:
Could this please updated to allow the colors to be changed for the upper limit threshold?

1739384835890.png

The dlow and low allows the the oversold colors to be changed but there are no settings to change the overbought colors.
 
Last edited by a moderator:
Could this please updated to allow the colors to be changed for the upper limit threshold?

View attachment 24101
The dlow and low allows the the oversold colors to be changed but there are no settings to change the overbought colors.

The code in the top post has been modified to allow overbought colors to be changed
 
The Scan Hacker does not work well with scripts that contain AddChart formatting functions.
The below script removes all formatting.

To scan for the signals found in this study:
SigUp is true
or
SigDn is true

Here is a tutorial for adding the scan filter to the scanner:
https://usethinkscript.com/threads/how-to-use-thinkorswim-stock-hacker-scans.284/

vYAUeGY.png


Ruby:
# SCAN SCRIPT ONLy
#indicator("Z-Score Heikin Ashi Transformed"
# converted by Sam4Cok@Samer800    - 07/2023

script f_z {
    input src = close;
    input len = 21;
    def mean = Average(src, len);
    def dev = StDev(src, len);
    def f_z = (src - mean) / dev;
    plot out = f_z;
}
input Zperiod = 21;            # 'Z Period'
input ReversionThreshold = {"1", default "2", "3"};    # "Reversion Threshold"
input showMovAvgLine1 = yes;
input movAvgLength1 = 50;
input showMovAvgLine2 = yes;
input movAvgLength2 = 150;

def na = Double.NaN;
def last = isNaN(close);

def revt;
Switch (ReversionThreshold) {
Case "1" : revt = 1;
Case "2" : revt = 2;
Case "3" : revt = 3;
}

def o_z = f_z(open, Zperiod);
def h_z = f_z(high, Zperiod);
def l_z = f_z(low, Zperiod);
def c_z = f_z(close, Zperiod);

def haClose = (o_z + h_z + l_z + c_z) / 4;
def haOpen = CompoundValue(1, (haOpen[1] + haClose[1]) / 2, (o_z + c_z) / 2);
def haHigh = Max(h_z, Max(haOpen, haClose));
def haLow = Min(l_z, Min(haOpen, haClose));
#def ohlc = (haClose + haOpen + haHigh + haLow) / 4;

def haColor = if haClose > haOpen then 1 else
              if haClose < haOpen then -1 else 0;
def OpenUp = if haColor > 0 then haOpen else na;
def OpenDn = if haColor < 0 then haOpen else na;


def dn = haHigh[1] < haHigh[2];
def up = haLow[1] > haLow[2];

plot SigUp = if (haHigh > revt and haHigh < haHigh[1] and !dn) then haHigh + 0.75 else na;    # "OB"
plot SigDn = if (haLow < -revt and haLow > haLow[1] and !up) then haLow - 0.75 else na;       # "OS"

#--- END of CODE
 
Last edited by a moderator:
3KfhHhv.png

Author Message:
he Z-Score Heikin-Ashi Transformed (𝘡 𝘏-𝘈) indicator is a powerful technical tool that combines the principles of Z-Score and Heikin Ashi to provide traders with a smoothed representation of price movements and a standardized measure of market volatility.

The 𝘡 𝘏-𝘈 indicator applies the Z-Score calculation to price data and then transforms the resulting Z-Scores using the Heikin Ashi technique. Understanding the individual components of Z-Score and Heikin Ashi will provide a foundation for comprehending the methodology and unique features of this indicator.
More Details : https://www.tradingview.com/v/MFW8vsmU/

CODE:

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#https://www.tradingview.com/v/MFW8vsmU/
#// © QuantiLuxe
#indicator("Z-Score Heikin Ashi Transformed", "{?} - ? ?-?", false)
# converted by Sam4Cok@Samer800    - 07/2023
declare lower;
#f_z(src, len) =>
script f_z {
    input src = close;
    input len = 21;
    def mean = Average(src, len);
    def dev = StDev(src, len);
    def f_z = (src - mean) / dev;
    plot out = f_z;
}
input Zperiod = 21;            # 'Z Period'
input showSignals = yes;
input ReversionThreshold = {"1", default "2", "3"};    # "Reversion Threshold"
input showMovAvgLine1 = yes;
input movAvgLength1 = 50;
input showMovAvgLine2 = yes;
input movAvgLength2 = 150;

def na = Double.NaN;
def last = isNaN(close);

def revt;
Switch (ReversionThreshold) {
Case "1" : revt = 1;
Case "2" : revt = 2;
Case "3" : revt = 3;
}
#-- Colors
DefineGlobalColor("colup", CreateColor(255,242,204));
DefineGlobalColor("coldn", CreateColor(111,168,220));
DefineGlobalColor("colema1", Color.CYAN);
DefineGlobalColor("colema2", Color.MAGENTA);
DefineGlobalColor("low", CreateColor(255,214,232));
DefineGlobalColor("dlow", Color.PLUM);

def o_z = f_z(open, Zperiod);
def h_z = f_z(high, Zperiod);
def l_z = f_z(low, Zperiod);
def c_z = f_z(close, Zperiod);

def haClose = (o_z + h_z + l_z + c_z) / 4;
def haOpen = CompoundValue(1, (haOpen[1] + haClose[1]) / 2, (o_z + c_z) / 2);
def haHigh = Max(h_z, Max(haOpen, haClose));
def haLow = Min(l_z, Min(haOpen, haClose));
#def ohlc = (haClose + haOpen + haHigh + haLow) / 4;

def haColor = if haClose > haOpen then 1 else
              if haClose < haOpen then -1 else 0;
def OpenUp = if haColor > 0 then haOpen else na;
def OpenDn = if haColor < 0 then haOpen else na;

# Plot the new Chart
AddChart(high = if haColor > 0 then haHigh else na , low = haLow , open = haClose,  close = OpenUp,
         type = ChartType.CANDLE, growcolor =  GlobalColor("colup"));

AddChart(high = if haColor < 0 then haHigh else na, low = haLow , open = OpenDn,  close = haClose,
         type = ChartType.CANDLE, growcolor =  GlobalColor("coldn"));

plot EMA1 = if showMovAvgLine1 then ExpAverage(haClose, movAvgLength1) else na;
plot EMA2 = if showMovAvgLine2 then ExpAverage(haClose, movAvgLength2) else na;
EMA1.SetDefaultColor(GlobalColor("colema1"));
EMA2.SetDefaultColor(GlobalColor("colema2"));

plot zero = if last then na else 0;    # "Mid Line"
zero.SetStyle(Curve.SHORT_DASH);
zero.SetDefaultColor(Color.DARK_GRAY);

def max = if last then na else 4;
def hh = if last then na else 3;
def lh = if last then na else 2;

DefineGlobalColor("high", Color.DARK_GRAY);
DefineGlobalColor("dhigh", Color.WHITE);
AddCloud(hh, lh, GlobalColor("dhigh"));
AddCloud(max, hh, GlobalColor("high"));

def min = if last then na else -4;
def ll = if last then na else -3;
def hl = if last then na else -2;

AddCloud(hl, ll, GlobalColor("dlow"));
AddCloud(ll, min, GlobalColor("low"));

def dn = haHigh[1] < haHigh[2];
def up = haLow[1] > haLow[2];

plot SigUp = if !showSignals then na else
             if (haHigh > revt and haHigh < haHigh[1] and !dn) then haHigh + 0.75 else na;    # "OB"
plot SigDn = if !showSignals then na else
             if (haLow < -revt and haLow > haLow[1] and !up) then haLow - 0.75 else na;       # "OS"

SigUp.SetPaintingStrategy(PaintingStrategy.SQUARES);
SigDn.SetPaintingStrategy(PaintingStrategy.SQUARES);
SigUp.SetDefaultColor(Color.GREEN);
SigDn.SetDefaultColor(Color.RED);

#--- END of CODE
I have been using this indicator for several weeks on a 1-5-10 minute basis. I tried setting up two different scans based on the up and down signals being true. However, nothing comes up. Perhaps my selection is wrong. Is it possible to set up a scan based on a certain level of the indicator ( above or below a certain level) ? I have attached the article by Samir in July 2023 and a copy of my Scan set up box. Many thanks for all your help to the user base.

Is there a way to scan if the Z Score is above or below a certain number?
 
Last edited by a moderator:
@TechGuy

The "levels" in this thread are not z-score. The levels shown in this thread pertain to Heiken-Ashi Trend Levels.
This is a HA Trend Indicator where the trend lengths (are dynamically calculated with Z-score math)

To look for the HA Trend Level:
Add this code snippet to the bottom of the scan script provided above:
https://usethinkscript.com/threads/...ransformed-for-thinkorswim.15964/#post-151949
input certainNumber = .75;
plot belowLevels = haclose < certainNumber;
plot aboveLevels = haclose > certainNumber;

Scan Filters ==
belowLevels is true
or
aboveLevels is true

Here is a tutorial for adding the scan filter to the scanner:
https://usethinkscript.com/threads/how-to-use-thinkorswim-stock-hacker-scans.284/

This is an interesting idea. But not sure what the scan's purpose is?
Come back and lets us know how this aids your trading strategy.
qDJAFzF.png
 
Last edited:
@TechGuy

The "levels" in this thread are not z-score. The levels shown in this thread pertain to Heiken-Ashi Trend Levels.
This is a HA Trend Indicator where the trend lengths (are dynamically calculated with Z-score math)

To look for the HA Trend Level:
Add this code snippet to the bottom of the scan script provided above:
https://usethinkscript.com/threads/...ransformed-for-thinkorswim.15964/#post-151949


Scan Filters ==

or


Here is a tutorial for adding the scan filter to the scanner:
https://usethinkscript.com/threads/how-to-use-thinkorswim-stock-hacker-scans.284/

This is an interesting idea. But not sure what the scan's purpose is?
Come back and lets us know how this aids your trading strategy.
qDJAFzF.png
Many thanks Merry Day this script for the levels... works very well on a scan.
 
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
424 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