双重指数移动平均线通道 DEMA_Range_Channel.mq5-MT5指标-峰汇在线
诚信为本
量力而为
当前位置:峰汇在线 > MetaTrader 5 > MT5指标 > 正文

双重指数移动平均线通道 DEMA_Range_Channel.mq5

DEMA_Range_Channel 指标根据两条平均线创建通道。

图表:DEMA_Range_Channel 指标

源码:

//+------------------------------------------------------------------+
//|                                           DEMA_Range_Channel.mq5 |
//|                               Copyright © 2018, Nikolay Kositsin | 
//+------------------------------------------------------------------+
#property copyright "Copyright © 2018, Nikolay Kositsin"
#property link       "http://www.125808047.com"
#property description "DEMA Range Channel"
#property version   "1.02"

#property indicator_chart_window 
#property indicator_buffers 9 
#property indicator_plots   4

#define RESET 0 
#property indicator_type1   DRAW_FILLING
#property indicator_color1 clrLavender
#property indicator_label1  "DEMA Range Channel"
#property indicator_type2   DRAW_LINE
#property indicator_type3   DRAW_LINE
#property indicator_color2  clrBlue
#property indicator_color3  clrRed
#property indicator_style2 STYLE_SOLID
#property indicator_style3 STYLE_SOLID
#property indicator_width2  1
#property indicator_width3  1
#property indicator_label2  "Up Line"
#property indicator_label3  "Down Line"
#property indicator_type4   DRAW_COLOR_CANDLES
#property indicator_color4   clrMagenta,clrBrown,clrBlue,clrAqua
#property indicator_label4  "Open;High;Low;Close"

input uint  ma_period=14;
input uint Shift=3;
input int PriceShift=0;

double ExtOpenBuffer[],ExtHighBuffer[],ExtLowBuffer[],ExtCloseBuffer[],ExtColorBuffer[];
double UpIndBuffer[],DnIndBuffer[],UpLineBuffer[],DnLineBuffer[];
double dPriceShift;
int min_rates_total;
int HInd_Handle,LInd_Handle;
//+---------------------------------------------------------------------+   
//| DEMA_Range_Channel indicator initialization function                | 
//+---------------------------------------------------------------------+ 
int OnInit()
  {
   min_rates_total=int(ma_period*2);
   dPriceShift=_Point*PriceShift;

   HInd_Handle=iDEMA(Symbol(),PERIOD_CURRENT,ma_period,0,PRICE_HIGH);
   if(HInd_Handle==INVALID_HANDLE)
     {
      Print(" Не удалось получить хендл индикатора DEMA PRICE_HIGH");
      return(INIT_FAILED);
     }
   LInd_Handle=iDEMA(Symbol(),PERIOD_CURRENT,ma_period,0,PRICE_LOW);
   if(LInd_Handle==INVALID_HANDLE)
     {
      Print(" Не удалось получить хендл индикатора DEMA PRICE_LOW");
      return(INIT_FAILED);
     }
   SetIndexBuffer(0,UpIndBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,DnIndBuffer,INDICATOR_DATA);
   PlotIndexSetInteger(0,PLOT_SHIFT,Shift);
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);
   SetIndexBuffer(2,UpLineBuffer,INDICATOR_DATA);
   SetIndexBuffer(3,DnLineBuffer,INDICATOR_DATA);
   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,min_rates_total);
   PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,min_rates_total);
   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE);
   PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,EMPTY_VALUE);
   PlotIndexSetInteger(1,PLOT_SHIFT,Shift);
   PlotIndexSetInteger(2,PLOT_SHIFT,Shift);
   SetIndexBuffer(4,ExtOpenBuffer,INDICATOR_DATA);
   SetIndexBuffer(5,ExtHighBuffer,INDICATOR_DATA);
   SetIndexBuffer(6,ExtLowBuffer,INDICATOR_DATA);
   SetIndexBuffer(7,ExtCloseBuffer,INDICATOR_DATA);
   SetIndexBuffer(8,ExtColorBuffer,INDICATOR_COLOR_INDEX);
   PlotIndexSetInteger(3,PLOT_DRAW_BEGIN,min_rates_total);
   PlotIndexSetDouble(3,PLOT_EMPTY_VALUE,EMPTY_VALUE);
   ArraySetAsSeries(ExtOpenBuffer,true);
   ArraySetAsSeries(ExtHighBuffer,true);
   ArraySetAsSeries(ExtLowBuffer,true);
   ArraySetAsSeries(ExtCloseBuffer,true);
   ArraySetAsSeries(ExtColorBuffer,true);
   ArraySetAsSeries(UpIndBuffer,true);
   ArraySetAsSeries(DnIndBuffer,true);
   ArraySetAsSeries(UpLineBuffer,true);
   ArraySetAsSeries(DnLineBuffer,true);

   string shortname;
   StringConcatenate(shortname,"DEMA_Range_Channel",ma_period,")");
   IndicatorSetString(INDICATOR_SHORTNAME,shortname);
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
   Comment("www.125808047.com"); 
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+ 
//| DEMA_Range_Channel iteration function                            | 
//+------------------------------------------------------------------+ 
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[])
  {
   if(rates_total<min_rates_total) return(RESET);
   if(BarsCalculated(HInd_Handle)<rates_total || BarsCalculated(LInd_Handle)<rates_total) return(prev_calculated);
   int to_copy,limit;
   double HDEMA[],LDEMA[];
   ArraySetAsSeries(open,true);
   ArraySetAsSeries(low,true);
   ArraySetAsSeries(high,true);
   ArraySetAsSeries(close,true);
   ArraySetAsSeries(HDEMA,true);
   ArraySetAsSeries(LDEMA,true);
   if(prev_calculated>rates_total || prev_calculated<=0)
     {
      limit=rates_total-min_rates_total-1; 
     }
   else limit=rates_total-prev_calculated;
   to_copy=limit+1;
   if(CopyBuffer(HInd_Handle,0,0,to_copy,UpLineBuffer)<=0) return(RESET);
   if(CopyBuffer(LInd_Handle,0,0,to_copy,DnLineBuffer)<=0) return(RESET);
   if(CopyBuffer(HInd_Handle,0,0,to_copy,UpIndBuffer)<=0) return(RESET);
   if(CopyBuffer(LInd_Handle,0,0,to_copy,DnIndBuffer)<=0) return(RESET);
   for(int bar=limit; bar>=0 && !IsStopped(); bar--)
     {
      UpLineBuffer[bar]=UpIndBuffer[bar]+=dPriceShift; 
      DnLineBuffer[bar]=DnIndBuffer[bar]-=dPriceShift;
     }
   for(int bar=limit; bar>=0 && !IsStopped(); bar--)
     {
      ExtOpenBuffer[bar]=ExtCloseBuffer[bar]=ExtHighBuffer[bar]=ExtLowBuffer[bar]=ExtColorBuffer[bar]=EMPTY_VALUE;
      if(close[bar]>UpLineBuffer[bar+Shift])
        {
         ExtOpenBuffer[bar]=open[bar];
         ExtCloseBuffer[bar]=close[bar];
         ExtHighBuffer[bar]=high[bar];
         ExtLowBuffer[bar]=low[bar];
         if(close[bar]>=open[bar]) ExtColorBuffer[bar]=3;
         else ExtColorBuffer[bar]=2;
        }
      if(close[bar]<DnLineBuffer[bar+Shift])
        {
         ExtOpenBuffer[bar]=open[bar];
         ExtCloseBuffer[bar]=close[bar];
         ExtHighBuffer[bar]=high[bar];
         ExtLowBuffer[bar]=low[bar];
         if(close[bar]<=open[bar]) ExtColorBuffer[bar]=0;
         else ExtColorBuffer[bar]=1;
        }
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+
打赏
版权所有转载请注明标题及链接:峰汇在线 » 双重指数移动平均线通道 DEMA_Range_Channel.mq5
上一篇:
下一篇:
分享到: 更多 (0)

如您觉得此文不错请扫码打赏!

支付宝扫一扫打赏

微信扫一扫打赏