True Range Momentum

Author: Mr. Harvester
0 Views
0 Downloads
0 Favorites
True Range Momentum
//+------------------------------------------------------------------+
//|                                          True Range Momentum.mq4 |
//|                                      Copyright 2021, MrHarvester |
//|                                                forwasp@yandex.ru |
//+------------------------------------------------------------------+
#property copyright "Mr. Harvester"
#property link      "forwasp@yandex.ru"
#property description "The indicator measures the acceleration or deceleration of volatility."
#property strict
#property version "1.1"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 clrRed
#property indicator_color2 clrLime
#property indicator_width1  2
#property indicator_width2  1
//---- input parameters
extern int           Far               = 5;  //ATR depth
extern int           AtrPeriod         = 50; //Period ATR
extern int           SignalSMA         = 20; //Period second MA
extern int           SignalOsma        = 5;  //Period signal1
extern ENUM_MA_METHOD Type_MA_ATR      = 0;  //Moving average type
extern ENUM_MA_METHOD Type_MA_Signal   = 0;  //Signal moving average type
//---- buffers
double OsmaBuffer[];
double OsmaSigBuffer[];
double TempBuffer[];
double AtrBuffer[];
double MACDSignBuffer[];

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
   IndicatorBuffers(5);
   SetIndexStyle(0, DRAW_LINE);
   SetIndexStyle(1, DRAW_LINE);
   SetIndexLabel(0,"TRM");
   SetIndexLabel(1,"Signal");
   SetIndexDrawBegin(0, MathMax(AtrPeriod, SignalOsma));
   SetIndexDrawBegin(1, MathMax(AtrPeriod, SignalOsma) + 10);
   IndicatorDigits(Digits + 2);

   SetIndexBuffer(0, OsmaBuffer);
   SetIndexBuffer(1, OsmaSigBuffer);
   SetIndexBuffer(2, AtrBuffer);
   SetIndexBuffer(3, TempBuffer);
   SetIndexBuffer(4, MACDSignBuffer);

   short_name = "True Range Momentum";
   IndicatorShortName(short_name);
   SetIndexLabel(0, short_name);
//----
   SetIndexDrawBegin(0, AtrPeriod);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| ATR                                                              |
//+------------------------------------------------------------------+
int start()
  {
   int i, counted_bars = IndicatorCounted();
//----
   if(Bars <= AtrPeriod)
      return(0);
//---- initial zero
   if(counted_bars < 1)
      for(i = 1; i <= AtrPeriod; i++) AtrBuffer[Bars - i] = 0.0;
   
   i = Bars - counted_bars - (1+Far);
   while(i >= 0)
     {
      double high = High[i];
      double low = Low[i];
      if(i == Bars - 1)
         TempBuffer[i] = high - low;
      else
        {
         double prevclose = Close[i + Far];
         TempBuffer[i] = MathMax(high, prevclose) - MathMin(low, prevclose);
        }
      i--;
     }
//+------------------------------------------------------------------+
//| MACDs                                                            |
//+------------------------------------------------------------------+     
   if(counted_bars > 0)
      counted_bars--;
   int limit = Bars - counted_bars;
   for(i = 0; i < limit; i++) AtrBuffer[i] = iMAOnArray(TempBuffer, Bars, AtrPeriod, 0, Type_MA_ATR, i);
   for(i = 0; i < limit; i++) MACDSignBuffer[i] = iMAOnArray(AtrBuffer, Bars, SignalSMA, 0, Type_MA_Signal, i);
   for(i = 0; i < limit; i++) OsmaBuffer[i] = AtrBuffer[i] - MACDSignBuffer[i];
   for(i = 0; i < limit; i++) OsmaSigBuffer[i] = iMAOnArray(OsmaBuffer, Bars, SignalOsma, 0, Type_MA_Signal, i);
   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 ---