Indicators Used
Miscellaneous
1
Views
0
Downloads
0
Favorites
aoamacd_mtf_nl
//+------------------------------------------------------------------+
//| AO&MACD_MTF_NL.mq4 |
//| -Multitimeframe Normalized / Line |
//| Copyright © 2005, MetaQuotes Software Corp. |
//| http://www.mql5.com/ru/code/7813 |
//| Some features add by AST, 2014 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 6
#property indicator_level1 0.0
#property indicator_levelwidth 0
#property indicator_levelstyle STYLE_DOT
#property indicator_levelcolor DimGray
#property indicator_color1 Black
#property indicator_color2 Green //colors for AO
#property indicator_color3 Red
#property indicator_color4 Black
#property indicator_color5 DodgerBlue //colors for MACD
#property indicator_color6 DodgerBlue
#property indicator_width1 0
#property indicator_width2 2
#property indicator_width3 2
#property indicator_width4 0
#property indicator_width5 2
#property indicator_width6 2
extern string _______Parameter1_______ = "_______Awesome Oscillator_______";
extern bool AO_show=true; // Show AO
extern int AO_TF=0; // Timeframe
extern int AO_fast=5; // Standart AO SMA fast Period=5
extern int AO_slow=34; // Standart AO SMA slow Period=34
extern bool AO_line=true;
extern string _______Parameter2_______ = "_______MACD Oscillator__________";
extern bool MACD_show=true; // Show MACD
extern int MACD_TF=0; // Timeframe
extern int MACD_fast=21; // Standart MACD EMA fast Period=12
extern int MACD_slow=55; // Standart MACD EMA slow Period=26
extern bool MACD_line=true;
//---- indicator buffers
double ExtBuffer0[];
double ExtBuffer1[];
double ExtBuffer2[];
double ExtBuffer3[];
double ExtBuffer4[];
double ExtBuffer5[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string AO_name, MACD_name, sp;
IndicatorBuffers(6);
IndicatorDigits(2);
//---- drawing settings
if (AO_line)
{
SetIndexStyle(0,DRAW_NONE);
SetIndexStyle(1,DRAW_LINE);
SetIndexStyle(2,DRAW_LINE);
} else
{
SetIndexStyle(0,DRAW_NONE);
SetIndexStyle(1,DRAW_HISTOGRAM);
SetIndexStyle(2,DRAW_HISTOGRAM);
}
if (MACD_line)
{
SetIndexStyle(3,DRAW_NONE);
SetIndexStyle(4,DRAW_LINE);
SetIndexStyle(5,DRAW_LINE);
} else
{
SetIndexStyle(3,DRAW_NONE);
SetIndexStyle(4,DRAW_HISTOGRAM);
SetIndexStyle(5,DRAW_HISTOGRAM);
}
SetIndexDrawBegin(0,AO_slow);
SetIndexDrawBegin(1,AO_slow);
SetIndexDrawBegin(2,AO_slow);
SetIndexDrawBegin(3,MACD_slow);
SetIndexDrawBegin(4,MACD_slow);
SetIndexDrawBegin(5,MACD_slow);
//---- 6 indicator buffers mapping
SetIndexBuffer(0,ExtBuffer0);
SetIndexBuffer(1,ExtBuffer1);
SetIndexBuffer(2,ExtBuffer2);
SetIndexBuffer(3,ExtBuffer3);
SetIndexBuffer(4,ExtBuffer4);
SetIndexBuffer(5,ExtBuffer5);
//---- name for DataWindow and indicator subwindow label
if (AO_show)
{
if (MACD_show) sp="+ "; else sp="";
AO_name=StringConcatenate("AO (",AO_fast,",",AO_slow,") TF_",StrPer(AO_TF));
}else AO_name="";
if (MACD_show)
MACD_name=StringConcatenate("MACD (",MACD_fast,",",MACD_slow,") TF_",StrPer(MACD_TF)); else MACD_name="";
IndicatorShortName(AO_name+sp+MACD_name);
SetIndexLabel(0,AO_name);
SetIndexLabel(1,AO_name);
SetIndexLabel(2,AO_name);
SetIndexLabel(3,MACD_name);
SetIndexLabel(4,MACD_name);
SetIndexLabel(5,MACD_name);
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Awesome Oscillator |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
double AO_prev,AO_current,MACD_prev,MACD_current;
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
if(counted_bars==0) limit-=1+1;
//---- macd
for(int i=0; i<limit; i++)
{
if (AO_show) ExtBuffer0[i]=(iMA(NULL,AO_TF,AO_fast,0,MODE_SMA,PRICE_MEDIAN,i)-iMA(NULL,AO_TF,AO_slow,0,MODE_SMA,PRICE_MEDIAN,i))/Point; else ExtBuffer0[i]=EMPTY_VALUE;
if (MACD_show) ExtBuffer3[i]=(iMA(NULL,MACD_TF,MACD_fast,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,MACD_TF,MACD_slow,0,MODE_EMA,PRICE_CLOSE,i))/Point; else ExtBuffer3[i]=EMPTY_VALUE;
}
//---- dispatch values between 2 buffers
bool AO_up=true, MACD_up=true;
for(i=limit-1; i>=0; i--)
{
if (AO_show)
{
AO_current=ExtBuffer0[i];
AO_prev=ExtBuffer0[i+1];
if(AO_current>AO_prev) AO_up=true;
if(AO_current<AO_prev) AO_up=false;
if(!AO_up)
{
ExtBuffer2[i]=AO_current;
ExtBuffer1[i]=EMPTY_VALUE;
ExtBuffer1[i+1]=AO_prev;
}
else
{
ExtBuffer1[i]=AO_current;
ExtBuffer2[i]=EMPTY_VALUE;
ExtBuffer1[i+1]=AO_prev;
}
}
if (MACD_show)
{
MACD_current=ExtBuffer3[i];
MACD_prev=ExtBuffer3[i+1];
if(MACD_current>MACD_prev) MACD_up=true;
if(MACD_current<MACD_prev) MACD_up=false;
if(!MACD_up)
{
ExtBuffer5[i]=MACD_current;
ExtBuffer4[i]=EMPTY_VALUE;
ExtBuffer4[i+1]=MACD_prev;
}
else
{
ExtBuffer4[i]=MACD_current;
ExtBuffer5[i]=EMPTY_VALUE;
ExtBuffer4[i+1]=MACD_prev;
}
}
}
//---- done
return(0);
}
//------------------------------------Period return----------------------------------------
string StrPer(int per)
{
if (per==0) per=Period();
if (per == 1) return("M1 ");
if (per == 5) return("M5 ");
if (per == 15) return("M15 ");
if (per == 30) return("M30 ");
if (per == 60) return("H1 ");
if (per == 240) return("H4 ");
if (per == 1440) return("D1 ");
if (per == 10080) return("W1 ");
if (per == 43200) return("MN ");
return("îøèáêà ïåðèîäà");
}
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
---