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

另类CCI CCI_CustomCandles.mq4

CCI_CustomCandles指标根据CCI信号创建另类K线。可谓别具风格。

图表:CCI_CustomCandles指标

源码:

//+------------------------------------------------------------------+
//|                                            CCI_CustomCandles.mq4 |
//|                                                  modified by cja |
//+------------------------------------------------------------------+
#property copyright "Copyright @2007, Christof Risch (iya)"
#property link      "http://www.125808047.com/"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Green //wick
#property indicator_color2 Red   //wick
#property indicator_color3 Green //candle
#property indicator_color4 Red   //candle
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 3
#property indicator_width4 3

extern int   CCI_Period     =14;
extern int   CCI_Price      =0;
extern int   Overbought     =100;
extern int   Oversold       =-100;

extern int   BarWidth        =1,
             CandleWidth     =3;

double Bar1[],
       Bar2[],
       Candle1[],
       Candle2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
{
   IndicatorShortName("CCI Candles:("+   CCI_Period+")");
   IndicatorBuffers(4);
   SetIndexBuffer(0,Bar1);
   SetIndexBuffer(1,Bar2);
   SetIndexBuffer(2,Candle1);
   SetIndexBuffer(3,Candle2);
   SetIndexStyle(0,DRAW_HISTOGRAM,0,BarWidth);
   SetIndexStyle(1,DRAW_HISTOGRAM,0,BarWidth);
   SetIndexStyle(2,DRAW_HISTOGRAM,0,CandleWidth);
   SetIndexStyle(3,DRAW_HISTOGRAM,0,CandleWidth);
   Comment("www.125808047.com");
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
double CCI     (int i=0)   {return(iCCI(NULL,0,CCI_Period,CCI_Price,i));}
//+------------------------------------------------------------------+
void SetCandleColor(int col, int i)
  {
   double high,low,bodyHigh,bodyLow;
     {
      bodyHigh=MathMax(Open[i],Close[i]);
      bodyLow =MathMin(Open[i],Close[i]);
      high     =High[i];
      low     =Low[i];
     }
   Bar1[i]=low;   Candle1[i]=bodyLow;
   Bar2[i]=low;   Candle2[i]=bodyLow;
   switch(col)
     {
      case 1:    Bar1[i]=high;   Candle1[i]=bodyHigh;   break;
      case 2:    Bar2[i]=high;   Candle2[i]=bodyHigh;   break;
     }
  }
//+------------------------------------------------------------------+
//| Custom indicator 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[])
  {
   for(int i=MathMax(Bars-1-IndicatorCounted(),1); i>=0; i--)
     {
      double   cci  =CCI(i);
      if(cci > Overbought)      SetCandleColor(1,i);
      else   if(cci < Oversold)      SetCandleColor(2,i);
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+
打赏
版权所有转载请注明标题及链接:峰汇在线 » 另类CCI CCI_CustomCandles.mq4
上一篇:
下一篇:
分享到: 更多 (0)

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

支付宝扫一扫打赏

微信扫一扫打赏