This script is a specialized technical analysis tool designed to measure market momentum and volatility simultaneously. It functions as a sophisticated variation of a "Stochastic" oscillator, modified to respond more dynamically to specific price behaviors and trading volume.

Instead of simply looking at price movement, the logic follows a multi-layered process to filter out "noise" and highlight meaningful trends:

1. Data Source Selection

The indicator begins by selecting a primary data stream. Depending on your settings, it can track different types of market activity, such as:

  • Trading Volume: How much activity is happening.
  • ATR (Average True Range): A measure of price volatility.
  • Standard Deviation: How much the price deviates from its average.
  • Price Action: Specific movements like "Close" prices or High/Low ranges.

2. The Normalization Process

Once a source is chosen, the script performs a "Normalization" step. It looks at a specific window of recent data to find the highest and lowest points. It then calculates where the current price sits within that range (from 0 to 100).

  • Sensitivity Logic: A unique feature here is the sensitivity threshold. If the market range is smaller than your defined threshold, the script automatically adjusts the "floor" of the calculation. This helps prevent the indicator from becoming too erratic when the market is moving very sideways or in a tight range.

3. Smoothing and Signal Filtering

Raw data is often jagged and difficult to read. The script applies several layers of smoothing:

  • Slowdown/Power: It adjusts the speed at which the data reacts to new information.
  • Moving Averages: It uses either Simple Moving Averages (SMA) or Exponential Moving Averages (EMA)—depending on your settings—to turn jagged lines into smooth curves.
  • Signal Decay: This is a specific logic step where the "Signal" line retains its previous value unless a new, higher peak is reached. This helps in identifying sustained momentum rather than temporary spikes.

4. Stochastic Integration and Final Output

The final stage combines the smoothed volatility data with a standard Stochastic calculation.

  • It takes the "Normalized Volatility" and modulates it against the standard Stochastic oscillator (shifted to a center point of 50).
  • The Result: You are left with two primary lines: the main Stochastic line (the core trend) and the Signal line (a smoothed version used to identify turning points).

Summary for the User

In plain terms, this script doesn't just tell you where the price is; it calculates how "strong" the current move is by comparing it to recent volatility and volume. By smoothing out the "noise" of the market and applying a sensitivity threshold, it aims to provide a clearer picture of whether a price movement is a significant trend or just a minor fluctuation.

Indicators Used
Indicator of the average true rangeStandard Deviation indicatorStochastic oscillator
Miscellaneous
Implements a curve of type %1
16 Views
0 Downloads
0 Favorites
7StochAM
//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2012, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
/*
iCustom(NULL,0,"~StochAM",Kperiod,Dperiod,Slowing,PriceField, Source,SourcePeriod,Window,Sens,Power,Smooth,Signal,Fade, N,i);
ãäå N:
0 - ñòîõàñòèê
1 - ñèãíàëüíàÿ %D
2 - ðåç-ò íîðìèðîâàíèÿ
3 - ñãëàæèâàíèå çàòóõàíèÿ
4 - áóôåð èñòî÷íèêà âîëàòèëüíîñòè // íå âûâîäèòñÿ
5 - ñûðîå íîðìèðîâàíèå // íå âûâîäèòñÿ
*/

#property indicator_separate_window // â îêíå èíäèêàòîðà
#property indicator_buffers 6
#property indicator_color1 Green // ñòîõàñòèê
#property indicator_color2 Red // ñèãíàëüíàÿ
#property indicator_maximum 100
#property indicator_minimum 0
#property indicator_level1 80
#property indicator_level2 20

// âõîäíûå ïàðàìåòðû
extern int Kperiod=5; // %K
extern int Dperiod=3; // %D: >0 SMA, <0 EMA
double kDp; // êîýôô.EMA äëÿ %D
bool bDp;
extern int Slowing=3; // çàìåäëåíèå
int Method=0; // ìåòîä ñãëàæèâàíèÿ %D
extern int PriceField=0; // 0- High/Low, 1- Close
extern int Source=2; // 0- îáúåì, 1- ATR, 2- ñò.äåâ., 3- Close
extern int SourcePeriod=5; // ïåðèîä èñòî÷íèêà, <0 EMA, >0 SMA
double kSp; // êîýôô.EMA äëÿ SourcePeriod
bool bSp;
extern int Window=5; // îêíî íîðìèðîâàíèÿ â áàðàõ
extern double Sens=2; // ïîðîã ÷óâñòâòèòåëüíîñòè â ïï.èëè òèêàõ (îáúåì)
double sens; // ïîðîã ÷óâñòâòèòåëüíîñòè â öåíàõ èëè òèêàõ (îáúåì)
extern double Power=2; // ñòåïåíü äëÿ ïåðåäàòî÷íîé ôóíêöèè
extern int Smooth=1; // ñãëàæèâàíèå íîðìèðîâàíèÿ
double kSm; // êîýôô.EMA äëÿ Smooth
bool bSl;
extern int Signal=1; // ñèãíàëüíàÿ
double kSg; // êîýôô.EMA äëÿ Signal
bool bSg;
extern int Fade=12; // çàòóõàíèå ñèãíàëüíîé
double kFd; // êîýôô.EMA äëÿ Fade

int History=0; // 0- âñå áàðû

               // ìàññèâû èíä.áóôåðîâ
double
STH[], // ñòîõàñòèê
SGN[], // ñèãíàëüíàÿ (%D) ñòîõàñòèêà
NRM[], // ðåç-ò íîðìèðîâàíèÿ
NEG[], // ñãëàæèâàíèå çàòóõàíèÿ
SRC[], // áóôåð èñòî÷íèêà âîëàòèëüíîñòè // íå âûâîäèòñÿ
NR0[]; // ñûðîå íîðìèðîâàíèå // íå âûâîäèòñÿ

       // îáùèå (ãëîáàëüíûå) ïåðåìåííûå
bool first=1; // ôëàã ïåðâîãî çàïóñêà
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
// èíèöèàëèçàöèÿ
int init()
  {
   first=1; // ôëàã ïåðâîãî çàïóñêà
   string _sth="Stoch("+(string)Kperiod+","+(string)Dperiod+","+(string)Slowing+") ";
   if(Source>0) sens=Sens*Point; // ïðèâåäåíèå ïîðîãà ê öåíàì äëÿ öåíîâûõ èñòî÷íèêîâ
   else sens=Sens;
   if(Sens>0) string _sn=DoubleToStr(Sens,1)+" ";
// âû÷èñëåíèå êîýôôèöèåíòîâ EMA
   if(Dperiod<0) {Dperiod=-Dperiod; kDp=2.0/(1+Dperiod); bDp=1;} else bDp=0;
   if(SourcePeriod<0) {SourcePeriod=-SourcePeriod; kSp=2.0/(1+SourcePeriod); bSp=1;} else bSp=0;
   if(Smooth<0) {Smooth=-Smooth; kSm=2.0/(1+Smooth); bSl=1;} else bSl=0;
   if(Signal<0) {Signal=-Signal; kSg=2.0/(1+Signal); bSg=1;} else bSg=0;
   kFd=2.0/(1+Fade);

   string _sgfd=" ("+(string)Signal+","+(string)Fade+")";
   string _src="";
   switch(Source)
     {
      case 0: _src=_src+"Volume"; break; // îáúåì
      case 1: _src=_src+"ATR"; break; // ATR
      case 2: _src=_src+"StDev"; break; // ñò.äåâèàöèÿ
      case 3: _src=_src+"Close"; break; // Close
      case 4: _src=_src+"H/L"; // High/Low
     }
   _src=_src+"("+(string)SourcePeriod+")";
   string _nrm=" ["+(string)Window+","+(string)Smooth+"]";
   IndicatorShortName(_sth+_sn+_src+_nrm+_sgfd);

// èíä.áóôåðû
   SetIndexBuffer(0,STH);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexLabel(0,_sth);

   SetIndexBuffer(1,SGN);
   SetIndexStyle(1,DRAW_LINE,2);
   SetIndexLabel(1,"Sgn("+(string)Slowing+")");

   SetIndexBuffer(2,NRM);
   SetIndexStyle(2,DRAW_NONE);
   SetIndexLabel(2,_nrm);

   SetIndexBuffer(3,NEG);
   SetIndexStyle(3,DRAW_NONE,2);
   SetIndexLabel(3,"Neg"+_sgfd);

   SetIndexBuffer(4,SRC);
   SetIndexStyle(4,DRAW_NONE);
   SetIndexLabel(4,NULL);

   SetIndexBuffer(5,NR0);
   SetIndexStyle(5,DRAW_NONE);
   SetIndexLabel(5,NULL);

   return(0);
  }
// ô-ÿ äîïîëíèòåëüíîé èíèöèàëèçàöèè
int reinit()
  {
   ArrayInitialize(STH,0.0); // îáíóëåíèå ìàññèâà
   ArrayInitialize(SGN,0.0); // îáíóëåíèå ìàññèâà
   ArrayInitialize(NRM,0.0); // îáíóëåíèå ìàññèâà
   ArrayInitialize(NEG,0.0); // îáíóëåíèå ìàññèâà
   ArrayInitialize(SRC,0.0); // îáíóëåíèå ìàññèâà
   ArrayInitialize(NR0,0.0); // îáíóëåíèå ìàññèâà
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   int ic=IndicatorCounted();
   if(!first && Bars-ic-1>1) ic=reinit(); // åñëè åñòü ïðîïóùåííûå áàðû íå íà ïîäêëþ÷åíèè - ïåðåñ÷åò
   bool ic0=ic==0; // ôëàã ïåðåñ÷åòà
   int limit=Bars-ic; // êîë-âî ïåðåñ÷åòîâ
   if(ic==0)
     {
      reinit();
      limit-=3;
     }
   for(int i=limit; i>=0; i--)
     { // öèêë ïåðåñ÷åòà ïî ÂÑÅÌ áàðàì
      bool reset=i==limit && ic0; // ñáðîñ íà ïåðâîé èòåðàöèè öèêëà ïåðåñ÷åòà
      if(reset)
        {
         static int BarsPrev=0; // ïðåä. çíà÷åíèå Bars
        }
      bool NewBar=(ic0 && i>0) || BarsPrev!=Bars; // ïåðâûé òèê íîâîãî áàðà
                                                  //=========================================
      // èñòî÷íèê
      int sh=i+SourcePeriod;
      switch(Source)
        {
         case 0: // îáúåì
            if(bSp) SRC[i]=kSp*Volume[i]+(1-kSp)*SRC[i+1]; // ÅÌÀ
            else
              { // SMA
               double ma=SRC[i+1]*SourcePeriod-Volume[sh];
               SRC[i]=(ma+Volume[i])/SourcePeriod;
              }
            break;
         case 1: SRC[i]=iATR(NULL,0,SourcePeriod,i); break; // ATR
         case 2: SRC[i]=iStdDev(NULL,0,SourcePeriod,0,bSp,0,i); break; // ñò.äåâèàöèÿ
         case 3: // Close
            if(bSp) SRC[i]=kSp*Close[i]+(1-kSp)*SRC[i+1]; // ÅÌÀ
            else
              { // SMA
               ma=SRC[i+1]*SourcePeriod-Close[sh];
               SRC[i]=(ma+Close[i])/SourcePeriod;
              }
            break;
        }
      //=========================================
      // íîðìèðîâàíèå
      // ýêñòðåìóìû
      double max=SRC[ArrayMaximum(SRC,Window,i)];
      double min=SRC[ArrayMinimum(SRC,Window,i)];
      double c=SRC[i];
      // øóìîïîäàâëåíèå
      double delta=max-min; // ðàçìàõ
      double diff=sens-delta; // ðàçíèöà ìåæäó ïîðîãîì ÷óâñòâ. è ðàçìàõîì
      if(diff>0)
        { // åñëè ðàçíèöà >0 (ðàçìàõ ìåíüøå ïîðîãà), òî
         delta=sens; // ðàçìàõ = ïîðîãó,
         min-=diff/2; // íîâîå çíà÷åíèå ìèíèìóìà
        }
      // íîðìèðîâàíèå
      if(delta!=0) NR0[i]=MathPow((c-min)/delta,Power);
      //==
      // çàìåäëåíèå
      if(bSl) NRM[i]=kSm*NR0[i]+(1-kSm)*NRM[i+1]; // EMA
      else
        { // SMA
         sh=i+Smooth;
         ma=NRM[i+1]*Smooth-NR0[sh];
         NRM[i]=(ma+NR0[i])/Smooth;
        }
      //==
      // ñèãíàëüíàÿ
      if(reset) {static double sgnPrev=0;}
      if(bSg) double sgn=kSg*NRM[i]+(1-kSg)*sgnPrev; // EMA
      else
        { // SMA
         sh=i+Signal;
         ma=sgnPrev*Signal-NRM[sh];
         sgn=(ma+NRM[i])/Signal;
        }
      //==      
      // çàòóõàíèå ñèãíàëüíîé
      // ïî çàòóõàíèþ
      NEG[i]=kFd*sgn+(1-kFd)*NEG[i+1];
      if(sgn>NEG[i+1]) NEG[i]=sgn;

      //=========================================
      // ñòîõàñòèê
      double sth=iStochastic(NULL,0,Kperiod,1,Slowing,0,PriceField,0,i)-50;
      STH[i]=NEG[i]*sth+50; // ìîäóëÿöèÿ íîìèðîâàííîé âîëàòèëüíîñòüþ
                            // ñèãíàëüíàÿ %D
      if(bDp) SGN[i]=kDp*STH[i]+(1-kDp)*SGN[i+1]; // EMA
      else
        { // SMA
         sh=i+Dperiod;
         if(sh<ArraySize(STH) && i+1<ArraySize(SGN))
           {
            ma=SGN[i+1]*Dperiod-STH[sh];
            SGN[i]=(ma+STH[i])/Dperiod;
           }
        }
      //=========================================
      // ñèíõðîíèçàöèÿ
      if(NewBar) {sgnPrev=sgn; BarsPrev=Bars;}
     }
   first=0; // ñáðîñ ôëàãà ïåðâîãî öèêëà
   return(0);
  }
//+------------------------------------------------------------------+

Comments