Indicators Used
0
Views
0
Downloads
0
Favorites
[i]Firebird_divergence_v05
//+------------------------------------------------------------------+
//| Custom Moving Average.mq4 |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "TraderSeven"
#property link "TraderSeven@gmx.net"
// Ron integrated the iFXAnalyser concept
// and cxhanged the simpleMA code to a real MA
// Mar 4, 2006
#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 Red
#property indicator_color2 Orange
#property indicator_color3 Black
#property indicator_color4 Black
#property indicator_color5 Black
#property indicator_color6 White
#property indicator_color7 White
double _fba[1505];
double _Slow1[1505], _Fast1[1505];
double _Slow2[1505], _Fast2[1505];
// FireBird Externals and
// Divergence controls
extern int FB_Simple.1_HMA.2=2;
extern int FB_Period=16;
extern int FB_Price=1;
extern double DVLimit=0.0007;
extern double Percent=0.19;
extern double FB_Shift=1;
extern int DV_Simple.1_HMA.2=1;
extern int Fast_Period=5;
extern int Fast_Price = PRICE_OPEN;
extern int Slow_Period=7;
extern int Slow_Price = PRICE_OPEN;
extern int BarCount=1500;
// percent calculation results
double UpperBand;
double LowerBand;
//indicator buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
double ExtMapBuffer6[];
double ExtMapBuffer7[];
int init()
{
// 233 up arrow
// 234 down arrow
// 159 big dot
// 158 little dot
// 168 open square
// 120 box with X
ArraySetAsSeries(_fba,true);
ArraySetAsSeries(_Slow1,true);
ArraySetAsSeries(_Fast1,true);
ArraySetAsSeries(_Slow2,true);
ArraySetAsSeries(_Fast2,true);
UpperBand=(1+Percent/100);
LowerBand=1-Percent/100;
//---- drawing settings
SetIndexStyle (0,DRAW_LINE);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle (1,DRAW_LINE);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexBuffer(2,ExtMapBuffer3);
SetIndexBuffer(3,ExtMapBuffer4);
SetIndexBuffer(4,ExtMapBuffer5);
SetIndexBuffer(5,ExtMapBuffer6);
SetIndexStyle (5,DRAW_ARROW);
SetIndexArrow (5,168);
SetIndexBuffer(6,ExtMapBuffer7);
SetIndexStyle (6,DRAW_ARROW);
SetIndexArrow (6,159);
int i;
//remove the old objects
for(i=0; i<=BarCount; i++)
{
ObjectDelete("myx"+DoubleToStr(i,0));
}
}
int deinit()
{
int i;
//remove the old objects
for(i=0; i<=BarCount; i++)
{
ObjectDelete("myx"+DoubleToStr(i,0));
}
}
int start()
{
int pos;
double myMA;
double MAfull, MAhalf;
double myDynamic=Close[0];
double maF1, maF2, maS1, maS2;
// HMA variables
int fullPeriod;
int halfPeriod;
int sqrtPeriod;
// HMA or not
if(FB_Simple.1_HMA.2==2)
{
// FireBird array
fullPeriod = FB_Period;
halfPeriod = FB_Period/2;
for(pos=BarCount; pos>=0; pos--)
{
MAfull=iMA(Symbol(),0,fullPeriod,0,MODE_LWMA,FB_Price,pos);
MAhalf=iMA(Symbol(),0,halfPeriod,0,MODE_LWMA,FB_Price,pos);
_fba[pos]=(2*MAhalf)-MAfull;
}
}
if(DV_Simple.1_HMA.2==2)
{
// Divergence Step 1
fullPeriod = Fast_Period;
halfPeriod = Fast_Period/2;
for(pos=BarCount; pos>=0; pos--)
{
MAfull=iMA(Symbol(),0,fullPeriod,0,MODE_LWMA,Fast_Price,pos);
MAhalf=iMA(Symbol(),0,halfPeriod,0,MODE_LWMA,Fast_Price,pos);
_Fast1[pos]=(2*MAhalf)-MAfull;
}
fullPeriod = Slow_Period;
halfPeriod = Slow_Period/2;
for(pos=BarCount; pos>=0; pos--)
{
MAfull=iMA(Symbol(),0,fullPeriod,0,MODE_LWMA,Slow_Price,pos);
MAhalf=iMA(Symbol(),0,halfPeriod,0,MODE_LWMA,Slow_Price,pos);
_Slow1[pos]=(2*MAhalf)-MAfull;
}
// Divergence Step 2
fullPeriod = Fast_Period;
halfPeriod = Fast_Period/2;
for(pos=BarCount; pos>=0; pos--)
{
MAfull=iMA(Symbol(),0,fullPeriod,0,MODE_LWMA,Fast_Price,pos+1);
MAhalf=iMA(Symbol(),0,halfPeriod,0,MODE_LWMA,Fast_Price,pos+1);
_Fast2[pos]=(2*MAhalf)-MAfull;
}
fullPeriod = Slow_Period;
halfPeriod = Slow_Period/2;
for(pos=BarCount; pos>=0; pos--)
{
MAfull=iMA(Symbol(),0,fullPeriod,0,MODE_LWMA,Slow_Price,pos+1);
MAhalf=iMA(Symbol(),0,halfPeriod,0,MODE_LWMA,Slow_Price,pos+1);
_Slow2[pos]=(2*MAhalf)-MAfull;
}
}
for(pos=BarCount; pos>=0; pos--)
{
// create Firebird channel (Simple or HMA)
if(FB_Simple.1_HMA.2==1)
{
myMA=iMA(Symbol(),0,FB_Period,0,0,FB_Price,pos+FB_Shift);
}
if(FB_Simple.1_HMA.2==2)
{
sqrtPeriod = MathFloor(MathSqrt(FB_Period*1.00));
myMA=iMAOnArray(_fba,0,sqrtPeriod,0,MODE_LWMA,pos);
}
ExtMapBuffer1[pos]=myMA*UpperBand;
ExtMapBuffer2[pos]=myMA*LowerBand;
// Create Divergence arrays and difference line
// calculate 1st mode
if(DV_Simple.1_HMA.2==1)
{
maF1=iMA(Symbol(),0,Fast_Period,0,MODE_SMA,Fast_Price,pos);
maS1=iMA(Symbol(),0,Slow_Period,0,MODE_SMA,Slow_Price,pos);
ExtMapBuffer3[pos]=(maF1-maS1)+myDynamic;
}
if(DV_Simple.1_HMA.2==2)
{
sqrtPeriod = MathFloor(MathSqrt(Fast_Period*1.00));
maF1=iMAOnArray(_Fast1,0,sqrtPeriod,0,MODE_LWMA,pos);
sqrtPeriod = MathFloor(MathSqrt(Slow_Period*1.00));
maS1=iMAOnArray(_Slow1,0,sqrtPeriod,0,MODE_LWMA,pos);
ExtMapBuffer3[pos]=(maF1-maS1)+myDynamic;
}
//Shaun's Slope counted in the 2-nd buffer
if(DV_Simple.1_HMA.2==1)
{
maF2=iMA(Symbol(),0,Fast_Period,0,MODE_SMA,Fast_Price,pos+1);
maS2=iMA(Symbol(),0,Slow_Period,0,MODE_SMA,Slow_Price,pos+1);
ExtMapBuffer4[pos]=((maF1-maS1)-(maF2-maS2))+myDynamic;
}
if(DV_Simple.1_HMA.2==2)
{
sqrtPeriod = MathFloor(MathSqrt(Fast_Period*1.00));
maF1=iMAOnArray(_Fast2,0,sqrtPeriod,0,MODE_LWMA,pos);
sqrtPeriod = MathFloor(MathSqrt(Slow_Period*1.00));
maS1=iMAOnArray(_Slow2,0,sqrtPeriod,0,MODE_LWMA,pos);
ExtMapBuffer4[pos]=((maF1-maS1)-(maF2-maS2))+myDynamic;
}
// dynamic around Close(0)
ExtMapBuffer5[pos]=(ExtMapBuffer3[pos]-ExtMapBuffer4[pos])+myDynamic;
if( ExtMapBuffer5[pos] >= myDynamic+DVLimit )ExtMapBuffer6[pos]=ExtMapBuffer1[pos];
if( ExtMapBuffer5[pos] <= myDynamic-DVLimit )ExtMapBuffer6[pos]=ExtMapBuffer2[pos];
} //for
} //start
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
---