Indicators Used
Moving average indicatorIndicator of the average true rangeStandard Deviation indicator
Miscellaneous
Implements a curve of type %1
2 Views
0 Downloads
0 Favorites
ATRNorm
//+------------------------------------------------------------------+
//|                                   Copyright © 2012, Ivan Kornilov|
//|                                                       ATRNorm.mq4|
//|                                   excelf@gmail.com, skype: excelf|
//+------------------------------------------------------------------+

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 DodgerBlue
#property indicator_color2 SlateGray
#property indicator_level1 0.5
#property indicator_level2 0.25
#property indicator_level3 0.75
//#property indicator_minimum 0
//#property indicator_maximum 1

extern int period = 12;
extern int ma = 12;
extern string Îïèñàíèå = "0-ATR, 1-Volume, 2-TrueRange, 3-TrueRange Volume, 4-Log, 5-stdDev";
extern int valueType = 0;

extern int normLimit = 24;
int maType = 0;


double AtrBuffer[];
double FlatBuffer[];

double MaBuffer[];
double TempBuffer[];

int init(){
   //normLimit = 1440 / Period();
   IndicatorBuffers(5);

   SetIndexStyle(0, DRAW_LINE, EMPTY, 1);
   SetIndexStyle(1, DRAW_LINE, EMPTY, 1);
   
   SetIndexBuffer(0, AtrBuffer);
   SetIndexBuffer(1, FlatBuffer);
   SetIndexBuffer(2, MaBuffer);
   SetIndexBuffer(3, TempBuffer);

   string short_name = "ATRNorm(" + period + "," + ma + "," + normLimit + " " + valueName(valueType) + ")";
   IndicatorShortName(short_name);
   SetIndexLabel(0, short_name);
}

string valueName(int valueType) {
   switch(valueType) {
      case 0: 
         return("ATR");
         break;
      case 1: 
         return("Volume");
         break;
      case 2:
         return("TrueRange");
         break;
      case 3: 
         return("TrueRange Volume");
         break;
      case 4: 
         return("Log");
         break;
      case 5: 
         return("stdDev");
         break;
   }
}

int start(){
   int i;
   int counted_bars=  IndicatorCounted();
   if(counted_bars>0) {
      counted_bars--;
   }
   int limit=Bars - counted_bars -1;
   for(i = limit; i >= 0; i--) {
      TempBuffer[i] = trueRange_getValue(valueType, i); 
   }
   
   for(i = limit; i >= 0; i--) {
      if(valueType != 5 || valueType != 0) {
         MaBuffer[i] = iMAOnArray(TempBuffer, 0, period, 0, maType, i);
      } else {
         MaBuffer[i] = TempBuffer[i];
      }
   }
   
   for(i = limit; i >= 0; i--) {
      AtrBuffer[i] = indiUtils_normValue(MaBuffer, normLimit, i);
   }
   
   for(i = limit - 1 ; i >= 0; i--) {
      FlatBuffer[i] = iMAOnArray(AtrBuffer, 0, ma, 0, maType, i);
   }
}

double indiUtils_normValue(double &buffer[], int normLimit, int i) {
   double max = buffer[ArrayMaximum(buffer, normLimit, i)];
   double min = buffer[ArrayMinimum(buffer, normLimit, i)];
   double value = 0;
   if(max - min == 0) {
      value = 1;
   } else {
      value = (buffer[i] - min) / (max - min);
   }
   if (value > 1) {
      value = 1;
   } else if(value < 0) {
      value = 0;
   }
   return(value);
}


double trueRange_getValue(int valueType, int shift) {
   double value  = 0;
   switch(valueType) {
      case 0:
         if(shift==Bars-1) { 
             value = High[shift]-Low[shift];
          } else{
             value = MathMax(High[shift], Close[shift+1]) - MathMin(Low[shift], Close[shift+1]);
          }
          return(iATR(NULL, 0, period, shift));
      case 1:
         return(Volume[shift]);
      case 2:
          if(shift==Bars-1) { 
             value = High[shift]-Low[shift];
          } else{
             value = MathMax(High[shift], High[shift+1]) - MathMin(Low[shift], Low[shift+1]);
          }
          return(value);
          
      case 3:
          if(shift==Bars - 1) { 
             value = High[shift]-Low[shift];
          } else{
             value = MathMax(High[shift], Close[shift + 1]) - MathMin(Low[shift], Close[shift + 1]);
          }
          return(value / Point * Volume[shift]);
      case 4:
          if(Close[shift + 1] == 0) {
            value = 0;
          } else {
            value = MathLog(MathMax(Close[shift + 1], Close[shift]) / MathMin(Close[shift + 1], Close[shift]));
          }
          return(value);
      case 5:
          return(iStdDev(NULL, 0, period, 0, 0, 0, shift));
      default:
          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 ---