i-MA-ATR-ROC

Author: =A9 2007 RickD
Indicators Used
Moving average indicatorIndicator of the average true range
Miscellaneous
Implements a curve of type %1
1 Views
0 Downloads
0 Favorites
i-MA-ATR-ROC

#property copyright "=A9 2007 RickD"
#property link      "www.e2e-fx.net"

#define vers    "03.09.2007"
#define major   1
#define minor   2

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Lime
#property indicator_width1 2

extern int MA.Length =3D 20;
extern int MA.Type   =3D MODE_SMA;
extern int MA.Price  =3D PRICE_CLOSE;
extern int ATR.Period =3D 5;
extern int ROC.Period =3D 5;
extern double NonYenTrendLevel =3D 50;
extern double YenTrendLevel =3D 0.5;
extern color LevelCol =3D Silver;

string Iname =3D "";
double line1[],line2[],MARoc[];

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=
~~~~~~~~~~~~~~

void init()
{
   //---- indicators
   IndicatorBuffers(3);
   SetIndexBuffer(0, MARoc);
   SetIndexStyle(0, DRAW_LINE);
   SetIndexDrawBegin(0, MA.Length+ROC.Period);
   SetIndexBuffer(1,line1);
   SetIndexBuffer(2,line2);
   SetIndexStyle(1,DRAW_LINE,STYLE_DASH,1);
   SetIndexStyle(2,DRAW_LINE,STYLE_DASH,1);

   Iname =3D "MTFROC";

   IndicatorShortName(Iname);
}

void deinit()
{
}

void start()
{
  double Level =3D NonYenTrendLevel;
  if (StringFind(Symbol(), "JPY") !=3D -1) Level =3D YenTrendLevel;

  drawLine(Iname + "_L1", Level, LevelCol);
  drawLine(Iname + "_L2", -Level,  LevelCol);

  int counted_bars =3D IndicatorCounted();
  if(counted_bars < 0) return;
  if(counted_bars > 0) counted_bars--;

  int limit =3D Bars-counted_bars;

  for (int i=3Dlimit; i >=3D 0; i--)
  {
    double Yx =3D iMA(NULL, 0, MA.Length, 0, MA.Type, MA.Price, =
i+ROC.Period);
    double Y =3D iMA(NULL, 0, MA.Length, 0, MA.Type, MA.Price, i);

    double ROC =3D 0;
    if (Yx !=3D 0) ROC =3D 100*((Y - Yx)/Yx);
   =20
    double ATR =3D iATR(NULL, 0, ATR.Period, i);

    MARoc[i] =3D 0;
    if (ATR !=3D 0) MARoc[i] =3D ROC/ATR;
  }
}

//+------------------------------------------------------------------+
void drawLine(string name, double price, color Col)
{    =20
    ObjectDelete(name);       =20
    ObjectCreate(name, OBJ_HLINE,WindowFind(Iname),Time[0],price);
    ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID);
    ObjectSet(name, OBJPROP_COLOR, Col);       =20
    ObjectSet(name,OBJPROP_WIDTH,1);
}

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