NRTR1
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
NRTR1
//+------------------------------------------------------------------+
//|                                                         NRTR.mq4 |
//|                                                       Nick Bilak |
//+------------------------------------------------------------------+

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
//---- input parameters
extern int AveragePeriod=10;
extern int CountBars=300;
//---- buffers
double value1[];
double value2[];
int trend=1;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {

//---- indicator line
   IndicatorBuffers(2);
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,159);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,159);
   SetIndexBuffer(0,value1);
   SetIndexBuffer(1,value2);
//----
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| NRTR                                                             |
//+------------------------------------------------------------------+
int start()
  {
   if (CountBars>Bars) CountBars=Bars;
   SetIndexDrawBegin(0,Bars-CountBars+1);
   SetIndexDrawBegin(1,Bars-CountBars+1);
   int i,j,counted_bars=IndicatorCounted();
   double value;
   double dK,ap,AvgRange,price;
   ap=AveragePeriod;
//----
   if(Bars<=AveragePeriod) return(0);

   i=CountBars-1;
   while(i>=0) {
     value1[i]=0; value2[i]=0;
     AvgRange=0;
     for (j=i ; j<i+AveragePeriod; j++) 
         AvgRange += MathAbs((Ask-Bid)+High[j]-Low[j]);
     dK = AvgRange/ap;
     if (Close[i]>10) dK=dK/100.0;

     if (trend >= 0) {
       if (Close[i] > price) {
       	price = Close[i];
       	value = price - dK;
       	trend=1;
       }
       if (Close[i] < value)  {
          price = Close[i];
          value = price + dK;
          trend = -1;
       }
     }
     else if (trend <= 0) {
       if (Close[i] < price) {
       	price = Close[i];
       	value = price + dK;
       	trend=-1;
       }
       if (Close[i] > value) {
          price = Close[i];
          value = price - dK;
          trend = 1;
       }
    }
    if (trend == 1)  {value1[i]=value; value2[i]=0.0;}
    if (trend == -1)  {value2[i]=value; value1[i]=0.0;}

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