_Channel@Stoch

Download script
_Channel@Stoch

This script is designed as a visual analysis tool for traders who want to identify significant price turning points and volatility boundaries. It works by combining the momentum logic of a Stochastic Oscillator with the structural identification of a ZigZag pattern, creating a dual-layered view of market trends.

Core Logic Overview

The tool functions through three primary logical stages:

1. Momentum Measurement (The Stochastic Filter) The underlying engine uses a Stochastic Oscillator. This calculates the relative position of the current price compared to recent high and low prices. It looks for "overbought" and "oversold" conditions—essentially identifying moments when the price has moved aggressively in one direction and might be due for a correction or a reversal.

2. Peak and Trough Identification Instead of just showing a standard line, the script uses the Stochastic results to "hunt" for structural highs and lows:

  • When momentum is high (Overbought): The logic assumes the market may be reaching a local peak. It then scans back through recent price data to find the actual highest point (the Peak) and its corresponding lowest point (the Trough) during that move.
  • When momentum is low (Oversold): Conversely, it looks for structural bottoms. The script intelligently "switches" its focus between looking for peaks and troughs, ensuring it captures a sequence of price swings rather than isolated noise.

3. Visual Output Options The script provides three distinct ways to visualize this data on your chart:

  • ZigZag Pattern: It can draw the classic zigzag lines connecting these identified peaks and troughs, making it easier to see the "skeleton" of the market trend.
  • Dynamic Channels: It can plot horizontal boundaries based on these extremes. This creates a visual "ceiling" and "floor," helping traders see the range within which the price is currently oscillating.
  • Customizable Visibility: The user can toggle these elements on or off independently, allowing for a clean chart that only shows the specific information needed at any given time.

Summary of User Benefits

By combining momentum (Stochastic) with structural identification (ZigZag/Channels), this tool helps filter out minor price fluctuations. It focuses on highlighting significant market structure—clearly marking where the trend might be exhausting and providing a visual map of the current trading range.

Indicators Used
Stochastic oscillator
Miscellaneous
Implements a curve of type %1
9 Views
0 Downloads
0 Favorites
_Channel@Stoch
#property indicator_chart_window // â îêíå èíñòðóìåíòà
#property indicator_buffers 5
#property indicator_color1 Magenta // çèãçàã
#property indicator_color3 Green // âåðõí. ãð. êàíàëà
#property indicator_color4 Red // íèæí. ãð. êàíàëà
// âõîäíûå ïàðàìåòðû
extern double OverSold=20; // çîíà ïåðåïðîäàííîñòè â %% (çîíà ïåðåêóïëåííîñòè=100-çîíà ÏÏ)
extern int K=5; // %K
extern int Slow=3; // çàìåäëåíèå
extern int SlowMethod=0; // 0-SMA, 1-EMA, 2-SMMA, 3-LWMA
extern int applied_price=0; // 0-High&Low, 1-Close&Close
extern int ShowChannel=2; // ïîêàçàòü 1 - ïî ìåñòó ýêñòðåìóìîâ, 2 - ïî âðåìåíè îïðåäåëåíèÿ
extern int ShowZigZag=0; // ïîêàçàòü 1 - ïî ìåñòó ýêñòðåìóìîâ, 2 - ïî âðåìåíè îïðåäåëåíèÿ
// èíä.áóôåðû
double   ZZpeak[], // ïèê
         ZZtrough[], // âïàäèíà
         ChTop[], // âåðõí. ãð. êàíàëà
         ChBot[], // íèæí. ãð. êàíàëà
         Stoch[]; // Stoch
double   JT[],JP[];
// îáùèå ïåðåìåííûå
double OverBought; // çîíà ïåðåêóïëåííîñòè
bool dir; // 0-ïîéìàíà âïàäèíà, 1 - ïèê
double max,min; // òåêóùèå ìàêñ., ìèíèìóìû
double top,bot; // ïèêè, âïàäèíû
int jDn,jUp; // ñ÷åò÷èêè ðàññòîÿíèÿ ìåæäó ýêñòðåìóìàìè
bool count=1; // íàïðàâëåíèå ïîèñêà öåíîâîãî ýêñòðåìóìà; 1 - îò ñòàðøèõ áàðîâ ê ìëàäøèì
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   if(ShowZigZag<0 || ShowChannel<0) count=0;
   ShowZigZag=MathAbs(ShowZigZag); ShowChannel=MathAbs(ShowChannel);
   OverBought=100.0-OverSold; // çîíà ïåðåêóïëåííîñòè
//---- indicators
   SetIndexBuffer(0,ZZpeak);
   SetIndexEmptyValue(0,0.0);
   SetIndexLabel(0,"Peak");
   
   SetIndexBuffer(1,ZZtrough);
   SetIndexEmptyValue(1,0.0);
   SetIndexLabel(1,"Trough");
   
   if(ShowZigZag>0) {
      SetIndexStyle(0,DRAW_ZIGZAG);
      SetIndexStyle(1,DRAW_ZIGZAG);
     }
   else {      
      SetIndexStyle(0,DRAW_NONE);
      SetIndexStyle(1,DRAW_NONE);
     }

   SetIndexBuffer(2,ChTop);
   SetIndexEmptyValue(2,0.0);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexLabel(2,"ChTop");

   SetIndexBuffer(3,ChBot);
   SetIndexEmptyValue(3,0.0);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexLabel(3,"ChBot");

   if(ShowChannel>0) {
      SetIndexStyle(2,DRAW_LINE);
      SetIndexStyle(3,DRAW_LINE);
     }
   else {      
      SetIndexStyle(2,DRAW_NONE);
      SetIndexStyle(3,DRAW_NONE);
     }

   SetIndexBuffer(4,Stoch);
   SetIndexStyle(4,DRAW_NONE);
   string _st="St("+K+", "+Slow+") "+SlowMethod+", "+applied_price;
   SetIndexLabel(4,_st);

//----
   IndicatorShortName("ZZ@Stoch"); 

   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int ic=IndicatorCounted();
   if(Bars-ic-1>1) ic=reinit();
   int limit=Bars-ic-1; // êîë-âî ïåðåñ÷åòîâ

   for(int i=limit; i>=0; i--) Stoch[i]=iStochastic(NULL,0,K,1,Slow,SlowMethod,applied_price, 0,i); 

   for(i=limit; i>0; i--)
     {
      double st=Stoch[i];
      jDn++; jUp++; // ñ÷åò÷èêè ðàññòîÿíèÿ ìåæäó ýêñòðåìóìàìè

      bool up=st>=OverBought; // 1 - â çîíå ÏÊ
      bool dn=st<=OverSold; // 1 - â çîíå ÏÏ
      
      if(dir) { // åñëè áûë ïîéìàí ïèê
         if(up) { // åñëè â çîíå ÏÊ
            double l=High[i]*100;
            if(count) {for(int k=jUp; k>=0; k--) if(Low[i+k]<l) {int sh=i+k;l=Low[i+k];}}
            else {for(k=0; k<=jUp; k++) if(Low[i+k]<l) {sh=i+k;l=Low[i+k];}}
            bot=Low[sh]; // âïàäèíà = ìèíèìóìó
            if(ShowZigZag==1) ZZtrough[sh]=bot; else ZZtrough[i]=bot;
            if(ShowChannel==1) for(k=sh; k>i; k--) ChBot[k]=bot;
            dir=0; // ïîéìàíà âïàäèíà
           }
        }
      else {
         if(dn) {
            double h=0;
            if(count) {for(k=jDn; k>=0; k--) if(High[i+k]>h) {sh=i+k; h=High[i+k];}}
            else {for(k=0; k<=jDn; k++) if(High[i+k]>h) {sh=i+k; h=High[i+k];}}
            top=High[sh];
            if(ShowZigZag==1) ZZpeak[sh]=top; else ZZpeak[i]=top;
            if(ShowChannel==1) for(k=sh; k>i; k--) ChTop[k]=top;
            dir=1;
           }
        }

      if(up) jUp=-2; if(dn) jDn=-2; // ñáðîñ ñ÷åò÷èêîâ

      for(k=0; k<2; k++) {ChTop[i-k]=top; ChBot[i-k]=bot;}
     }
        
   return(0);
  }


// ô-ÿ äîïîëíèòåëüíîé èíèöèàëèçàöèè
int reinit()
  {
   ArrayInitialize(ZZpeak,0.0);
   ArrayInitialize(ZZtrough,0.0);
   ArrayInitialize(ChTop,0.0);
   ArrayInitialize(ChBot,0.0);
   ArrayInitialize(Stoch,0.0);
   dir=0;max=0;min=0;top=0;bot=0;jDn=0;jUp=0;
   return(0);
  }

Comments