Miscellaneous
0
Views
0
Downloads
0
Favorites
Gann_Multi_Trend_2
//+------------------------------------------------------------------+
//| Gann_Multi_Trend.mq4 |
//| Copyright © 2011, Mikhail Pashnin (raxxla). |
//| http://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, Mikhail Pashnin."
#property link "http://www.mql4.com"
#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 Red
#property indicator_color2 Green
#property indicator_color3 Red
#property indicator_color4 Green
#property indicator_color5 Red
#property indicator_color6 Green
extern int Bars1 = 3;
extern int Bars2 = 5;
extern int Bars3 = 8;
//---- buffers
double Buffer1Up[];
double Buffer1Dn[];
double Buffer2Up[];
double Buffer2Dn[];
double Buffer3Up[];
double Buffer3Dn[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,3);
SetIndexBuffer(0,Buffer3Up);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,3);
SetIndexBuffer(1,Buffer3Dn);
SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,2);
SetIndexBuffer(2,Buffer2Up);
SetIndexStyle(3,DRAW_LINE,STYLE_SOLID,2);
SetIndexBuffer(3,Buffer2Dn);
SetIndexStyle(4,DRAW_LINE,STYLE_SOLID,1);
SetIndexBuffer(4,Buffer1Up);
SetIndexStyle(5,DRAW_LINE,STYLE_SOLID,1);
SetIndexBuffer(5,Buffer1Dn);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
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+1+MathMax(Bars3,MathMax(Bars1,Bars2));
int pos=limit-Bars3;
if(Bars1>0)
{
while(pos>=0)
{
SetBufferData(Buffer1Up,Buffer1Dn,Bars1,pos);
pos--;
}
}
pos=limit-Bars1;
if(Bars2>0)
{
while(pos>=0)
{
SetBufferData(Buffer2Up,Buffer2Dn,Bars2,pos);
pos--;
}
}
pos=limit-Bars1;
if(Bars3>0)
{
while(pos>=0)
{
SetBufferData(Buffer3Up,Buffer3Dn,Bars3,pos);
pos--;
}
}
Comment("Gunn_Multi_Trend("+Bars1+"/"+Bars2+"/"+Bars3+")");
//----
return(0);
}
//+------------------------------------------------------------------+
void SetBufferData(double &up[],double &dn[],int bars,int index)
{
int max_i = iHighest(NULL, 0, MODE_HIGH, bars, index+1);
int min_i = iLowest(NULL, 0, MODE_LOW, bars, index+1);
double max = High[max_i];
double min = Low[min_i];
if(High[index]>=max && Low[index]>min)
{
dn[index]=EMPTY_VALUE;
up[index]=High[index];
return;
}
if(Low[index]<=min && High[index]<max)
{
up[index]=EMPTY_VALUE;
dn[index]=Low[index];
return;
}
if(Low[index]<=min && High[index]>=max)
{
up[index]=High[index];
dn[index]=Low[index];
return;
}
up[index]=up[index+1];
dn[index]=dn[index+1];
}
//+------------------------------------------------------------------+
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---