诚信为本
量力而为
当前位置:峰汇在线 > MetaTrader 5 > MT5指标 > 正文

价格通道 Price_Channell.mq5

Price_Channell 指标创建价格通道。

图表:Price_Channell 指标

源码:

//+------------------------------------------------------------------+
//|                                               Price_Channell.mq5 |
//|                        Copyright 2009, MetaQuotes Software Corp. |
//+------------------------------------------------------------------+
#property copyright "2009, MetaQuotes Software Corp."
#property link      "http://www.125808047.com"

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_plots   2
#property indicator_type1   DRAW_FILLING
#property indicator_type2   DRAW_LINE
#property indicator_color1  DodgerBlue,Gray
#property indicator_color2  Blue
#property indicator_label1  "Channel upper;Channel lower"
#property indicator_label2  "Channel median"

input int InpChannelPeriod=22; // Period

double    ExtHighBuffer[];
double    ExtLowBuffer[];
double    ExtMiddBuffer[];

void OnInit()
  {
   SetIndexBuffer(0,ExtHighBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,ExtLowBuffer,INDICATOR_DATA);
   SetIndexBuffer(2,ExtMiddBuffer,INDICATOR_DATA);
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);

   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpChannelPeriod);

   PlotIndexSetInteger(0,PLOT_SHIFT,1);
   PlotIndexSetInteger(1,PLOT_SHIFT,1);

   IndicatorSetString(INDICATOR_SHORTNAME,"Price Channel("+string(InpChannelPeriod)+")");
   PlotIndexSetString(0,PLOT_LABEL,"Channel("+string(InpChannelPeriod)+") upper;Channel("+string(InpChannelPeriod)+") lower");
   PlotIndexSetString(1,PLOT_LABEL,"Median("+string(InpChannelPeriod)+")");

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0);
    Comment("www.125808047.com");
  }
//+------------------------------------------------------------------+
//| get highest value for range                                      |
//+------------------------------------------------------------------+
double Highest(const double &array[],int range,int fromIndex)
  {
   double res;
   int i;

   res=array[fromIndex];
   for(i=fromIndex;i>fromIndex-range && i>=0;i--)
     {
      if(res<array[i]) res=array[i];
     }
   return(res);
  }
//+------------------------------------------------------------------+
//| get lowest value for range                                       |
//+------------------------------------------------------------------+
double Lowest(const double &array[],int range,int fromIndex)
  {
   double res;
   int i;

   res=array[fromIndex];
   for(i=fromIndex;i>fromIndex-range && i>=0;i--)
     {
      if(res>array[i]) res=array[i];
     }
   return(res);
  }
//+------------------------------------------------------------------+
//| Price Channell                                                   |
//+------------------------------------------------------------------+
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 &TickVolume[],
                const long &Volume[],
                const int &Spread[])
  {
   int i,limit;

   if(rates_total<InpChannelPeriod)
      return(0);

   if(prev_calculated==0)
      limit=InpChannelPeriod;
   else limit=prev_calculated-1;

   for(i=limit;i<rates_total && !IsStopped();i++)
     {
      ExtHighBuffer[i]=Highest(High,InpChannelPeriod,i);
      ExtLowBuffer[i]=Lowest(Low,InpChannelPeriod,i);
      ExtMiddBuffer[i]=(ExtHighBuffer[i]+ExtLowBuffer[i])/2.0;;
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+
打赏
版权所有转载请注明标题及链接:峰汇在线 » 价格通道 Price_Channell.mq5
上一篇:
下一篇:
分享到: 更多 (0)

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

支付宝扫一扫打赏

微信扫一扫打赏