zscore_mtf
Download scriptThis tool is designed to help traders understand market volatility and price positioning by converting raw market prices into a standardized numerical scale. Instead of looking at the actual price of an asset (like $150 or €1.20), this script measures how far the current price has deviated from its recent average, making it much easier to identify "overbought" or "oversold" conditions across different timeframes.
How the Logic Works
1. Establishing a Baseline (The Average) The tool begins by calculating a moving average of the price over a specific number of bars (defined by the user). This represents the "normal" behavior or the equilibrium of the market for that period. Think of this as the steady path the price usually follows.
2. Measuring the Variation (Standard Deviation) Simultaneously, the script calculates the "Standard Deviation." In simple terms, this measures how much the price typically swings around that baseline average. A high standard deviation means the market is volatile and swinging wildly; a low standard deviation means the market is calm and stable.
3. The Normalization Process (Z-Score) The core logic combines these two pieces of information to create a "Z-Score." It takes the difference between the current price and the average, then divides that difference by the standard deviation.
By doing this math, the script "normalizes" the data:
- If the result is near zero, the price is trading very close to its recent average.
- If the result is a high positive number, the price is significantly higher than usual (potentially overextended).
- If the result is a low negative number, the price is significantly lower than usual (potentially stretched downward).
Key Features for the User
- Multi-Timeframe Analysis: The logic allows you to view this data from various perspectives—ranging from small 1-minute fluctuations to larger daily or weekly trends—allowing for a broader view of market sentiment.
- Visualized Boundaries: The indicator includes preset levels (such as 2, 1, -1, and -2). These act as visual "warning zones." When the line crosses these boundaries, it indicates that the price has moved far enough away from the norm to potentially warrant attention.
- Simplified Interpretation: By stripping away the noise of raw price fluctuations, this tool provides a cleaner look at market momentum, helping you see whether a move is an extreme outlier or just standard market behavior.
//+------------------------------------------------------------------+
//| zscore.mq4 |
//| mtf fx tsd ki modulatum |
//+------------------------------------------------------------------+
// C-MA(C,60)/ Stddev(C,60) normalizes price over a period60
#property copyright "Mod"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 DeepSkyBlue
#property indicator_level1 2
#property indicator_level2 1
#property indicator_level3 -1
#property indicator_level4 -2
#property indicator_levelcolor DarkSlateGray
//---- input parameters
extern int TimeFrame = 0;
extern int Period_ = 20;
extern int barsToCount = 2000;
extern string TimeFrames = "M1;5,15,30,60H1;240H4;1440D1;10080W1;43200MN|0-CurrentTF";
//---- buffers
double zscore[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorBuffers(1);
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,zscore);
//----
IndicatorShortName("zscore ["+TimeFrame+"]");
if (TimeFrame<Period())TimeFrame=Period();
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
datetime TimeArray[];
int i,limit,y=0,counted_bars=IndicatorCounted();
ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),TimeFrame);
limit= Bars-counted_bars;
limit= MathMax(limit,TimeFrame/Period());
limit= MathMin(limit,barsToCount);
//----
for(i=0,y=0;i<limit;i++)
{
if (Time[i]<TimeArray[y]) y++;
// for(int i = 0 ;i <= limit-20 ;i++)
// {
zscore[i] = (iClose(NULL,TimeFrame,y)-iMA(NULL,TimeFrame,Period_,0,0,0,y))/iStdDev(NULL,TimeFrame,Period_,0,0,0,y);
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments