Author: Copyright � 2011,RJ Rjabkov Alexander
Miscellaneous
Implements a curve of type %1
2 Views
0 Downloads
0 Favorites
Rj_RMA
//+------------------------------------------------------------------+
//|                                                       Rj_RMA.mq4 |
//|                            Copyright © 2011,RJ Rjabkov Alexander |
//|                                                     rj-a@mail.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011,RJ Rjabkov Alexander"
#property link      "rj-a@mail.ru"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Aqua
#property indicator_color2 Red
#property indicator_width1 2
#property indicator_width2 2

extern int CalcPeriodRange=13;

double AwlUpper[];
double AwlLower[];
double UpperLimit[];
double LowerLimit[];
double Current[];
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init() 
  {
   IndicatorBuffers(5);
   SetIndexBuffer(0,AwlUpper);
   SetIndexBuffer(1,AwlLower);
   SetIndexBuffer(2,UpperLimit);
   SetIndexBuffer(3,LowerLimit);
   SetIndexBuffer(4,Current);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexLabel(0,"Upper");
   SetIndexLabel(1,"Lower");
   return(0);
  }

int deinit() {return(0);}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start() 
  {
   int i;
   int counted_bars = IndicatorCounted();
   if(counted_bars < 0)  return(-1);
   if(counted_bars > 0)   counted_bars--;
   int cb = Bars - counted_bars;
   if(counted_bars==0) cb-=1+CalcPeriodRange;

   while(cb>=0) 
     {
      i=cb+CalcPeriodRange-1;
      double b1=0,b2=0;
      while(i>=cb) 
        {
         b1 += High[iHighest(NULL, 0, MODE_HIGH, CalcPeriodRange, i)];
         b2 += Low[iLowest(NULL, 0, MODE_LOW, CalcPeriodRange, i)];
         i--;
        }
      UpperLimit[cb]=b1/CalcPeriodRange;
      LowerLimit[cb]=b2/CalcPeriodRange;
      Current[cb]=NormalizeDouble((UpperLimit[cb]+LowerLimit[cb])/2,5);
      AwlUpper[cb]=EMPTY_VALUE;
      AwlLower[cb]=EMPTY_VALUE;
      if(Current[cb]>Current[cb+1]) {AwlUpper[cb]=Current[cb]; AwlUpper[cb+1]=Current[cb+1];}
      if(Current[cb]<Current[cb+1]) {AwlLower[cb]=Current[cb]; AwlLower[cb+1]=Current[cb+1];}
      if(Current[cb]==Current[cb+1] && AwlLower[cb+1]!=EMPTY_VALUE) {AwlLower[cb]=Current[cb];}
      if(Current[cb]==Current[cb+1] && AwlUpper[cb+1]!=EMPTY_VALUE) {AwlUpper[cb]=Current[cb];}
      cb--;
     }
   return(0);
  }
//+------------------------------------------------------------------+

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 ---