zscore2x_mtf

Download script
Author: Mod
zscore2x_mtf

This tool is designed to provide a clearer picture of market price behavior by "normalizing" the data. In simple terms, it strips away some of the noise of standard price movements to show you how far the current price has drifted from its recent average.

How it Works

The script focuses on a mathematical concept called a Z-Score. This is used to determine if a price is behaving normally or if it is moving into an "extreme" zone compared to its recent history.

To achieve this, the tool performs three main actions simultaneously:

  • Moving Average Calculation: It looks at the closing prices over two different time windows (defined by you as "Period 1" and "Period 2"). This establishes a baseline of what the "normal" price should be based on recent trends.
  • Volatility Measurement: It calculates the Standard Deviation, which measures how much the price typically swings up and down. This helps the tool understand if the market is currently calm or highly volatile.
  • Distance Calculation: Finally, it subtracts the average price from the current price and divides it by the volatility.

What this means for the user

Instead of looking at a chart where prices can jump hundreds of pips, this indicator translates that movement into a numerical score.

  1. Relative Positioning: It tells you how many "units" away the price is from its average. If the score is low, the price is hugging its average; if it is high (or very low), the price has moved significantly far away.
  2. Dual Perspective: Because the script uses two different periods (for example, a short-term and a long-term window), you can see how the current price relates to both immediate trends and broader market history at the same time.
  3. Timeframe Flexibility: The logic is designed to be versatile, allowing you to view these normalized scores across various timeframes (from small minutes to larger monthly views) to identify overextended markets regardless of the asset's actual dollar value.
Price Data Components
Series array that contains close prices for each bar
Indicators Used
Moving average indicatorStandard Deviation indicator
Miscellaneous
Implements a curve of type %1
13 Views
0 Downloads
0 Favorites
zscore2x_mtf
//+------------------------------------------------------------------+
//|                                                       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 2
#property indicator_color1 BlueViolet
#property indicator_color2 DeepSkyBlue

//#property indicator_level1  0
#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  MA1_Period       = 20;
extern int  MA2_Period       = 38;
extern string   note_MA_Method_Mode = "SMA0 EMA1 SMMA2 LWMA3";
extern int  MA1_Method   = 0;
extern int  MA2_Method   = 0;
extern string   note_Price = "C0,O1, 2H3L,4Md 5Tp 6WghC: Md(HL/2)4,Tp(HLC/3)5,Wgh(HLCC/4)6";
extern int  MA1_Price    = 0;
extern int  MA2_Price    = 0;
extern bool DrawMa1Histo = true;


extern int       barsToCount = 2000;
extern string  TimeFrames  = "M1;5,15,30,60H1;240H4;1440D1;10080W1;43200MN|0-CurrentTF";

//---- buffers
double zscore1[];
double zscore2[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorBuffers(2);

   SetIndexBuffer(1,zscore1);
   SetIndexBuffer(0,zscore2);
  if (DrawMa1Histo)  SetIndexStyle(0,DRAW_HISTOGRAM);
  else  SetIndexStyle(0,DRAW_LINE);
  SetIndexStyle(1,DRAW_LINE);
  //---- 
   IndicatorShortName("zscore ["+TimeFrame+"]"+MA1_Period+"|"+MA2_Period+"");

  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++; 

      
      zscore1[i] = (iClose(NULL,TimeFrame,y)-iMA(NULL,TimeFrame,MA1_Period,0,MA1_Method,MA1_Price,y))/iStdDev(NULL,TimeFrame,MA1_Period,0,MA1_Method,MA1_Price,y);  
      zscore2[i] = (iClose(NULL,TimeFrame,y)-iMA(NULL,TimeFrame,MA2_Period,0,MA2_Method,MA2_Price,y))/iStdDev(NULL,TimeFrame,MA2_Period,0,MA2_Method,MA2_Price,y);  

   }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments