Multi Z Score [DW]
"Multi Z Score [DW]" by DonovanWall, MPL-2.0. Ported to FloScript by FloSignals; modifications under MPL-2.0. Original: Multi Z Score [DW] (v3.0), read 2026-10-12T15:59:24.941Z; source language v4.
Licence: Mozilla Public License 2.0 (MPL-2.0) — full text. The source is published with it, modifications included, under the same licence.
Multi Z Score [DW] by DonovanWall, ported from Pine v4. Pane indicator with 18 plots, bar/background colouring and 37 inputs.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © DonovanWall
//██████╗ ██╗ ██╗
//██╔══██╗██║ ██║
//██║ ██║██║ █╗ ██║
//██║ ██║██║███╗██║
//██████╔╝╚███╔███╔╝
//╚═════╝ ╚══╝╚══╝
// ------------------------------------------------------------------------------------------------
// Original author: DonovanWall
// Original title: Multi Z Score [DW]
// Licence: MPL-2.0 (the header above is the original notice, kept verbatim)
// Pine version: 4
// Fetched: 2026-10-12
// Ported to FloScript by FloSignals; modifications under MPL-2.0.
// Converter: @flosignals/floscript 0.1.0, strict mode, score 100/100
// ------------------------------------------------------------------------------------------------
//@floscript=1
//@version=5
// Converted by the FloScript converter from a Pine-compatible v4 source.
indicator(title="Multi Z Score [DW]", shorttitle="Multi Z [DW]", overlay=false)
//by Donovan Wall
//This is an experimental study using z scores of multiple sampling periods to analyze price trends.
//Z score measures the number of standard deviations price is from its mean.
//In this study, z scores are calculated over a Fibonacci sequence of sampling periods from 3 to 4181.
//The scores are then averaged with equal weighting, resulting in a display of long term trend with short term sensitivity.
//Custom bar colors are included. The color scheme is based on the perceived trend from the average z score.
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Updates:
//Added dynamic weightings to the script based on a request @mcbw_.
//There are four weigting methods to choose from:
// -> Equal Weights - The original method.
// -> Volume Weights - Weights each Z score by its cumulative volume
// -> Length Weights - Weights each Z score by its sampling period
// -> Volatility Weights - Weights each Z score by its standard deviation of price over its respective sampling period
//Added exponential smoothing to the script for a noise reduced result
//Made some changes to the aesthetic:
// -> Average Z Score is now plotted as columns
// -> Individual Z Scores are now plotted as circles
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Updates:
// -> Migrated to v4.
// -> Rebuilt script and reorganized the structure.
// -> Main calculations have been converted to functions.
// -> Z-scores now have adjustable periods and toggle switches so you can customize your experience.
// -> Fixed an issue with volume detection. Now, when volume weigths are being used, tick volume will automatically be used when real volume is NaN.
// -> Added an option to invert the weights for average Z-score. Enabling this will place heavier weighting on shorter term data. This does not affect the output when equal weights are used.
// -> Revamped color scheme.
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Functions
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Z-Score Function
z_score(x, t) =>
(x - ta.sma(x, t)) / ta.stdev(x, t)
//Weighting Function
z_wt(x, t, v, method, invert) =>
z_wt1 = method == "Equal Weights" ? 1 : method == "Volume Weights" ? math.sum(v, t) : method == "Length Weights" ? t : ta.stdev(x, t)
z_wt = invert ? 1 / z_wt1 : z_wt1
z_wt
//Color Function
z_color(z) =>
z > 0 and z > nz(z[1]) ? #0affa8 : z > 0 and z <= nz(z[1]) ? #00945f : z < 0 and z < nz(z[1]) ? #ff0a70 : z < 0 and z >= nz(z[1]) ? #990040 : #cccccc
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Inputs
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Source
src = input(defval=close, title="Source")
//Z1 Inputs
use_z1 = input(defval=true, title="Use Z1")
per1 = input.int(defval=3, minval=1, title="Z1 Period")
//Z2 Inputs
use_z2 = input(defval=true, title="Use Z2")
per2 = input.int(defval=5, minval=1, title="Z2 Period")
//Z3 Inputs
use_z3 = input(defval=true, title="Use Z3")
per3 = input.int(defval=8, minval=1, title="Z3 Period")
//Z4 Inputs
use_z4 = input(defval=true, title="Use Z4")
per4 = input.int(defval=13, minval=1, title="Z4 Period")
//Z5 Inputs
use_z5 = input(defval=true, title="Use Z5")
per5 = input.int(defval=21, minval=1, title="Z5 Period")
//Z6 Inputs
use_z6 = input(defval=true, title="Use Z6")
per6 = input.int(defval=34, minval=1, title="Z6 Period")
//Z7 Inputs
use_z7 = input(defval=true, title="Use Z7")
per7 = input.int(defval=55, minval=1, title="Z7 Period")
//Z8 Inputs
use_z8 = input(defval=true, title="Use Z8")
per8 = input.int(defval=89, minval=1, title="Z8 Period")
//Z9 Inputs
use_z9 = input(defval=true, title="Use Z9")
per9 = input.int(defval=144, minval=1, title="Z9 Period")
//Z10 Inputs
use_z10 = input(defval=true, title="Use Z10")
per10 = input.int(defval=233, minval=1, title="Z10 Period")
//Z11 Inputs
use_z11 = input(defval=true, title="Use Z11")
per11 = input.int(defval=377, minval=1, title="Z11 Period")
//Z12 Inputs
use_z12 = input(defval=true, title="Use Z12")
per12 = input.int(defval=610, minval=1, title="Z12 Period")
//Z13 Inputs
use_z13 = input(defval=true, title="Use Z13")
per13 = input.int(defval=987, minval=1, title="Z13 Period")
//Z14 Inputs
use_z14 = input(defval=true, title="Use Z14")
per14 = input.int(defval=1597, minval=1, title="Z14 Period")
//Z15 Inputs
use_z15 = input(defval=true, title="Use Z15")
per15 = input.int(defval=2584, minval=1, title="Z15 Period")
//Z16 Inputs
use_z16 = input(defval=true, title="Use Z16")
per16 = input.int(defval=4181, minval=1, title="Z16 Period")
//Weighting Method
w_method = input.string(defval="Equal Weights", options=["Equal Weights", "Volume Weights", "Length Weights", "Volatility Weights"], title="Average Z Score Weighting Method")
w_invert = input(defval=false, title="Invert Weights")
//Volume Type
voltype = input.string(defval="Default", options=["Default", "Tick"], title="Volume Type (for Volume Weighting)")
//Smoothing Period
smper = input.int(defval=2, minval=1, title="Smoothing Period")
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Definitions
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Z-Scores
z1 = use_z1 ? z_score(src, per1) : 0
z2 = use_z2 ? z_score(src, per2) : 0
z3 = use_z3 ? z_score(src, per3) : 0
z4 = use_z4 ? z_score(src, per4) : 0
z5 = use_z5 ? z_score(src, per5) : 0
z6 = use_z6 ? z_score(src, per6) : 0
z7 = use_z7 ? z_score(src, per7) : 0
z8 = use_z8 ? z_score(src, per8) : 0
z9 = use_z9 ? z_score(src, per9) : 0
z10 = use_z10 ? z_score(src, per10) : 0
z11 = use_z11 ? z_score(src, per11) : 0
z12 = use_z12 ? z_score(src, per12) : 0
z13 = use_z13 ? z_score(src, per13) : 0
z14 = use_z14 ? z_score(src, per14) : 0
z15 = use_z15 ? z_score(src, per15) : 0
z16 = use_z16 ? z_score(src, per16) : 0
//Volume Type With Tick Volume Substitution When Real Volume is NaN
tick = syminfo.mintick
rng = close - open
tickrng = tick
tickrng := math.abs(rng) < tick ? nz(tickrng[1]) : rng
tickvol = math.abs(tickrng) / tick
vol = voltype == "Default" ? (na(volume) ? tickvol : volume) : tickvol
//Weights
w1 = z_wt(src, per1, vol, w_method, w_invert)
w2 = z_wt(src, per2, vol, w_method, w_invert)
w3 = z_wt(src, per3, vol, w_method, w_invert)
w4 = z_wt(src, per4, vol, w_method, w_invert)
w5 = z_wt(src, per5, vol, w_method, w_invert)
w6 = z_wt(src, per6, vol, w_method, w_invert)
w7 = z_wt(src, per7, vol, w_method, w_invert)
w8 = z_wt(src, per8, vol, w_method, w_invert)
w9 = z_wt(src, per9, vol, w_method, w_invert)
w10 = z_wt(src, per10, vol, w_method, w_invert)
w11 = z_wt(src, per11, vol, w_method, w_invert)
w12 = z_wt(src, per12, vol, w_method, w_invert)
w13 = z_wt(src, per13, vol, w_method, w_invert)
w14 = z_wt(src, per14, vol, w_method, w_invert)
w15 = z_wt(src, per15, vol, w_method, w_invert)
w16 = z_wt(src, per16, vol, w_method, w_invert)
//Composite Weight
w_composite = w1 + w2 + w3 + w4 + w5 + w6 + w7 + w8 + w9 + w10 + w11 + w12 + w13 + w14 + w15 + w16
//Average Z Score
z_average = ta.ema((z1 * w1 + z2 * w2 + z3 * w3 + z4 * w4 + z5 * w5 + z6 * w6 + z7 * w7 + z8 * w8 + z9 * w9 + z10 * w10 + z11 * w11 + z12 * w12 + z13 * w13 + z14 * w14 + z15 * w15 + z16 * w16) / w_composite, smper)
//Colors
z1_color = z_color(z1)
z2_color = z_color(z2)
z3_color = z_color(z3)
z4_color = z_color(z4)
z5_color = z_color(z5)
z6_color = z_color(z6)
z7_color = z_color(z7)
z8_color = z_color(z8)
z9_color = z_color(z9)
z10_color = z_color(z10)
z11_color = z_color(z11)
z12_color = z_color(z12)
z13_color = z_color(z13)
z14_color = z_color(z14)
z15_color = z_color(z15)
z16_color = z_color(z16)
z_av_color = z_color(z_average)
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Outputs
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Center Line
plot(0, color=#cccccc, title="Center Line")
//Z Scores
plot(z1, color=z1_color, style=plot.style_circles, title="Z1")
plot(z2, color=z2_color, style=plot.style_circles, title="Z2")
plot(z3, color=z3_color, style=plot.style_circles, title="Z3")
plot(z4, color=z4_color, style=plot.style_circles, title="Z4")
plot(z5, color=z5_color, style=plot.style_circles, title="Z5")
plot(z6, color=z6_color, style=plot.style_circles, title="Z6")
plot(z7, color=z7_color, style=plot.style_circles, title="Z7")
plot(z8, color=z8_color, style=plot.style_circles, title="Z8")
plot(z9, color=z9_color, style=plot.style_circles, title="Z9")
plot(z10, color=z10_color, style=plot.style_circles, title="Z10")
plot(z11, color=z11_color, style=plot.style_circles, title="Z11")
plot(z12, color=z12_color, style=plot.style_circles, title="Z12")
plot(z13, color=z13_color, style=plot.style_circles, title="Z13")
plot(z14, color=z14_color, style=plot.style_circles, title="Z14")
plot(z15, color=z15_color, style=plot.style_circles, title="Z15")
plot(z16, color=z16_color, style=plot.style_circles, title="Z16")
//Average Z Score
plot(z_average, color=color.new(z_av_color, 50), style=plot.style_columns, title="Average Z")
//Bar Color
barcolor(z_av_color)
This file is under the Mozilla Public License 2.0; it is a port of the original by DonovanWall, with the original licence header kept and the changes made for FloScript noted in the file.
- v2
Library refresh 2026-10-14
- v1
Library refresh 2026-10-12
Disclaimer. Scripts are written and published by members, or ported by FloSignals from open-source originals, and are their authors' own work and opinion. FloSignals does not review them for correctness and nothing in a script is financial advice or a recommendation to buy or sell anything — read the Risk Disclaimer. Posting here is under the Community Rules; a script that is not the poster's to post can be reported as the Copyright & Takedowns page says.

Comments (0)
No comments yet. Members can leave one.