Indicators Used
Miscellaneous
0
Views
0
Downloads
0
Favorites
MaByMa
//+------------------------------------------------------------------+
//| Copyright © 2010, Ivan Kornilov|
//| MaByMa.mq4|
//| excelf@gmail.com, skype: excelf|
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, Ivan Kornilov. All rights reserved."
#property link "excelf@gmail.com"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Green
#property indicator_color2 Red
extern int ma = 10;
extern int signal = 15;
extern int maType = 0;
extern int maPrice = 0;
double SignalBuffer1[];
double SignalBuffer2[];
int init(){
SetIndexStyle(0, DRAW_LINE, EMPTY, 1);
SetIndexStyle(1, DRAW_LINE, EMPTY, 1);
IndicatorDigits(Digits + 1);
SetIndexBuffer(0, SignalBuffer1);
SetIndexBuffer(1, SignalBuffer2);
IndicatorShortName("MaByMa(" + ma + "," + signal + ")");
SetIndexLabel(0, "SignalBuffer1");
SetIndexLabel(1, "SignalBuffer2");
SetIndexLabel(2, "MABuffer");
}
int start(){
int counted_bars=IndicatorCounted();
if(counted_bars > 0) {
counted_bars--;
}
int limit = Bars - counted_bars - 1;
for(int i = limit; i >= 0; i--) {
SignalBuffer1[i] = iMA(NULL, 0, ma, 0, maType, maPrice, i);
SignalBuffer2[i] = indicators_getMaByMaValue(ma, signal, Period(), i);
}
for(i = limit; i >= 0; i--) {
//SignalBuffer2[i] = iMAOnArray(SignalBuffer1, 0, signal, 0, maType, i);
}
}
#define SECOND_IN_MINUT 60
datetime indicators_maArrayLastTime = 0;
double indicators_maArray[];
double indicators_getMaByMaValue(int maPeriod, int maByma, int tf, int shift = 0) {
if(!ArrayIsSeries(indicators_maArray)) {
ArraySetAsSeries(indicators_maArray, true);
}
int maArraySize = ArraySize(indicators_maArray);
if(maArraySize != maByma) {
maArraySize = ArrayResize(indicators_maArray, maByma);
}
int i;
datetime time = iTime(NULL, tf, shift);
indicators_maArray[0] = iMA(NULL, tf, maPeriod, 0, maType, maPrice, shift);
if(indicators_maArrayLastTime != time) {
if(time - indicators_maArrayLastTime == tf * SECOND_IN_MINUT) {
for(i = maArraySize - 1; i > 0; i--) {
indicators_maArray[i] = indicators_maArray[i - 1];
}
} else {
for(i = maArraySize - 1; i > 0; i--) {
indicators_maArray[i] = iMA(NULL, tf, maPeriod, 0, maType, maPrice, i + shift);
}
}
indicators_maArrayLastTime = time;
}
return(iMAOnArray(indicators_maArray, 0, maByma, 0, maType, 0));
}
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
---