_Channel@SAR

Download script
_Channel@SAR

This technical tool is designed to provide traders with a comprehensive visual overlay for analyzing market structure, price extremes, and potential trend reversals. It combines several core trading concepts into a single indicator to help identify significant "peaks" (highs) and "troughs" (lows) while establishing dynamic price boundaries.

Core Logic & Components

The script operates by synchronizing three distinct visual elements to provide a multi-layered view of market behavior:

1. Parabolic Stop and Reverse (SAR) Integration The foundation of this logic relies on the SAR calculation. The tool uses this to detect "flips" in momentum. It constantly monitors the relationship between the SAR value and the midpoint of the price candles. When the SAR crosses over these midpoints, the script interprets it as a signal that the current price movement is losing steam or reversing direction.

2. Peak and Trough Identification (ZigZag Logic) Once a reversal signal is detected via the SAR logic, the script automatically searches for the highest high or lowest low within a specific window of time.

  • Peak Detection: When a downward reversal is signaled, the tool identifies the highest price reached in that move.
  • Trough Detection: When an upward reversal is signaled, it identifies the lowest price reached. These points are then plotted on the chart as ZigZag lines (depending on user settings), allowing traders to see the "skeleton" of the market trend clearly.

3. Dynamic Channel Mapping Beyond just marking single points, the script can project the high and low values of these identified extremes onto the chart to form a channel. Instead of just showing where a peak was, it can draw lines representing the boundaries of the current price action. This helps in visualizing support and resistance zones, effectively creating a visual "corridor" that the price is currently navigating.

Key Features for the User

  • Customizable Visibility: The logic allows you to toggle between showing extremes based on the specific bar where they occurred or based on the time/location of the reversal.
  • Dual-Mode Display: You can choose to view the data as a classic ZigZag (connecting points) or as a structural Channel (defining the high and low bounds).
  • Automated Scanning: The script handles the complex calculations of searching back through previous bars to find the absolute highest or lowest price once a reversal is triggered, ensuring that the "peaks" and "troughs" shown are the most accurate representations of the move.

Summary for Trading Strategy

By combining these elements, the tool serves as a structural map. It tells the trader: "Here is where the price has peaked, here is the floor it has hit, and here is the channel boundary we should expect the price to respect." It filters out market noise by focusing on confirmed reversals rather than every minor price fluctuation.

Indicators Used
Parabolic Stop and Reverse system
Miscellaneous
Implements a curve of type %1
7 Views
0 Downloads
0 Favorites
_Channel@SAR
#property indicator_chart_window // â îêíå èíñòðóìåíòà
#property indicator_buffers 5
#property indicator_color1 Magenta // çèãçàã
#property indicator_color3 Green // âåðõí. ãð. êàíàëà
#property indicator_color4 Red // íèæí. ãð. êàíàëà
#property indicator_color5 Blue // íèæí. ãð. êàíàëà
// âõîäíûå ïàðàìåòðû
extern double Step=0.02; // íà÷àëüíîå çíà÷åíèå è øàã
extern double Maximum=0.2; // êîíå÷íîå çíà÷åíèå
extern int ShowChannel=2; // ïîêàçàòü 1 - ïî ìåñòó ýêñòðåìóìîâ, 2 - ïî âðåìåíè îïðåäåëåíèÿ
extern int ShowZigZag=0; // ïîêàçàòü 1 - ïî ìåñòó ýêñòðåìóìîâ, 2 - ïî âðåìåíè îïðåäåëåíèÿ
// èíä.áóôåðû
double   ZZpeak[], // ïèê
         ZZtrough[], // âïàäèíà
         ChTop[], // âåðõí. ãð. êàíàëà
         ChBot[], // íèæí. ãð. êàíàëà
         SAR[]; // SAR
// îáùèå ïåðåìåííûå
double OverBought; // çîíà ïåðåêóïëåííîñòè
bool dir; // 0-ïîéìàíà âïàäèíà, 1 - ïèê
double max,min; // òåêóùèå ìàêñ., ìèíèìóìû
double top,bot; // ïèêè, âïàäèíû
int j; // ñ÷åò÷èê ñìåùåíèÿ
bool count=1; // íàïðàâëåíèå ïîèñêà öåíîâîãî ýêñòðåìóìà; 1 - îò ñòàðøèõ áàðîâ ê ìëàäøèì
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   if(ShowZigZag<0 || ShowChannel<0) count=0;
   ShowZigZag=MathAbs(ShowZigZag); ShowChannel=MathAbs(ShowChannel);
//---- 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,SAR);
   SetIndexStyle(4,DRAW_ARROW);
   SetIndexEmptyValue(4,0.0);
   SetIndexArrow(4,159);
   
   string _sar="SAR("+DoubleToStr(Step,3)+","+DoubleToStr(Maximum,1)+")";
   SetIndexLabel(4,_sar);

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

   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--) SAR[i]=iSAR(NULL,0,Step,Maximum, i);
   for(i=limit; i>0; i--)
     {
      double sar=SAR[i];
      double mid[2]; // ñð. öåíà
      mid[0]=(High[i]+Low[i])/2; // ñð.öåíà íà òåêóùåì áàðå
      mid[1]=(High[i+1]+Low[i+1])/2; // ñð.öåíà íà ïðåä.áàðå

      j++; // ñ÷åò÷èê ñìåùåíèÿ

      bool up=SAR[i+1]>=mid[1] && SAR[i]<mid[0]; // ïåðåâîðîò ââåðõ
      bool dn=SAR[i+1]<=mid[1] && SAR[i]>mid[0]; // ïååâîðîò âíèç

      if(dir) // ëîâëÿ  ïèêà
        {
         if(dn) // ïåðåâîðîò âíèç
           {
            double h=0;
            if(count) {for(int k=j; k>=0; k--) if(High[i+k]>h) {int sh=i+k; h=High[i+k];}}
            else {for(k=0; k<=j; 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;
            j=1; dir=0; // ïîéìàí ïèê
           }
        }
      else // ëîâëÿ âïàäèíû
        {
         if(up) // ïåðåâîðîò ââåðõ
           {
            double l=High[i]*100;
            if(count) {for(k=j; k>=0; k--) if(Low[i+k]<l) {sh=i+k;l=Low[i+k];}}
            else {for(k=0; k<=j; 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;
            j=1;dir=1; // ïîéìàíà âïàäèíà
           }
        }

      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(SAR,0.0);
   dir=0;max=0;min=0;top=0;bot=0;j=0;
   return(0);
  }

Comments