awesome_mtf_nl

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
awesome_mtf_nl
//+------------------------------------------------------------------+
//|                                               Awesome_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_SOLID
#property  indicator_levelcolor SlateGray

#property  indicator_color1  Black
#property  indicator_color2  Green //colors for 1'st AO
#property  indicator_color3  Red

#property  indicator_color4  Black
#property  indicator_color5  DodgerBlue //colors for 2'st AO
#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 1_____";
extern int  AO1_TF=0; // Timeframe
extern int  ma1_fast=5; //standart AO SMA fast Period=5
extern int  ma1_slow=34; //standart AO SMA slow Period=34
extern bool AO1_line=true;
extern string _______Parameter2_______ = "_______Awesome Oscillator 2_____";
extern int  AO2_TF=0; // Timeframe
extern int  ma2_fast=21; //custom AO SMA fast Period
extern int  ma2_slow=55; //custom AO SMA slow Period
extern bool AO2_line=true;

//---- indicator buffers
double     ExtBuffer0[];
double     ExtBuffer1[];
double     ExtBuffer2[];

double     ExtBuffer3[];
double     ExtBuffer4[];
double     ExtBuffer5[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorBuffers(6);
   IndicatorDigits(2);
   //---- drawing settings
   if (AO1_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 (AO2_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,ma1_slow);
   SetIndexDrawBegin(1,ma1_slow);
   SetIndexDrawBegin(2,ma1_slow);

   SetIndexDrawBegin(3,ma2_slow);
   SetIndexDrawBegin(4,ma2_slow);
   SetIndexDrawBegin(5,ma2_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
   IndicatorShortName("AO ("+ma1_fast+","+ma1_slow+") TF_"+StrPer(AO1_TF)+"+ AO ("+ma2_fast+","+ma2_slow+") TF_"+StrPer(AO2_TF));
   SetIndexLabel(1,NULL);
   SetIndexLabel(2,NULL);
   SetIndexLabel(4,NULL);
   SetIndexLabel(5,NULL);
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Awesome Oscillator                                               |
//+------------------------------------------------------------------+
int start()
{
   int    limit;
   int    counted_bars=IndicatorCounted();
   double AO1_prev,AO1_current,AO2_prev,AO2_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++)
   {
     ExtBuffer0[i]=(iMA(NULL,AO1_TF,ma1_fast,0,MODE_SMA,PRICE_MEDIAN,i)-iMA(NULL,AO1_TF,ma1_slow,0,MODE_SMA,PRICE_MEDIAN,i))/Point;
     ExtBuffer3[i]=(iMA(NULL,AO2_TF,ma2_fast,0,MODE_SMA,PRICE_MEDIAN,i)-iMA(NULL,AO2_TF,ma2_slow,0,MODE_SMA,PRICE_MEDIAN,i))/Point;
   }
//---- dispatch values between 2 buffers

   bool AO1_up=true, AO2_up=true;
   for(i=limit-1; i>=0; i--)
   {
      AO1_current=ExtBuffer0[i];
      AO1_prev=ExtBuffer0[i+1];

      AO2_current=ExtBuffer3[i];
      AO2_prev=ExtBuffer3[i+1];

      if(AO1_current>AO1_prev) AO1_up=true;
      if(AO1_current<AO1_prev) AO1_up=false;

      if(AO2_current>AO2_prev) AO2_up=true;
      if(AO2_current<AO2_prev) AO2_up=false;

      if(!AO1_up)
      {
         ExtBuffer2[i]=AO1_current;
         ExtBuffer1[i]=EMPTY_VALUE;
         ExtBuffer1[i+1]=AO1_prev;

      }
      else
      {
         ExtBuffer1[i]=AO1_current;
         ExtBuffer2[i]=EMPTY_VALUE;
         ExtBuffer1[i+1]=AO1_prev;
      }

      if(!AO2_up)
      {
         ExtBuffer5[i]=AO2_current;
         ExtBuffer4[i]=EMPTY_VALUE;
         ExtBuffer4[i+1]=AO2_prev;

      }
      else
      {
         ExtBuffer4[i]=AO2_current;
         ExtBuffer5[i]=EMPTY_VALUE;
         ExtBuffer4[i+1]=AO2_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 supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---