AO с использованием PowMA для тонкой настройки

AO с использованием PowMA для тонкой настройки

5 января 2016, 11:35
Maxim Kuznetsov
0
177

Аналог индикатора AO с возможностью тонкой подстройки периодов и гладкости вычитаемых MA.

//+------------------------------------------------------------------+
//|                                                        PowAO.mq4 |
//|                                                Maxim A.Kuznetsov |
//|                                            nektomk.wordpress.com |
//+------------------------------------------------------------------+
#property copyright "Maxim A.Kuznetsov"
#property link      "nektomk.wordpress.com"
#property version   "1.00"
#property description "Indicator like Awessome Oscillator"
#property description "Shows difference between two PowMA as colored histogram"
#property link "https://www.mql5.com/ru/market/product/13771"
#property strict
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_plots   3
//--- plot AO_UP
#property indicator_label1  "AO_UP"
#property indicator_type1   DRAW_HISTOGRAM
#property indicator_color1  clrGreen
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot AO_DOWN
#property indicator_label2  "AO_DOWN"
#property indicator_type2   DRAW_HISTOGRAM
#property indicator_color2  clrRed
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
//--- plot AO
#property indicator_label3  "AO"
#property indicator_type3   DRAW_LINE
#property indicator_color3  clrGray
#property indicator_style3  STYLE_SOLID
#property indicator_width3  1

//--- input parameters
input int      FASTMA_PERIOD=5;
input double      FASTMA_POWER=0;
input ENUM_APPLIED_PRICE      FASTMA_APPLIED=PRICE_CLOSE;
input int      SLOWMA_PERIOD=34;
input double      SLOWMA_POWER=0;
input ENUM_APPLIED_PRICE      SLOWMA_APPLIED=PRICE_CLOSE;
//--- indicator buffers
double         AO_UP[];
double         AO_DOWN[];
double         AO[];

int OnInit()
{
   SetIndexBuffer(0,AO_UP);
   SetIndexBuffer(1,AO_DOWN);
   SetIndexBuffer(2,AO);
   return(INIT_SUCCEEDED);
}
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[])
{
   int bar;
   double fast,slow;
   ArraySetAsSeries(AO_UP,false);
   ArraySetAsSeries(AO_DOWN,false);
   ArraySetAsSeries(AO,false);
   for(bar=prev_calculated;bar<rates_total;bar++) {
      AO_UP[bar]=AO_DOWN[bar]=AO[bar]=EMPTY_VALUE;
      if (bar<SLOWMA_PERIOD) continue;
      fast=iCustom(_Symbol,_Period,"PowMA",FASTMA_PERIOD,FASTMA_POWER,FASTMA_APPLIED,0,rates_total-bar-1);
      slow=iCustom(_Symbol,_Period,"PowMA",SLOWMA_PERIOD,SLOWMA_POWER,SLOWMA_APPLIED,0,rates_total-bar-1);
      AO[bar]=fast-slow;
      if (AO[bar-1]==EMPTY_VALUE || AO[bar-1]<AO[bar]) {
         AO_UP[bar]=AO[bar];
         AO_DOWN[bar]=EMPTY_VALUE;
      } else {
         AO_UP[bar]=EMPTY_VALUE;
         AO_DOWN[bar]=AO[bar];
      }
   }
   return(rates_total);
}

Приведённый код базируется на индикаторе PowMA https://www.mql5.com/ru/market/product/13771
Поделитесь с друзьями: