0
Views
0
Downloads
0
Favorites
GMMAbeta4
//+------------------------------------------------------------------+
//| GMMA.mq4 |
//| QQ:513394217,WeChat:xiaoaizhi1226 |
//| https://www.mql5.com/zh/users/tottiss/ |
//+------------------------------------------------------------------+
#property copyright "QQ:513394217,WeChat:xiaoaizhi1226"
#property link "https://www.mql5.com/zh/users/tottiss/"
#property version "1.00"
#property strict
#define LINES_SIRNAME "GMMA"
#define LINES_TOTAL 12
#define RESET 0
#define COLOR1 C'192,128,128'
#define COLOR2 C'0,128,255'
const double peroid_length[LINES_TOTAL] = {3, 5, 8, 10, 12, 15, 30, 35, 40, 45, 50, 60 };
#property indicator_chart_window
#property indicator_buffers LINES_TOTAL
#property indicator_plots LINES_TOTAL
#property indicator_type1 DRAW_LINE
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
#property indicator_color1 COLOR1
#property indicator_color2 COLOR1
#property indicator_color3 COLOR1
#property indicator_color4 COLOR1
#property indicator_color5 COLOR1
#property indicator_color6 COLOR1
#property indicator_color7 COLOR2
#property indicator_color8 COLOR2
#property indicator_color9 COLOR2
#property indicator_color10 COLOR2
#property indicator_color11 COLOR2
#property indicator_color12 COLOR2
double lineBuffer[LINES_TOTAL];
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
class CIndicatorsBuffers {
public:
double IndBuffer[];
};
CIndicatorsBuffers Ind[LINES_TOTAL];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit() {
//--- indicator buffers mapping
IndicatorBuffers(12);
string shortname = "GMA(";
for(int i = 0; i < LINES_TOTAL; i++) {
SetIndexBuffer(i, Ind[i].IndBuffer, INDICATOR_DATA);
SetIndexDrawBegin(i,10);
shortname += (string)peroid_length[i] + ",";
ArraySetAsSeries(Ind[i].IndBuffer,false);
}
shortname += ")";
IndicatorSetString(INDICATOR_SHORTNAME, shortname);
IndicatorSetInteger(INDICATOR_DIGITS, _Digits + 1);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[]) {
//---
ArraySetAsSeries(close,false);
int i, j, start = 0;
start = prev_calculated - 1;
if(start < 0) start = 0;
for(i = 0; i < rates_total; i++) {
double price = close[i];
for(j = 0; j < LINES_TOTAL; j++) {
if(i == 0) {
Ind[j].IndBuffer[i] = price;
} else {
Ind[j].IndBuffer[i] = (price * 2 + Ind[j].IndBuffer[i - 1] * (peroid_length[j] - 1)) / (peroid_length[j] + 1);
}
}
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
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
---