诚信为本
量力而为
当前位置:首页MetaTrader 4MT4指标K线形态修饰指标 DRP.mq4

K线形态修饰指标 DRP.mq4

DRP 指标是MT4自定义主图指标,创建特定的柱状形态以试图描述K线形态。

图表:DRP 指标

源码:

//+------------------------------------------------------------------+
//|                                                          DRP.mq4 |
//|                                                     Yuriy Tokman |
//+------------------------------------------------------------------+
#property copyright "Yuriy Tokman"
#property link      "http://www.125808047.com"

#property indicator_chart_window
extern color     colir = Blue;
extern int       barsToProcess=1000;
       int       total=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
{
   Comment("www.125808047.com");
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   string name;
   for(int i=0;;i++) {
       name=StringConcatenate("drp",DoubleToStr(i,0));
       if(!ObjectDelete(name)) 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[])
  {
   int      counted_bars=IndicatorCounted(),
            per=Period()*60,
            limit=0,
            i=0;
   string   name;
   datetime time_1=0;
   
   limit=Bars-counted_bars;
   
   if(limit>barsToProcess)
      limit=barsToProcess;

   i=limit-1;
   while (i>=0)
    {
     double x=0.0,
            h = iHigh(NULL,0,i),
            l = iLow(NULL,0,i),
            o = iOpen(NULL,0,i),
            c = iClose(NULL,0,i);
     if(c<o)       x=(h+l+c+l)/2;
     else if(c>o)  x=(h+l+c+h)/2;
     else if(c==o) x=(h+l)/2;
     if(ObjectGet(StringConcatenate("drp",DoubleToStr(total-1,0)),
                                    OBJPROP_TIME1)==Time[0]) {
        ObjectSet(StringConcatenate("drp",DoubleToStr(total-1,0)),
                                    OBJPROP_PRICE1,x-l);
        ObjectSet(StringConcatenate("drp",DoubleToStr(total-1,0)),
                                    OBJPROP_PRICE2,x-h);
        break;
       }
     time_1=Time[i]+per;
     while(iBarShift(0,0,time_1,true)==-1 && time_1<Time[0])
           time_1+=per; 
     name=StringConcatenate("drp",DoubleToStr(total,0));
     ObjectCreate(name,OBJ_RECTANGLE,0,
                  Time[i],x-l,time_1,x-h);
     ObjectSet(name,OBJPROP_COLOR,colir);
     total++;
     i--;
    }
   return(rates_total);
  }
版权所有转载请注明标题及链接:峰汇在线 » K线形态修饰指标 DRP.mq4
上一篇:
下一篇:
分享到: 更多 (0)