ZScoreAnalysis

Z-score analysis for detecting statistical deviations and excess market behavior
calculate_zscore(source, lookback, threshold, switch_enabled)
Calculate Z-score and related metrics with history tracking
Parameters:
source (float): Data source for Z-score calculation
lookback (int): Lookback period for mean and standard deviation
threshold (float): Z-score threshold for significance
switch_enabled (string): Enable/disable switch ("Enabled"/"Disabled")
Returns: [z_score, z_hist, z_avg] Z-score, historical significant values, and running average
get_zscore_threshold(opt, input_thr, avg)
Get threshold based on threshold option
Parameters:
opt (string): Threshold option ("User Input Threshold", "Average as Threshold", or other)
input_thr (float): User input threshold
avg (float): Average threshold
Returns: Calculated threshold value
is_zscore_filtered(switch_enabled, zscore, threshold)
Check if a metric passes the Z-score filter
Parameters:
switch_enabled (string): Enable/disable switch
zscore (float): Current Z-score value
threshold (float): Z-score threshold
Returns: True if filtered (exceeds threshold)
get_consecutive_distances(body_dir, breakout_dir, is_inside_bar)
Calculate consecutive distances for Z-score analysis
Parameters:
body_dir (int): Body direction
breakout_dir (int): Breakout direction
is_inside_bar (bool): Inside bar flag
Returns: [consecutive_close_dist, consecutive_hl_dist]
get_trend_to_mean_distance()
Calculate distance from trend to mean for momentum analysis
Returns: Distance between trend and mean
get_all_zscores(lookback, threshold, bar_dist_switch, body_dist_switch, chl_dist_switch, cc_dist_switch, m_dist_switch, body_dir, breakout_dir, is_inside_bar)
Get all Z-score calculations for the indicator
Parameters:
lookback (int): Z-score lookback period
threshold (float): Z-score threshold
bar_dist_switch (string): Enable bar distance Z-score
body_dist_switch (string): Enable body distance Z-score
chl_dist_switch (string): Enable consecutive highs/lows Z-score
cc_dist_switch (string): Enable consecutive closes Z-score
m_dist_switch (string): Enable momentum distance Z-score
body_dir (int): Body direction
breakout_dir (int): Breakout direction
is_inside_bar (bool): Inside bar flag
Returns: [z_results] Array of Z-score results and filters
get_combined_zscore_filters(z_filters)
Get combined Z-score filters
Parameters:
z_filters (map<string, bool>): Map of individual Z-score filters
Returns: [combined_filters] Various combinations of Z-score filters
get_basic_distances()
Calculate basic distances used in Z-score analysis
Returns: [bar_dist, body_dist] Bar range and body range
get_individual_zscore_filter(z_filters, filter_name)
Get individual Z-score filter by name
Parameters:
z_filters (map<string, bool>): Map of Z-score filters
filter_name (string): Name of the filter ("bar_dist", "body_dist", etc.)
Returns: Boolean filter result
has_any_zscore_signal(z_filters)
Check if any Z-score filter is active
Parameters:
z_filters (map<string, bool>): Map of individual Z-score filters
Returns: True if any Z-score exceeds threshold
Biblioteca Pine
Fiel al espíritu de TradingView, el autor ha publicado este código de Pine como biblioteca de código abierto, para que otros programadores Pine de nuestra comunidad puedan reutilizarlo. ¡Enhorabuena al autor! Puede usar esta biblioteca de forma privada o en otras publicaciones de código abierto, pero la reutilización de este código en publicaciones está sujeta a nuestras Normas internas.
Exención de responsabilidad
Biblioteca Pine
Fiel al espíritu de TradingView, el autor ha publicado este código de Pine como biblioteca de código abierto, para que otros programadores Pine de nuestra comunidad puedan reutilizarlo. ¡Enhorabuena al autor! Puede usar esta biblioteca de forma privada o en otras publicaciones de código abierto, pero la reutilización de este código en publicaciones está sujeta a nuestras Normas internas.