Miscellaneous
0
Views
0
Downloads
0
Favorites
Gann_Multi_Trend
//+------------------------------------------------------------------+
//| 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 = 1;
extern int Bars2 = 2;
extern int Bars3 = 3;
//---- 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()
{
//----
if(Bars<=Bars1) 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+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--;
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
void SetBufferData(double& up[], double& dn[], int bars, int index)
{
double max = High[index+bars];
double min = Low[index+bars];
for(int i=1; i<bars; i++)
{
max = MathMax(max, High[index+bars+i]);
min = MathMin(max, Low[index+bars+i]);
}
if(High[index]>max && Low[index]>min)
{
dn[index]=EMPTY_VALUE;
up[index]=High[index];
up[index+1]=High[index+1];
return;
}
if(Low[index]<min && High[index]<max)
{
dn[index]=Low[index];
dn[index+1]=Low[index+1];
up[index]=EMPTY_VALUE;
return;
}
if(Low[index]>min && High[index]<max)
{
dn[index]=dn[index+1];
up[index]=up[index+1];
return;
}
if(Low[index]<min && High[index]>max)
{
dn[index]=Low[index];
up[index]=High[index];
return;
}
}
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
---