Indicators Used
Miscellaneous
0
Views
0
Downloads
0
Favorites
VininI_CMA
//+------------------------------------------------------------------+
//| CMA.mq4 |
//| Raff |
//| just_raff1410@yahoo.com |
//+------------------------------------------------------------------+
// "Modify 2008, Victor Nicolev"
// link "vinin.ucoz.ru"
// Óáðàë âñå ÿâíûå îøèáêè, òåïåðü èíäèêòîð ìîæíî èñïîëüçîâàòü â ñîâåòíèêå
// Ïðè èñïîëüçîâàíèè â îñâåòíèêå îáðàùàòüñÿ ê íóëåâîìó áóôôåðó
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Yellow
#property indicator_color2 Green
#property indicator_color3 Red
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2
extern int Ma_Period = 5;
extern int Ma_Method = 0;
extern int Ma_Price = 0;
extern double Koef=1.0;
//---- buffers
double CA[];
double DIR[];
double UpBuffer[];
double DnBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_LINE);
SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(0,CA);
SetIndexBuffer(1,UpBuffer);
SetIndexBuffer(2,DnBuffer);
SetIndexDrawBegin(0,Ma_Period);
SetIndexDrawBegin(1,Ma_Period);
SetIndexDrawBegin(2,Ma_Period);
IndicatorShortName("CMA("+Ma_Period+")");
SetIndexLabel(1,"UP");
SetIndexLabel(2,"DN");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start() {
double K, v1, v2, MA;
int counted_bars = IndicatorCounted();
if(counted_bars < 0) return(-1);
if (counted_bars > 0) counted_bars--;
int i, limit;
limit=Bars - counted_bars-1;
for(i=limit;i>=0;i--) {
if (CA[i+1]==0) CA[i+1]=Price(Ma_Price,i+1);
MA=iMA(NULL,0,Ma_Period,0,Ma_Method,Ma_Price,i);
v1=Koef*MathSqrt(iStdDev(NULL,0,Ma_Period,0,Ma_Method,Ma_Price,i));
v2=MathSqrt(MathAbs(CA[i+1]-MA));
if (v2<v1 || v2==0) {K=0;} else {K=1-(v1/v2);}
CA[i]=CA[i+1]+K*(MA-CA[i+1]);
DnBuffer[i] = EMPTY_VALUE;
UpBuffer[i] = EMPTY_VALUE;
if (CA[i]-CA[i+1] > 0) UpBuffer[i] = CA[i];
if (CA[i+1]-CA[i] > 0) DnBuffer[i] = CA[i];
}
return(0);
}
//+------------------------------------------------------------------+
double Price(int mode, int pos){
switch (mode) {
case PRICE_CLOSE : return(Close[pos]);
case PRICE_OPEN : return(Open[pos]);
case PRICE_HIGH : return(High[pos]);
case PRICE_LOW : return(Low[pos]);
case PRICE_MEDIAN : return((High[pos]+Low[pos])/2.0);
case PRICE_TYPICAL : return((High[pos]+Low[pos]+Close[pos])/3.0);
case PRICE_WEIGHTED : return((High[pos]+Low[pos]+2.0*Close[pos])/4.0);
}
return(-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
---