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

CandlesticksBW.mq4

CandlesticksBW指标根据AO和AC在主图绘制另类K线。

图表:CandlesticksBW指标

源码:

//+------------------------------------------------------------------+
//|                                               CandlesticksBW.mq4 |
//|                                                         Vladimir |
//+------------------------------------------------------------------+
#property copyright "Vladimir"
#property link      "http://www.125808047.com/"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 LimeGreen
#property indicator_color2 OrangeRed
#property indicator_color3 LimeGreen
#property indicator_color4 OrangeRed

double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];

int ExtCountedBars=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
{
   SetIndexStyle(0,DRAW_HISTOGRAM,0,1,LimeGreen);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_HISTOGRAM,0,1,OrangeRed);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexStyle(2,DRAW_HISTOGRAM,0,2,LimeGreen);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexStyle(3,DRAW_HISTOGRAM,0,2,OrangeRed);
   SetIndexBuffer(3,ExtMapBuffer4);
   Comment("www.125808047.com");
  }
//+------------------------------------------------------------------+
//| 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[])
  {
   if(Bars<=10) return(0);
   ExtCountedBars=IndicatorCounted();

   if (ExtCountedBars<0) return(-1);

   if (ExtCountedBars>0) ExtCountedBars--;
   int pos=Bars-ExtCountedBars-1;

   while(pos>=0)
     {
      if (iAO(NULL,0,pos)>=iAO(NULL,0,pos+1) && iAC(NULL,0,pos)>=iAC(NULL,0,pos+1))
        {
         ExtMapBuffer1[pos]=High[pos];
         ExtMapBuffer2[pos]=Low[pos];
         if (Open[pos]>=Close[pos])
         { ExtMapBuffer3[pos]=Open[pos]; ExtMapBuffer4[pos]=Close[pos]; }
         else // if (Open[pos]<=Close[pos]) 
         { ExtMapBuffer3[pos]=Close[pos]; ExtMapBuffer4[pos]=Open[pos]; }
        }
      else
        {
         if (iAO(NULL,0,pos)<=iAO(NULL,0,pos+1) && iAC(NULL,0,pos)<=iAC(NULL,0,pos+1))
           {
            ExtMapBuffer1[pos]=Low[pos];
            ExtMapBuffer2[pos]=High[pos];
            if (Open[pos]<=Close[pos])
            { ExtMapBuffer3[pos]=Open[pos]; ExtMapBuffer4[pos]=Close[pos]; }
            else // if (Open[pos]>=Close[pos]) 
            { ExtMapBuffer3[pos]=Close[pos]; ExtMapBuffer4[pos]=Open[pos]; }
           }
         else
           {
            ExtMapBuffer1[pos]=EMPTY_VALUE;
            ExtMapBuffer2[pos]=EMPTY_VALUE;
            ExtMapBuffer3[pos]=EMPTY_VALUE;
            ExtMapBuffer4[pos]=EMPTY_VALUE;
           }
        }
      pos--;
     }
   return(0);
  }
//+------------------------------------------------------------------+
打赏
版权所有转载请注明标题及链接:峰汇在线 » CandlesticksBW.mq4
上一篇:
下一篇:
分享到: 更多 (0)

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

支付宝扫一扫打赏

微信扫一扫打赏