HL_Activator_NEXT

Download script
Author: Copyright � 2005, MetaQuotes Software Corp.
HL_Activator_NEXT

This script is designed to identify and highlight specific price levels on a trading chart based on historical highs and lows. It acts as a visual guide, signaling potential areas of interest where price may react depending on the timeframe you are viewing.

Core Logic and Functionality

The script operates by scanning through historical data to find significant "peaks" (highest prices) and "valleys" (lowest prices). Its primary goal is to calculate an average of these points to establish a dynamic boundary for the market.

1. Timeframe-Specific Intelligence The script does not treat all timeframes the same way. It contains unique logic for various intervals, including 5-minute, 15-minute, 30-minute, 60-minute, 240-minute (4-hour), 1440-minute (daily), 10,080-minute (weekly), and monthly charts. For each of these, it looks for specific "transition points"—such as the start of a new hour, a new day, a new week, or a new month—to determine where to capture high and low data.

2. High/Low Identification Once the script identifies a transition point (like a new day starting), it looks back at a specific window of bars. Within that window:

  • It identifies the highest price reached.
  • It identifies the lowest price reached.
  • It accounts for the "spread" (the difference between the buy and sell price) to ensure the calculations remain accurate to real-market conditions.

3. Averaging and Boundary Creation Instead of just looking at a single high or low, the script takes a set number of these points (defined by a user setting) and calculates their average. This creates two distinct reference levels:

  • An Upper Bound: The average of the historical highs.
  • A Lower Bound: The average of the historical lows.

4. Signal Visualization The script then compares the current closing price against these calculated averages to determine which signal to display on your chart:

  • Bullish Signal: If the price closes significantly above the "Upper Bound" average, it triggers a specific visual marker (an arrow).
  • Bearish Signal: If the price closes significantly below the "Lower Bound" average, it triggers a different visual marker.

Summary for the User

Essentially, this tool filters out the "noise" of the market by looking at the historical extremes of specific time blocks. It then averages those extremes to create a "ceiling" and a "floor." When the price breaks through these calculated levels, the script places an arrow on your chart to notify you of the momentum shift.

Miscellaneous
Implements a curve of type %1
15 Views
0 Downloads
0 Favorites
HL_Activator_NEXT
//+------------------------------------------------------------------+
//|                                            HL_Activator_NEXT.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 DarkKhaki
#property indicator_color2 Red
//---- input parameters
extern int       HL_period=3;
extern int       NumBars=300;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//------
double ur[][2];
int h1[];
int l1[];

int hh=0;
int ll=0;

double spread;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,159);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexEmptyValue(0,0.0);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,159);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexEmptyValue(1,0.0);
//----
   ArrayResize(ur,NumBars+1);
   ArrayResize(h1,HL_period);
   ArrayResize(l1,HL_period);
   
   spread = Ask-Bid;
   return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
  int   n,shift,Nbar,k,mm;
  double MaH,MaL;

//---- 
  if( Period() == 5 )
  {
    ArrayInitialize(ur,0);
    ArrayInitialize(h1,0);
    ArrayInitialize(l1,0);
    for( shift = NumBars; shift>=0; shift-- )
    {
      if( TimeHour(Time[shift + 1]) != TimeHour(Time[shift]) )
      {
        Nbar = -1;
        k = 0;
        mm = 0;
        n = shift - 15;
        while( n <= shift + HL_period * 12 + 5 )
        {
          if( n < 0 )
          {
            n = 1;
            Nbar = 0;
          }
          if( TimeHour(Time[n + 1]) != TimeHour(Time[n]) && Nbar == -1 )
          {
            Nbar = n;
            mm = n;
            n++;
            continue;
          }
          if( TimeHour(Time[n + 1]) != TimeHour(Time[n]) && Nbar != -1 )
          {
            h1[k] = Highest(NULL,0,MODE_HIGH,n - Nbar,n-(n-Nbar)+1);
            l1[k] = Lowest(NULL,0,MODE_LOW,n - Nbar,n-(n-Nbar)+1);
            k++;
            Nbar = n;
          }
          n++;
        }
        MaH = 0;
        MaL = 0;
        for( n = 0; n<HL_period; n++ )
        {
          MaH = MaH + High[h1[n]]+spread;
          MaL = MaL + Low[l1[n]];
        }
        MaH = MaH / HL_period;
        MaL = MaL / HL_period;
        ur[shift][0] = MaH;
        ur[shift][1] = MaL;
        if( Close[mm + 1]+spread/2 >= MaH ) { ll = 1; hh = 0; }
        if( Close[mm + 1]+spread/2 <= MaL ) { hh = 1; ll = 0; }
      }
      if( ur[shift,1] == 0 )
      {
        ur[shift][0] = ur[shift + 1][0];
        ur[shift][1] = ur[shift + 1][1];
      }
      if( ll == 1 )
      {
        ExtMapBuffer2[shift]=0;
        ExtMapBuffer1[shift]=ur[shift][1];
      }
      if( hh == 1 )
      {
        ExtMapBuffer1[shift]=0;
        ExtMapBuffer2[shift]=ur[shift][0];
      }
    }
    return(0);
  }
//-----------------------------
  if( Period() == 15 )
  {
    ArrayInitialize(ur,0);
    ArrayInitialize(h1,0);
    ArrayInitialize(l1,0);
    for( shift = NumBars; shift>=0; shift-- )
    {
      if( TimeHour(Time[shift + 1]) != TimeHour(Time[shift]) )
      {
        Nbar = -1;
        k = 0;
        mm = 0;
        n = shift - 5;
        while( n <= shift + HL_period * 4 + 2 )
        {
          if( n < 0 )
          {
            n = 1;
            Nbar = 0;
          }
          if( TimeHour(Time[n + 1]) != TimeHour(Time[n]) && Nbar == -1 )
          {
            Nbar = n;
            mm = n;
            n++;
            continue;
          }
          if( TimeHour(Time[n + 1]) != TimeHour(Time[n]) && Nbar != -1 )
          {
            h1[k] = Highest(NULL,0,MODE_HIGH,n - Nbar,n-(n-Nbar)+1);
            l1[k] = Lowest(NULL,0,MODE_LOW,n - Nbar,n-(n-Nbar)+1);
            k++;
            Nbar = n;
          }
          n++;
        }
        MaH = 0;
        MaL = 0;
        for( n = 0; n<HL_period; n++ )
        {
          MaH = MaH + High[h1[n]]+spread;
          MaL = MaL + Low[l1[n]];
        }
        MaH = MaH / HL_period;
        MaL = MaL / HL_period;
        ur[shift][0] = MaH;
        ur[shift][1] = MaL;
        if( Close[mm + 1]+spread/2 >= MaH ) { ll = 1; hh = 0; }
        if( Close[mm + 1]+spread/2 <= MaL ) { hh = 1; ll = 0; }
      }
      if( ur[shift,1] == 0 )
      {
        ur[shift][0] = ur[shift + 1][0];
        ur[shift][1] = ur[shift + 1][1];
      }
      if( ll == 1 )
      {
        ExtMapBuffer2[shift]=0;
        ExtMapBuffer1[shift]=ur[shift][1];
      }
      if( hh == 1 )
      {
        ExtMapBuffer1[shift]=0;
        ExtMapBuffer2[shift]=ur[shift][0];
      }
    }
    return(0);
  }
//-------------------------
  if( Period() == 30 )
  {
    ArrayInitialize(ur,0);
    ArrayInitialize(h1,0);
    ArrayInitialize(l1,0);
    for( shift = NumBars; shift>=0; shift-- )
    {
      if( TimeMinute(Time[shift])==0 && (TimeHour(Time[shift])==0 || TimeHour(Time[shift])==4 || TimeHour(Time[shift])==8 || TimeHour(Time[shift])==12 || TimeHour(Time[shift])==16 || TimeHour(Time[shift])==20) )
      {
        Nbar = -1;
        k = 0;
        mm = 0;
        n = shift - 10;
        while( n <= shift + HL_period * 8 + 5 )
        {
          if( n < 0 )
          {
            n = 1;
            Nbar = 0;
          }
          if( TimeMinute(Time[n])==0 && (TimeHour(Time[n])==0 || TimeHour(Time[n])==4 || TimeHour(Time[n])==8 || TimeHour(Time[n])==12 || TimeHour(Time[n])==16 || TimeHour(Time[n])==20) && Nbar == -1 )
          {
            Nbar = n;
            mm = n;
            n++;
            continue;
          }
          if( TimeMinute(Time[n])==0 && (TimeHour(Time[n])==0 || TimeHour(Time[n])==4 || TimeHour(Time[n])==8 || TimeHour(Time[n])==12 || TimeHour(Time[n])==16 || TimeHour(Time[n])==20) && Nbar != -1 )
          {
            h1[k] = Highest(NULL,0,MODE_HIGH,n - Nbar,n-(n-Nbar)+1);
            l1[k] = Lowest(NULL,0,MODE_LOW,n - Nbar,n-(n-Nbar)+1);
            k++;
            Nbar = n;
          }
          n++;
        }
        MaH = 0;
        MaL = 0;
        for( n = 0; n<HL_period; n++ )
        {
          MaH = MaH + High[h1[n]]+spread;
          MaL = MaL + Low[l1[n]];
        }
        MaH = MaH / HL_period;
        MaL = MaL / HL_period;
        ur[shift][0] = MaH;
        ur[shift][1] = MaL;
        if( Close[mm + 1]+spread/2 >= MaH ) { ll = 1; hh = 0; }
        if( Close[mm + 1]+spread/2 <= MaL ) { hh = 1; ll = 0; }
      }
      if( ur[shift,1] == 0 )
      {
        ur[shift][0] = ur[shift + 1][0];
        ur[shift][1] = ur[shift + 1][1];
      }
      if( ll == 1 )
      {
        ExtMapBuffer2[shift]=0;
        ExtMapBuffer1[shift]=ur[shift][1];
      }
      if( hh == 1 )
      {
        ExtMapBuffer1[shift]=0;
        ExtMapBuffer2[shift]=ur[shift][0];
      }
    }
    return(0);
  }
//----
  if( Period() == 60 )
  {
    ArrayInitialize(ur,0);
    ArrayInitialize(h1,0);
    ArrayInitialize(l1,0);
    for( shift = NumBars; shift>=0; shift-- )
    {
      if( TimeMinute(Time[shift])==0 && (TimeHour(Time[shift])==0 || TimeHour(Time[shift])==4 || TimeHour(Time[shift])==8 || TimeHour(Time[shift])==12 || TimeHour(Time[shift])==16 || TimeHour(Time[shift])==20) )
      {
        Nbar = -1;
        k = 0;
        mm = 0;
        n = shift - 6;
        while( n <= shift + HL_period * 4 + 3 )
        {
          if( n < 0 )
          {
            Nbar = 0;
            n = 1;
          }
          if( TimeMinute(Time[n])==0 && (TimeHour(Time[n])==0 || TimeHour(Time[n])==4 || TimeHour(Time[n])==8 || TimeHour(Time[n])==12 || TimeHour(Time[n])==16 || TimeHour(Time[n])==20) && Nbar == -1 )
          {
            Nbar = n;
            mm = n;
            n++;
            continue;
          }
          if( TimeMinute(Time[n])==0 && (TimeHour(Time[n])==0 || TimeHour(Time[n])==4 || TimeHour(Time[n])==8 || TimeHour(Time[n])==12 || TimeHour(Time[n])==16 || TimeHour(Time[n])==20) && Nbar != -1 )
          {
            h1[k] = Highest(NULL,0,MODE_HIGH,n - Nbar,n-(n-Nbar)+1);
            l1[k] = Lowest(NULL,0,MODE_LOW,n - Nbar,n-(n-Nbar)+1);
            k++;
            Nbar = n;
          }
          n++;
        }
        MaH = 0;
        MaL = 0;
        for( n = 0; n<HL_period; n++ )
        {
          MaH = MaH + High[h1[n]]+spread;
          MaL = MaL + Low[l1[n]];
        }
        MaH = MaH / HL_period;
        MaL = MaL / HL_period;
        ur[shift][0] = MaH;
        ur[shift][1] = MaL;
        if( Close[mm + 1]+spread/2 >= MaH ) { ll = 1; hh = 0; }
        if( Close[mm + 1]+spread/2 <= MaL ) { hh = 1; ll = 0; }
      }
      if( ur[shift,1] == 0 )
      {
        ur[shift][0] = ur[shift + 1][0];
        ur[shift][1] = ur[shift + 1][1];
      }
      if( ll == 1 )
      {
        ExtMapBuffer2[shift]=0;
        ExtMapBuffer1[shift]=ur[shift][1];
      }
      if( hh == 1 )
      {
        ExtMapBuffer1[shift]=0;
        ExtMapBuffer2[shift]=ur[shift][0];
      }
    }
    return(0);
  }
//--------------  
  if( Period() == 240 )
  {
    ArrayInitialize(ur,0);
    ArrayInitialize(h1,0);
    ArrayInitialize(l1,0);
    for( shift = NumBars; shift>=0; shift-- )
    {
      if( TimeDay(Time[shift + 1]) != TimeDay(Time[shift]) )
      {
        Nbar = -1;
        k = 0;
        mm = 0;
        n = shift - 8;
        while( n <= shift + HL_period * 8 + 4 )
        {
          if( n < 0 )
          {
            Nbar = 0;
            n = 1;
          }
          if( TimeDay(Time[n + 1]) != TimeDay(Time[n]) && Nbar == -1 )
          {
            Nbar = n;
            mm = n;
            n++;
            continue;
          }
          if( TimeDay(Time[n + 1]) != TimeDay(Time[n]) && Nbar != -1 )
          {
            h1[k] = Highest(NULL,0,MODE_HIGH,n - Nbar,n-(n-Nbar)+1);
            l1[k] = Lowest(NULL,0,MODE_LOW,n - Nbar,n-(n-Nbar)+1);
            k++;
            Nbar = n;
          }
          n++;
        }
        MaH = 0;
        MaL = 0;
        for( n = 0; n<HL_period; n++ )
        {
          MaH = MaH + High[h1[n]]+spread;
          MaL = MaL + Low[l1[n]];
        }
        MaH = MaH / HL_period;
        MaL = MaL / HL_period;
        ur[shift][0] = MaH;
        ur[shift][1] = MaL;
        if( Close[mm + 1]+spread/2 >= MaH ) { ll = 1; hh = 0; }
        if( Close[mm + 1]+spread/2 <= MaL ) { hh = 1; ll = 0; }
      }
      if( ur[shift,1] == 0 )
      {
        ur[shift][0] = ur[shift + 1][0];
        ur[shift][1] = ur[shift + 1][1];
      }
      if( ll == 1 )
      {
        ExtMapBuffer2[shift]=0;
        ExtMapBuffer1[shift]=ur[shift][1];
      }
      if( hh == 1 )
      {
        ExtMapBuffer1[shift]=0;
        ExtMapBuffer2[shift]=ur[shift][0];
      }
    }
    return(0);
  }
//----
  if( Period() == 1440 )
  {
    ArrayInitialize(ur,0);
    ArrayInitialize(h1,0);
    ArrayInitialize(l1,0);
    for( shift = NumBars; shift>=0; shift-- )
    {
      if( TimeDayOfWeek(Time[shift + 1]) == 5 && TimeDayOfWeek(Time[shift]) == 1 )
      {
        Nbar = -1;
        k = 0;
        mm = 0;
        n = shift - 6;
        while( n <= shift + HL_period * 5 + 3 )
        {
          if( n < 0 )
          {
            Nbar = 0;
            n = 1;
          }
          if( TimeDayOfWeek(Time[n + 1])==5 && TimeDayOfWeek(Time[n])==1 && Nbar == -1 )
          {
            Nbar = n;
            mm = n;
            n++;
            continue;
          }
          if( TimeDayOfWeek(Time[n + 1])==5 && TimeDayOfWeek(Time[n])==1 && Nbar != -1 )
          {
            h1[k] = Highest(NULL,0,MODE_HIGH,n - Nbar,n-(n-Nbar)+1);
            l1[k] = Lowest(NULL,0,MODE_LOW,n - Nbar,n-(n-Nbar)+1);
            k++;
            Nbar = n;
          }
          n++;
        }
        MaH = 0;
        MaL = 0;
        for( n = 0; n<HL_period; n++ )
        {
          MaH = MaH + High[h1[n]]+spread;
          MaL = MaL + Low[l1[n]];
        }
        MaH = MaH / HL_period;
        MaL = MaL / HL_period;
        ur[shift][0] = MaH;
        ur[shift][1] = MaL;
        if( Close[mm + 1]+spread/2 >= MaH ) { ll = 1; hh = 0; }
        if( Close[mm + 1]+spread/2 <= MaL ) { hh = 1; ll = 0; }
      }
      if( ur[shift,1] == 0 )
      {
        ur[shift][0] = ur[shift + 1][0];
        ur[shift][1] = ur[shift + 1][1];
      }
      if( ll == 1 )
      {
        ExtMapBuffer2[shift]=0;
        ExtMapBuffer1[shift]=ur[shift][1];
      }
      if( hh == 1 )
      {
        ExtMapBuffer1[shift]=0;
        ExtMapBuffer2[shift]=ur[shift][0];
      }
    }
    return(0);
  }
//----
  if( Period() == 10080 )
  {
    ArrayInitialize(ur,0);
    ArrayInitialize(h1,0);
    ArrayInitialize(l1,0);
    for( shift = NumBars; shift>=0; shift-- )
    {
      if( TimeMonth(Time[shift + 1]+1440*60) != TimeMonth(Time[shift]+1440*60) )
      {
        Nbar = -1;
        k = 0;
        mm = 0;
        n = shift - 8;
        while( n <= shift + HL_period * 8 + 4 )
        {
          if( n < 0 )
          {
            Nbar = 0;
            n = 1;
          }
          if( TimeMonth(Time[n + 1]+1440*60) != TimeMonth(Time[n]+1440*60) && Nbar == -1 )
          {
            Nbar = n;
            mm = n;
            if( n>NumBars-18 ) Print(TimeToStr(Time[n]));
            n++;
            continue;
          }
          if( TimeMonth(Time[n + 1]+1440*60) != TimeMonth(Time[n]+1440*60) && Nbar != -1 )
          {
            h1[k] = Highest(NULL,0,MODE_HIGH,n - Nbar,n-(n-Nbar)+1);
            l1[k] = Lowest(NULL,0,MODE_LOW,n - Nbar,n-(n-Nbar)+1);
            k++;
            Nbar = n;
          }
          n++;
        }
        MaH = 0;
        MaL = 0;
        for( n = 0; n<HL_period; n++ )
        {
          MaH = MaH + High[h1[n]]+spread;
          MaL = MaL + Low[l1[n]];
        }
        MaH = MaH / HL_period;
        MaL = MaL / HL_period;
        ur[shift][0] = MaH;
        ur[shift][1] = MaL;
        if( Close[mm + 1]+spread/2 >= MaH ) { ll = 1; hh = 0; }
        if( Close[mm + 1]+spread/2 <= MaL ) { hh = 1; ll = 0; }
      }
      if( ur[shift,1] == 0 )
      {
        ur[shift][0] = ur[shift + 1][0];
        ur[shift][1] = ur[shift + 1][1];
      }
      if( ll == 1 )
      {
        ExtMapBuffer2[shift]=0;
        ExtMapBuffer1[shift]=ur[shift][1];
      }
      if( hh == 1 )
      {
        ExtMapBuffer1[shift]=0;
        ExtMapBuffer2[shift]=ur[shift][0];
      }
    }
    return(0);
  }
//----
  return(0);
}
//+------------------------------------------------------------------+

Comments