Price_Channel

Author: Copyright � 2009, MaxxMT
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
Price_Channel
//+------------------------------------------------------------------+
//|                                                Price Channel.mq4 |
//|                                         Copyright © 2009, MaxxMT |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, MaxxMT"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Blue
//---- indicator parameters
extern int High_Period      = 10;
extern int Low_Period       = 10;
extern int Shift            = 1;
extern int Timeframe        = 1440;
//---- indicator buffers
double HighBuffer[];
double LowBuffer[];
//----
int ExtCountedBars=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexShift(0,Shift);
   SetIndexShift(1,Shift);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
   IndicatorShortName("Price Channel("+High_Period+", "+Low_Period+")");
   SetIndexLabel(0,"Highest("+High_Period+")");
   SetIndexLabel(1,"Lowest("+Low_Period+")");
   SetIndexDrawBegin(0,High_Period);
   SetIndexDrawBegin(1,Low_Period);
//---- indicator buffers mapping
   SetIndexBuffer(0,HighBuffer);
   SetIndexBuffer(1,LowBuffer);
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+

int start()
  {
   if(Bars<=MathMax(High_Period,Low_Period)) return(0);

   int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   int limit=Bars-counted_bars;
   if(counted_bars==0) limit-=1+MathMax(Low_Period,High_Period)*MathMax(Low_Period,High_Period);
//----
   highest(limit);
   lowest(limit);
//---- done
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void highest(int index)
  {
   if (index<=0) return;
   int i=index;
   int j=High_Period;
   while(i>=0)
     {
      int ind1=iHighest(NULL,Timeframe,MODE_HIGH,High_Period,i);
      double high=High[ind1];
      if(i==Bars-1) HighBuffer[i]=high;
      else
        {
         for(j=1;j<=High_Period;j++) double nexthigh=High[i+j];
         HighBuffer[i]=MathMax(high,nexthigh);
         j++;
        }
      i--;
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void lowest(int index)
  {
   if (index<=0) return;
   int k=index;
   int l=Low_Period;
   while(k>=0)
     {
      int ind1=iLowest(NULL,Timeframe,MODE_LOW,Low_Period,k);
      double low=Low[ind1];
      if(k==Bars-1) LowBuffer[k]=low;
      else
        {
         for(l=1;l<=Low_Period;l++) double nextlow=Low[k+l];
         LowBuffer[k]=MathMin(low,nextlow);
         l++;
        }
      k--;
     }
  }
//+------------------------------------------------------------------+

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