Author: Copyright � 2005, Nick Bilak
NB-channel

Technical Overview: NB_SHI_Channel Logic

This script is designed to analyze price action by identifying significant historical structural points—specifically highs and lows—to project a "channel" of potential support and resistance levels on your trading chart. It uses mathematical progression to define how the market might expand or contract over a specific period.

Core Operational Logic

1. Structural Identification (The Foundation) Instead of reacting to every minor price fluctuation, the script scans back through history to find significant turning points. It automatically determines the "look-back" window based on your current timeframe (e.g., it looks deeper into the past on daily charts than on 1-minute charts). It identifies two primary anchors:

  • A significant Low (bottom)
  • A significant High (top)

2. Trend and Slope Calculation Once these two anchors are identified, the script calculates the "Step." This is essentially the mathematical slope between the two points. By knowing the distance between the high and low and how much time passed between them, the script determines the rate of price change. It uses this slope to project where the price "should" be relative to its previous boundaries.

3. Dynamic Projection (The Channel) The logic then generates three distinct linear paths (represented as trend lines and buffers) based on the identified slope:

  • Primary Boundary Line: A projection based on the direct slope between the two major anchors.
  • Secondary Boundary Line: A secondary calculation that adjusts the projection based on local price "breaches" to ensure the channel remains relevant to recent action.
  • Median Line: A dotted midpoint line that represents the equilibrium balance between the upper and lower projected boundaries.

4. Visual Execution The script translates these mathematical calculations into visual elements:

  • It draws Trend Lines on your chart to show the historical connection between the anchors and the future projection.
  • It calculates a "buffer" to populate the chart with data points, allowing you to see the linear progression of these boundaries in real-time as new candles form.

Summary for the User

In simple terms, this script looks at the "big picture" of recent price history to find where the floor and ceiling were established. It then draws a mathematical corridor showing where those floors and ceilings are likely to move in the future. This helps traders visualize the current market trajectory and identify potential zones where the price might encounter resistance or find support.

Miscellaneous
Implements a curve of type %1
7 Views
0 Downloads
0 Favorites
NB-channel
//+------------------------------------------------------------------+
//|                                               NB_SHI_Channel.mq4 |
//|                                     Copyright © 2005, Nick Bilak |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Nick Bilak"
#property link      ""
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Red
//#property indicator_color2 Green
//#property indicator_color3 Green
//#property indicator_color4 Green
double buf1[];
double buf2[];
double buf3[];
double ExtMapBuffer1[];
//---- input parameters
extern int       AllBars=240;
extern int       BarsForFract=0;
int CurrentBar=0;
double Step=0;
int B1=-1,B2=-1;
int UpDown=0;
double P1=0,P2=0,PP=0;
int i=0,AB=300,BFF=0;
int ishift=0;
double iprice=0;
datetime T1,T2;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,164);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexEmptyValue(0,0.0);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,buf1);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,buf2);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexBuffer(3,buf3);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
//----
   return(0);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void DelObj()
  {
   ObjectDelete("TL1");
   ObjectDelete("TL2");
   ObjectDelete("MIDL");
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   //  if( Time[0]>= StrToTime("2005.8.19 06:00")) return(0);
   int    counted_bars=IndicatorCounted();
//---- 
   if ((AllBars==0) || (Bars<AllBars)) AB=Bars; else AB=AllBars; 
   if (BarsForFract>0)
      BFF=BarsForFract;
   else
     {
      switch(Period())
        {
         case 1: BFF=12; break;
         case 5: BFF=48; break;
         case 15: BFF=24; break;
         case 30: BFF=24; break;
         case 60: BFF=12; break;
         case 240: BFF=15; break;
         case 1440: BFF=10; break;
         case 10080: BFF=6; break;
         default: DelObj(); return(-1); break;
        }
     }
   CurrentBar=2;
   B1=-1; B2=-1; UpDown=0;
   while(((B1==-1) || (B2==-1)) && (CurrentBar<AB))
     {

      if((UpDown<1) && (CurrentBar==Lowest(Symbol(),Period(),MODE_LOW,BFF*2+1,CurrentBar-BFF)))
        {
         if(UpDown==0) { UpDown=-1; B1=CurrentBar; P1=Low[B1]; }
         else { B2=CurrentBar; P2=Low[B2];}
        }
      if((UpDown>-1) && (CurrentBar==Highest(Symbol(),Period(),MODE_HIGH,BFF*2+1,CurrentBar-BFF)))
        {
         if(UpDown==0) { UpDown=1; B1=CurrentBar; P1=High[B1]; }
         else { B2=CurrentBar; P2=High[B2]; }
        }
      CurrentBar++;
     }
   if((B1==-1) || (B2==-1)) {DelObj(); return(-1);}
   Step=(P2-P1)/(B2-B1);
   P1=P1-B1*Step; B1=0;
   ishift=0; iprice=0;
   if(UpDown==1)
     {
      PP=Low[2]-2*Step;
      for(i=3;i<=B2;i++)
        {
         if(Low[i]<PP+Step*i) { PP=Low[i]-i*Step; }
        }
      if(Low[0]<PP) {ishift=0; iprice=PP;}
      if(Low[1]<PP+Step) {ishift=1; iprice=PP+Step;}
      if(High[0]>P1) {ishift=0; iprice=P1;}
      if(High[1]>P1+Step) {ishift=1; iprice=P1+Step;}
     }
   else
     {
      PP=High[2]-2*Step;
      for(i=3;i<=B2;i++)
        {
         if(High[i]>PP+Step*i) { PP=High[i]-i*Step;}
        }
      if(Low[0]<P1) {ishift=0; iprice=P1;}
      if(Low[1]<P1+Step) {ishift=1; iprice=P1+Step;}
      if(High[0]>PP) {ishift=0; iprice=PP;}
      if(High[1]>PP+Step) {ishift=1; iprice=PP+Step;}
     }
   P2=P1+AB*Step;
   T1=Time[B1]; T2=Time[AB];
//----
   if(iprice!=0) ExtMapBuffer1[ishift]=iprice;
   DelObj();
   ObjectCreate("TL1",OBJ_TREND,0,T2,PP+Step*AB,T1,PP);
   ObjectSet("TL1",OBJPROP_COLOR,Lime);
   ObjectSet("TL1",OBJPROP_WIDTH,2);
   ObjectSet("TL1",OBJPROP_STYLE,STYLE_SOLID);
   ObjectCreate("TL2",OBJ_TREND,0,T2,P2,T1,P1);
   ObjectSet("TL2",OBJPROP_COLOR,Lime);
   ObjectSet("TL2",OBJPROP_WIDTH,2);
   ObjectSet("TL2",OBJPROP_STYLE,STYLE_SOLID);
   ObjectCreate("MIDL",OBJ_TREND,0,T2,(P2+PP+Step*AB)/2,T1,(P1+PP)/2);
   ObjectSet("MIDL",OBJPROP_COLOR,Lime);
   ObjectSet("MIDL",OBJPROP_WIDTH,1);
   ObjectSet("MIDL",OBJPROP_STYLE,STYLE_DOT);
//----
   double cbars=AB-B1;
   double startPP=PP+Step*AB, endPP=PP;
   double startP1=P2, endP1=P1;
   double startP2=(P2+PP+Step*AB)/2, endP2=(P1+PP)/2;
   double deltaPP=(startPP-endPP)/cbars;
   double deltaP1=(startP1-endP1)/cbars;
   double deltaP2=(startP2-endP2)/cbars;
   buf1[AB]=startPP;
   buf2[AB]=startP1;
   buf3[AB]=startP2;
     for(int i=AB-1; i>=0; i--) 
     {
      buf1[i]=buf1[i+1]-deltaPP;
      buf2[i]=buf2[i+1]-deltaP1;
      buf3[i]=buf3[i+1]-deltaP2;
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments