Indicators Used
0
Views
0
Downloads
0
Favorites
Guppy MMA oscillator mtf
//+------------------------------------------------------------------+
//| Guppy MMA oscilator.mq4 |
//| mladen |
//+------------------------------------------------------------------+
#property copyright "mladen"
#property link "mladenfx@gmail.com"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Gold
#property indicator_level1 0
#property indicator_levelcolor DarkSlateGray
//
//
//
//
//
extern string _ = "parameters";
extern int Price = PRICE_CLOSE;
extern int SignalPeriod = 13;
extern string TimeFrame = "Current time frame";
//
//
//
//
//
double buffer1[];
double buffer2[];
double periods[]={3,5,8,10,12,15,30,35,40,45,50,60};
int persize;
int timeFrame;
string indicatorFileName;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int init()
{
SetIndexBuffer(0,buffer1);
SetIndexBuffer(1,buffer2);
persize = ArraySize(periods);
if (_=="calculating") return(0);
timeFrame = stringToTimeFrame(TimeFrame);
indicatorFileName = WindowExpertName();
return(0);
}
int deinit() { return(0); }
//
//
//
//
//
int start()
{
double alpha = 2.0/(1.0+SignalPeriod);
int counted_bars=IndicatorCounted();
int i,limit;
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit = Bars-counted_bars;
//
//
//
//
//
if (_=="calculating")
{
for(i=limit; i>=0; i--)
{
double sum = 0;
for(int j=0; j<persize; j++)
{
if (periods[j]<30)
sum += iMA(NULL,0,periods[j],0,MODE_EMA,Price,i);
else sum -= iMA(NULL,0,periods[j],0,MODE_EMA,Price,i);
}
buffer1[i] = sum*10.0;
buffer2[i] = buffer2[i+1]+alpha*(buffer1[i]-buffer2[i+1]);
}
return(0);
}
//
//
//
//
//
limit = MathMax(limit,timeFrame/Period());
for(i=limit; i>=0; i--)
{
int y = iBarShift(NULL,timeFrame,Time[i]);
buffer1[i] = iCustom(NULL,timeFrame,indicatorFileName,"calculating",Price,SignalPeriod,0,y);
buffer2[i] = iCustom(NULL,timeFrame,indicatorFileName,"calculating",Price,SignalPeriod,1,y);
}
}
//
//
//
//
//
int stringToTimeFrame(string tfs)
{
for(int l = StringLen(tfs)-1; l >= 0; l--)
{
int char = StringGetChar(tfs,l);
if((char > 96 && char < 123) || (char > 223 && char < 256))
tfs = StringSetChar(tfs, l, char - 32);
else
if(char > -33 && char < 0)
tfs = StringSetChar(tfs, l, char + 224);
}
//
//
//
//
//
int tf=0;
if (tfs=="M1" || tfs=="1") tf=PERIOD_M1;
if (tfs=="M5" || tfs=="5") tf=PERIOD_M5;
if (tfs=="M15"|| tfs=="15") tf=PERIOD_M15;
if (tfs=="M30"|| tfs=="30") tf=PERIOD_M30;
if (tfs=="H1" || tfs=="60") tf=PERIOD_H1;
if (tfs=="H4" || tfs=="240") tf=PERIOD_H4;
if (tfs=="D1" || tfs=="1440") tf=PERIOD_D1;
if (tfs=="W1" || tfs=="10080") tf=PERIOD_W1;
if (tfs=="MN" || tfs=="43200") tf=PERIOD_MN1;
if (tf<Period() && tf!=0) tf=Period();
return(tf);
}
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
---