ATR Levels2

Download script
Author: Sergey Iljukhin

This tool is designed to provide visual support for traders by highlighting significant price levels on a chart based on daily market volatility. It specifically calculates and displays "Upper" and "Lower" channels that help define the boundaries of price movement relative to previous market activity.

Core Functionality

The script works by analyzing daily price data (High, Low, Open, and Close) and combining it with an Average True Range (ATR). The ATR is a technical metric that measures how much an asset typically moves in a given timeframe—essentially measuring the "volatility" or the distance between highs and lows.

How the Logic Works

  1. Data Gathering: The tool automatically pulls data from the Daily timeframe, regardless of what smaller chart you are currently viewing (such as 1-hour or 15-minute charts).
  2. Volatility Calculation: It uses a user-defined period (defaulting to 10 days) to determine the average volatility. By calculating this, the tool understands how much "room" the price usually has to move each day.
  3. Level Projection: For every new day on the chart, the script creates four distinct horizontal levels:
    • Today's Boundaries: It calculates the high and low points for the current day by taking the current day's actual prices and adjusting them based on the calculated volatility.
    • Yesterday's Boundaries: It repeats this process for the previous day, projecting where yesterday's price limits were.
  4. Visual Representation: These four levels are drawn on your chart as lines. This allows you to see a "channel" of movement. By comparing today's projected high/low with yesterday's, traders can visually identify if the price is expanding into new territory or remaining within established historical ranges.

Key Usage Notes

  • Timeframe Restriction: To ensure accuracy, the tool is designed to be used on charts with a timeframe of 4 hours or less. If a larger timeframe (like Daily or Weekly) is selected, the tool will provide a notification that it cannot display correctly.
  • Visual Indicators: The lines are color-coded to distinguish between "Up Channels" (the upper boundaries) and "Down Channels" (the lower boundaries), making it easier to read at a glance during live trading.
Indicators Used
Indicator of the average true range
Miscellaneous
Implements a curve of type %1
11 Views
0 Downloads
0 Favorites
ATR Levels2
//+------------------------------------------------------------------+
//|                                                  ATR Levels2.mq4 |
//|                                                  Sergey Iljukhin |
//|                                                  sergey@tibet.ru |
//+------------------------------------------------------------------+
#property copyright "Sergey Iljukhin"
#property link      "mailto:sergey@tibet.ru"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Magenta 
#property indicator_color2 IndianRed 
#property indicator_color3 Magenta 
#property indicator_color4 IndianRed 

#define   LevelMaxDeep  2000 //



extern int ATRPeriod = 10;         

datetime PrevTime;              
string ShortName="ATR Levels";  

double OHLC_D1[][6];  

//---- buffers
double UpLine1[],UpLine2[],DnLine1[],DnLine2[];

ArraySetAsSeries(UpLine1,true);
ArraySetAsSeries(UpLine2,true);
ArraySetAsSeries(DnLine1,true);
ArraySetAsSeries(DnLine2,true);

//+------------------------------------------------------------------+
//| Èíèöèàëèçàöèÿ ìàññèâîâ                                           |
//+------------------------------------------------------------------+

int InitChart()
{
//---- indicator line
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE,2);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexStyle(3,DRAW_LINE,2);
   SetIndexBuffer(0,UpLine1);
   SetIndexBuffer(1,UpLine2);
   SetIndexBuffer(2,DnLine1);
   SetIndexBuffer(3,DnLine2);
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName(ShortName+" ("+ATRPeriod+")");
   SetIndexLabel(0,"Up Channel 1");
   SetIndexLabel(1,"Up Channel 2");
   SetIndexLabel(2,"Down Channel 1");
   SetIndexLabel(3,"Down Channel 2");
//----
   SetIndexEmptyValue(0,0);
   SetIndexEmptyValue(1,0);
   SetIndexEmptyValue(2,0);
   SetIndexEmptyValue(3,0);

//----
   return(0);
}


int init()
  {
   InitChart();
   return(0);
  }

int deinit()
  {
   InitChart();
   return(0);
  }

int start()
  {
   int  counted_bars=IndicatorCounted();
   int  lastday=0, i, j, daybar=0, chartbar=0;  
   double LowYesterday, HighYesterday, LowToday, HighToday, fullatr;
   
   
   if (PrevTime==Time[0]) return(-1);
   
   
   if(Period() > PERIOD_H4)
      {
         Comment("ATR Levels - îøèáêà: ïåðèîä ãðàôèêà áîëåå Í4 !");
         return(-1); // then exit
      }

   
   ArrayCopyRates(OHLC_D1, Symbol(), PERIOD_D1);

   lastday=TimeDay(Time[0]);
   
   for (i=0; i<Bars; i++) {
    if (lastday!=TimeDay(Time[i])) {

     // Âû÷èñëÿåì çíà÷åíèå ATR ïðåäûäóùåãî áàðà
     fullatr = iATR(Symbol(), PERIOD_D1, ATRPeriod, daybar+1);
             
     LowYesterday  = OHLC_D1[daybar+1][3] - fullatr;   
     HighYesterday = OHLC_D1[daybar+1][2] + fullatr;
     LowToday  = OHLC_D1[daybar][3] - fullatr;   
     HighToday = OHLC_D1[daybar][2] + fullatr;

     
     
     for (j=chartbar; j<i; j++) { 
       UpLine1[j]=HighToday;
       UpLine2[j]=HighYesterday;
       DnLine1[j]=LowToday;
       DnLine2[j]=LowYesterday;
     }  

    lastday=TimeDay(Time[i]);
    daybar++;
    chartbar=i;
    }
   }
   
   
   PrevTime=Time[0];
   return(0);

  }
//+------------------------------------------------------------------+

Comments