Overbought_Oversould_Level

Author: © 2023, Alexey Viktorov
1 Views
0 Downloads
0 Favorites
Overbought_Oversould_Level
ÿþ/********************************************************************\

|                                     Overbought_Oversould_Level.mq5 |

|                                            © 2023, Alexey Viktorov |

|                       https://www.mql5.com/ru/users/alexeyvik/news |

\********************************************************************/

#property copyright "© 2023, Alexey Viktorov"

#property link      "https://www.mql5.com/ru/users/alexeyvik/news"

#property description "Adaptive Market Level"

#property version   "1.00"

//#property indicator_chart_window

#property indicator_separate_window

#define zz " ***** "

#property indicator_buffers     2

#property indicator_plots       1

#property indicator_type1       DRAW_COLOR_LINE

#property indicator_color1      clrMediumVioletRed, clrPurple

#property indicator_label1      "Level"

#property indicator_width1      2

#property indicator_minimum     0

#property indicator_maximum     10

#property indicator_level1      3.5

#property indicator_level2      6.5

#property indicator_levelcolor  clrDarkGoldenrod

//--- input parameters

input int     shortPeriod = 12;

input int     longPeriod  = 24;

input double  indLevel    = 3.5;

//---

int       short_highest,short_lowest; // bar index shorter channel

int       long_highest,long_lowest;   // bar index longer channel

double    upper_diff,lower_diff;      // channel difference

/****************indicator buffers****************/

double dataIndex[];

double colIndex[];

/**************Custom indicator initialization function**************/

int OnInit()

 {

  SetIndexBuffer(0, dataIndex, INDICATOR_DATA);

  SetIndexBuffer(1, colIndex, INDICATOR_COLOR_INDEX);

  //PlotIndexSetDouble(1, PLOT_EMPTY_VALUE, 0.0);

  IndicatorSetDouble(INDICATOR_LEVELVALUE, 0, indLevel);

  IndicatorSetDouble(INDICATOR_LEVELVALUE, 1, 10.0-indLevel);

  return(INIT_SUCCEEDED);

 }/******************************************************************/



/****************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(prev_calculated == 0)

   {

    ArrayInitialize(dataIndex, EMPTY_VALUE);

   }

  int limit = prev_calculated == 0 ? shortPeriod+longPeriod-1 : rates_total-1;

//Print(__LINE__, "  ", rates_total);

  for(int i = limit; i < rates_total && !IsStopped(); i++)

   {

    //--- initial zero

    upper_diff=0.0;

    lower_diff=0.0;

    //--- shorter period channel

    short_highest = ArrayMaximum(high, i-shortPeriod, shortPeriod);

    short_lowest = ArrayMinimum(low, i-shortPeriod, shortPeriod);

    //short_highest = iHighest(_Symbol, PERIOD_CURRENT, MODE_HIGH, shortPeriod, rates_total-1-shortPeriod);

    //short_lowest = iLowest(_Symbol, PERIOD_CURRENT, MODE_LOW, shortPeriod, rates_total-1-shortPeriod);

    //---

    //Print(__LINE__, "  ", limit);

    for(int n = i-longPeriod; n > i-longPeriod-shortPeriod; n--)

     {

      //--- longer period channel

      //Print(__LINE__, "  ", n);

      long_highest = ArrayMaximum(high, n, longPeriod);

      long_lowest = ArrayMinimum(low, n, longPeriod);

      //long_highest = iHighest(_Symbol, PERIOD_CURRENT, MODE_HIGH, longPeriod, n);

      //long_lowest = iLowest(_Symbol, PERIOD_CURRENT, MODE_LOW, longPeriod, n);

      //--- channel difference

      upper_diff += high[long_highest]-low[short_lowest];

      lower_diff += high[short_highest]-low[long_lowest];

     }

    //--- index calculation

    if(upper_diff!=0.0)

      dataIndex[i]=MathCeil(9.0-9.0/(1+lower_diff/upper_diff));

    else

      dataIndex[i]=9.0;

    //--- overbought / oversold level

    if(dataIndex[i] <= indLevel || dataIndex[i] >= 10.0-indLevel)

      colIndex[i] = 0;

    else

      colIndex[i] = 1;

   }

  return(rates_total);

 }/******************************************************************/



/********************************************************************/

void OnDeinit(const int reason)

 {

//Print(__FUNCTION__, reason);

  Comment("");

 }/*******************************************************************/

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---