aroonoscillator_v3

Download script
Author: Copyright � 2011, Nikolay Kositsin

Indicator Logic Overview

This script provides a technical analysis tool designed to measure the strength of a price trend by evaluating how much "space" is covered between the highest and lowest price points over a specific period. Instead of just looking at where the price is currently, it analyzes the volatility and range of movement within a defined timeframe.

Core Functionality

The indicator calculates an oscillator value based on the following logic:

  • Range Identification: The script looks back at a user-defined number of previous bars (the "Period"). Within this window, it identifies two key data points: the absolute highest price reached and the absolute lowest price reached.
  • Calculation Method: It determines the difference between that highest high and lowest low, then divides that difference by the total number of bars in the period.
  • Normalization: The result is multiplied by 100 to create a standardized oscillator value. This allows the indicator to stay within a consistent scale, making it easier to compare different assets or timeframes.

Visual Representation

  • The Line: The primary output is a solid red line displayed in a separate window below your main price chart.
  • Horizontal Levels: To help with interpretation, the indicator features three reference levels:
    • +50: Often used to identify significant upward movement or trend strength.
    • 0: The center point of the oscillator.
    • -50: Often used to identify significant downward movement or trend strength.

How it Works in Practice

The script serves as a "momentum" or "strength" gauge. By calculating how much of the available price range is being utilized over a set number of bars, it helps traders visualize whether the current market move is expanding significantly or if the price action is becoming compressed.

User Customization

The script includes two main settings that allow you to tailor the logic to your trading style:

  1. Period: This determines how far back in time the indicator looks to find the highest and lowest prices (e.g., looking at the last 9 bars vs. the last 50 bars).
  2. Shift: This allows you to move the visual line horizontally on your chart without changing the underlying math, which can be useful for aligning the data with specific visual layouts.
10 Views
0 Downloads
0 Favorites
aroonoscillator_v3
//+------------------------------------------------------------------+
//|                                              AroonOscillator.mq5 |
//|                             Copyright © 2011,   Nikolay Kositsin | 
//|                              Khabarovsk,   farria@mail.redcom.ru | 
//+------------------------------------------------------------------+
//---- àâòîðñòâî èíäèêàòîðà
#property copyright "Copyright © 2011, Nikolay Kositsin"
//---- ññûëêà íà ñàéò àâòîðà
#property link "farria@mail.redcom.ru"
//---- íîìåð âåðñèè èíäèêàòîðà
#property version   "1.00"
//---- îòðèñîâêà èíäèêàòîðà â îòäåëüíîì îêíå
#property indicator_separate_window
//---- êîëè÷åñòâî èíäèêàòîðíûõ áóôåðîâ 1
#property indicator_buffers 1 
//---- èñïîëüçîâàíî âñåãî îäíî ãðàôè÷åñêèå ïîñòðîåíèå
#property indicator_plots   1
//+-----------------------------------+
//| Ïàðàìåòðû îòðèñîâêè èíäèêàòîðà    |
//+-----------------------------------+
//---- îòðèñîâêà èíäèêàòîðà â âèäå òðåõöâåòíîé ëèíèè
#property indicator_type1 DRAW_LINE
//---- â êà÷åñòâå öâåòà ëèíèè èñïîëüçîâàí êðàñíûé öâåò
#property indicator_color1 clrRed
//---- ëèíèÿ èíäèêàòîðà - ñïëîøíàÿ
#property indicator_style1 STYLE_SOLID
//---- òîëùèíà ëèíèè èíäèêàòîðà ðàâíà 2
#property indicator_width1 2
//---- îòîáðàæåíèå ìåòêè ñèãíàëüíîé ëèíèè
#property indicator_label1  "AroonOscillator"
//+----------------------------------------------+
//| Ïàðàìåòðû îòîáðàæåíèÿ ãîðèçîíòàëüíûõ óðîâíåé |
//+----------------------------------------------+
#property indicator_level1 +50
#property indicator_level2   0
#property indicator_level3 -50
#property indicator_levelcolor clrGray
#property indicator_levelstyle STYLE_DASHDOTDOT
//+----------------------------------------------+
//| Âõîäíûå ïàðàìåòðû èíäèêàòîðà                 |
//+----------------------------------------------+
input int AroonPeriod= 9; // Ïåðèîä èíäèêàòîðà 
input int AroonShift = 0; // Ñäâèã èíäèêàòîðà ïî ãîðèçîíòàëè â áàðàõ 
//+----------------------------------------------+
//---- îáúÿâëåíèå äèíàìè÷åñêèõ ìàññèâîâ, êîòîðûå áóäóò â 
//---- äàëüíåéøåì èñïîëüçîâàíû â êà÷åñòâå èíäèêàòîðíûõ áóôåðîâ
double ExtLineBuffer[];
//+------------------------------------------------------------------+
//| Searching index of the highest bar                               |
//+------------------------------------------------------------------+
int iHighest(const double &array[], // ìàññèâ äëÿ ïîèñêà èíäåêñà ìàêñèìàëüíîãî ýëåìåíòà
             int count,             // ÷èñëî ýëåìåíòîâ ìàññèâà (â íàïðàâëåíèè îò òåêóùåãî áàðà â ñòîðîíó óáûâàíèÿ èíäåêñà), 
                                    // ñðåäè êîòîðûõ äîëæåí áûòü ïðîèçâåäåí ïîèñê.
             int startPos)          // èíäåêñ (ñìåùåíèå îòíîñèòåëüíî òåêóùåãî áàðà) íà÷àëüíîãî áàðà, 
                                    // ñ êîòîðîãî íà÷èíàåòñÿ ïîèñê íàèáîëüøåãî çíà÷åíèÿ
  {
//----
   int index=startPos;
//---- ïðîâåðêà ñòàðòîâîãî èíäåêñà íà êîððåêòíîñòü
   if(startPos<0)
     {
      Print("Íåâåðíîå çíà÷åíèå â ôóíêöèè iHighest, startPos = ",startPos);
      return(0);
     }
//---- ïðîâåðêà çíà÷åíèÿ startPos íà êîððåêòíîñòü
   if(startPos-count<0)
      count=startPos;
//---
   double max=array[startPos];
//---- ïîèñê èíäåêñà
   for(int i=startPos; i>startPos-count; i--)
     {
      if(array[i]>max)
        {
         index=i;
         max=array[i];
        }
     }
//---- âîçâðàò èíäåêñà íàèáîëüøåãî áàðà
   return(index);
  }
//+------------------------------------------------------------------+
//| Searching index of the lowest bar                                |
//+------------------------------------------------------------------+
int iLowest(const double &array[], // ìàññèâ äëÿ ïîèñêà èíäåêñà ìèíèìàëüíîãî ýëåìåíòà
            int count,             // ÷èñëî ýëåìåíòîâ ìàññèâà (â íàïðàâëåíèè îò òåêóùåãî áàðà â ñòîðîíó óáûâàíèÿ èíäåêñà), 
                                   // ñðåäè êîòîðûõ äîëæåí áûòü ïðîèçâåäåí ïîèñê.
            int startPos)          // èíäåêñ (ñìåùåíèå îòíîñèòåëüíî òåêóùåãî áàðà) íà÷àëüíîãî áàðà, 
                                   // ñ êîòîðîãî íà÷èíàåòñÿ ïîèñê íàèìåíüøåãî çíà÷åíèÿ
  {
//----
   int index=startPos;
//---- ïðîâåðêà ñòàðòîâîãî èíäåêñà íà êîððåêòíîñòü
   if(startPos<0)
     {
      Print("Íåâåðíîå çíà÷åíèå â ôóíêöèè iLowest, startPos = ",startPos);
      return(0);
     }
//---- ïðîâåðêà çíà÷åíèÿ startPos íà êîððåêòíîñòü
   if(startPos-count<0)
      count=startPos;
//---
   double min=array[startPos];
//---- ïîèñê èíäåêñà
   for(int i=startPos; i>startPos-count; i--)
     {
      if(array[i]<min)
        {
         index=i;
         min=array[i];
        }
     }
//---- âîçâðàò èíäåêñà íàèìåíüøåãî áàðà
   return(index);
  }
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+  
void OnInit()
  {
//---- ïðåâðàùåíèå äèíàìè÷åñêîãî ìàññèâà ExtLineBuffer â èíäèêàòîðíûé áóôåð
   SetIndexBuffer(0,ExtLineBuffer,INDICATOR_DATA);
//---- èíèöèàëèçàöèè ïåðåìåííîé äëÿ êîðîòêîãî èìåíè èíäèêàòîðà
   string shortname;
   StringConcatenate(shortname,"AroonOscillator(",AroonPeriod,")");
//---- îñóùåñòâëåíèå ñäâèãà èíäèêàòîðà 1 ïî ãîðèçîíòàëè íà AroonShift
   PlotIndexSetInteger(0,PLOT_SHIFT,AroonShift);
//---- ñîçäàíèå ìåòêè äëÿ îòîáðàæåíèÿ â Îêíå äàííûõ
   PlotIndexSetString(0,PLOT_LABEL,shortname);
//---- ñîçäàíèå èìåíè äëÿ îòîáðàæåíèÿ â îòäåëüíîì ïîäîêíå è âî âñïëûâàþùåé ïîäñêàçêå
   IndicatorSetString(INDICATOR_SHORTNAME,shortname);
//---- îïðåäåëåíèå òî÷íîñòè îòîáðàæåíèÿ çíà÷åíèé èíäèêàòîðà
   IndicatorSetInteger(INDICATOR_DIGITS,0);
//---- çàïðåò íà îòðèñîâêó èíäèêàòîðîì ïóñòûõ çíà÷åíèé
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);
//----
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,    // êîëè÷åñòâî èñòîðèè â áàðàõ íà òåêóùåì òèêå
                const int prev_calculated,// êîëè÷åñòâî èñòîðèè â áàðàõ íà ïðåäûäóùåì òèêå
                const datetime &time[],
                const double &open[],
                const double& high[],     // öåíîâîé ìàññèâ ìàêñèìóìîâ öåíû äëÿ ðàñ÷åòà èíäèêàòîðà
                const double& low[],      // öåíîâîé ìàññèâ ìèíèìóìîâ öåíû  äëÿ ðàñ÷åòà èíäèêàòîðà
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---- ïðîâåðêà êîëè÷åñòâà áàðîâ íà äîñòàòî÷íîñòü äëÿ ðàñ÷åòà
   if(rates_total<AroonPeriod) return(0);
//---- îáúÿâëåíèÿ ëîêàëüíûõ ïåðåìåííûõ 
   int first,bar,highest,lowest;
//---- ðàñ÷åò ñòàðòîâîãî íîìåðà first äëÿ öèêëà ïåðåñ÷åòà áàðîâ
   if(prev_calculated>rates_total || prev_calculated<=0) // ïðîâåðêà íà ïåðâûé ñòàðò ðàñ÷åòà èíäèêàòîðà
      first=AroonPeriod-1; // ñòàðòîâûé íîìåð äëÿ ðàñ÷åòà âñåõ áàðîâ
   else first=prev_calculated-1; // ñòàðòîâûé íîìåð äëÿ ðàñ÷åòà íîâûõ áàðîâ
//---- îñíîâíîé öèêë ðàñ÷åòà èíäèêàòîðà
   for(bar=first; bar<rates_total; bar++)
     {
      highest=iHighest(high,AroonPeriod,bar);
      lowest=iLowest(low,AroonPeriod,bar);
      //----
      ExtLineBuffer[bar]=100*(highest-lowest)/AroonPeriod;
     }
//----     
   return(rates_total);
  }
//+------------------------------------------------------------------+

Comments