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

多个周期最高K线与最低K线的收盘价 KLines.mq4

KLines 指标根据多个周期的最高K线与最低K线的收盘价绘制线段来参考行情波动的不同级别的支撑与阻力。

图表:KLines 指标

源码:

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

extern int KLPeriod=14;
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{ 
   drawLabel();
   Comment("www.125808047.com");
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
  void OnDeinit(const int reason)
  {
   ObjectsDeleteAll() ;
  }
//+------------------------------------------------------------------+
//| 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[])
  {
   double hhmd =iClose(NULL,PERIOD_D1, Highest (NULL,PERIOD_D1, MODE_CLOSE, KLPeriod,1));
   double hhmh4=iClose(NULL,PERIOD_H4, Highest (NULL,PERIOD_H4, MODE_CLOSE, KLPeriod,1));
   double hhmh1=iClose(NULL,PERIOD_H1, Highest (NULL,PERIOD_H1, MODE_CLOSE, KLPeriod,1));
   double hhm30=iClose(NULL,PERIOD_M30, Highest (NULL,PERIOD_M30, MODE_CLOSE, KLPeriod,1));
   double hhm15=iClose(NULL,PERIOD_M15, Highest (NULL,PERIOD_M15, MODE_CLOSE, KLPeriod,1));

   drawLine("HH_D1",Time[50],Time[40],hhmd,hhmd,3,0,Green,1);
   drawLine("HH_H4",Time[40],Time[30],hhmh4,hhmh4,3,0,Green,1);
   drawLine("HH_H1",Time[30],Time[20],hhmh1,hhmh1,3,0,Green,2);
   drawLine("HH_M30",Time[20],Time[10],hhm30,hhm30,3,0,LimeGreen,2);
   drawLine("HH_M15",Time[10],Time[0],hhm15,hhm15,3,0,Lime,1);
   drawLine("HH_D1r",Time[50],Time[40],hhmd,hhmd,1,1,Green,0);
   drawLine("HH_H4r",Time[40],Time[30],hhmh4,hhmh4,1,1,Green,0);
   drawLine("HH_H1r",Time[30],Time[20],hhmh1,hhmh1,1,1,LimeGreen,0);
   drawLine("HH_M30r",Time[20],Time[10],hhm30,hhm30,1,1,Lime,0);

   drawTXTLabel("D1 Bar Highest Close",hhmd,Time[45],Green);
   drawTXTLabel("H4 Bar Highest Close",hhmh4,Time[35],Green);
   drawTXTLabel("H1 Bar Highest Close",hhmh1,Time[25],Green);
   drawTXTLabel("M30 Bar Highest Close",hhm30,Time[15],Green);
   drawTXTLabel("M15 Bar Highest Close",hhm15,Time[5],Green);

   double llmd =iClose(NULL,PERIOD_D1, Lowest (NULL,PERIOD_D1, MODE_CLOSE, KLPeriod,1));
   double llmh4=iClose(NULL,PERIOD_H4, Lowest (NULL,PERIOD_H4, MODE_CLOSE, KLPeriod,1));
   double llmh1=iClose(NULL,PERIOD_H1, Lowest (NULL,PERIOD_H1, MODE_CLOSE, KLPeriod,1));
   double llm30=iClose(NULL,PERIOD_M30, Lowest (NULL,PERIOD_M30, MODE_CLOSE, KLPeriod,1));
   double llm15=iClose(NULL,PERIOD_M15, Lowest (NULL,PERIOD_M15, MODE_CLOSE, KLPeriod,1));

   drawLine("LL_D1",Time[50],Time[40],llmd,llmd,3,0,Red,1);
   drawLine("LL_H4",Time[40],Time[30],llmh4,llmh4,3,0,Red,1);
   drawLine("LL_H1",Time[30],Time[20],llmh1,llmh1,3,0,Red,2);
   drawLine("LL_M30",Time[20],Time[10],llm30,llm30,3,0,Magenta,2);
   drawLine("LL_M15",Time[10],Time[0],llm15,llm15,3,0,Violet,1);
   drawLine("LL_D1r",Time[50],Time[40],llmd,llmd,1,1,Red,0);
   drawLine("LL_H4r",Time[40],Time[30],llmh4,llmh4,1,1,Red,0);
   drawLine("LL_H1r",Time[30],Time[20],llmh1,llmh1,1,1,Magenta,0);
   drawLine("LL_M30r",Time[20],Time[10],llm30,llm30,1,1,Violet,0);

   drawTXTLabel("D1 Bar Lowest Close",llmd,Time[45],Red);
   drawTXTLabel("H4 Bar Lowest Close",llmh4,Time[35],Red);
   drawTXTLabel("H1 Bar Lowest Close",llmh1,Time[25],Red);
   drawTXTLabel("M30 Bar Lowest Close",llm30,Time[15],Red);
   drawTXTLabel("M15 Bar Lowest Close",llm15,Time[5],Red);

   return(rates_total);
  }
//+------------------------------------------------------------------+
void drawTXTLabel(string name,double lvl,datetime time, color Color)
  {
   if(ObjectFind(name)!=0)
     {
      ObjectCreate(name, OBJ_TEXT, 0, time, lvl);
      ObjectSetText(name, name, 8, "Arial", EMPTY);
      ObjectSet(name, OBJPROP_COLOR, Color);
     }
   else
     {
      ObjectMove(name, 0, time, lvl);
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void drawLine(string name,datetime tfrom, datetime tto, double pfrom, double pto, int width, int ray, color Col,int type)
  {
   if(ObjectFind(name)!=0)
     {
      ObjectCreate(name, OBJ_TREND, 0, tfrom, pfrom,tto,pto);
      if(type==1)
         ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID);
      else if(type==2)
            ObjectSet(name, OBJPROP_STYLE, STYLE_DASHDOT);
         else
            ObjectSet(name, OBJPROP_STYLE, STYLE_DOT);
      ObjectSet(name, OBJPROP_COLOR, Col);
      ObjectSet(name,OBJPROP_WIDTH,width);
      ObjectSet(name,OBJPROP_RAY,ray);
     }
   else
     {
      ObjectDelete(name);
      ObjectCreate(name, OBJ_TREND, 0, tfrom, pfrom,tto,pto);
      if(type==1)
         ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID);
      else if(type==2)
            ObjectSet(name, OBJPROP_STYLE, STYLE_DASHDOT);
         else
            ObjectSet(name, OBJPROP_STYLE, STYLE_DOT);
      ObjectSet(name, OBJPROP_COLOR, Col);
      ObjectSet(name,OBJPROP_WIDTH,width);
      ObjectSet(name,OBJPROP_RAY,ray);
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void drawLabel()
  {
   ObjectCreate("KLabelKLines", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("KLabelKLines","Kale Workshop", 15, "Arial", EMPTY);
   ObjectSet("KLabelKLines", OBJPROP_COLOR, DodgerBlue);
   ObjectSet("KLabelKLines", OBJPROP_CORNER, 0);
   ObjectSet("KLabelKLines", OBJPROP_XDISTANCE, 20);
   ObjectSet("KLabelKLines", OBJPROP_YDISTANCE, 20);
   ObjectCreate("InameKLines", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("InameKLines","KLines", 10, "Arial", EMPTY);
   ObjectSet("InameKLines", OBJPROP_COLOR, DodgerBlue);
   ObjectSet("InameKLines", OBJPROP_CORNER, 0);
   ObjectSet("InameKLines", OBJPROP_XDISTANCE, 21);
   ObjectSet("InameKLines", OBJPROP_YDISTANCE, 50);

   string desc="Indicator peroid: "+KLPeriod+" Bars";
   ObjectCreate("DescKLines", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("DescKLines",desc, 8, "Arial", EMPTY);
   ObjectSet("DescKLines", OBJPROP_COLOR, DodgerBlue);
   ObjectSet("DescKLines", OBJPROP_CORNER, 0);
   ObjectSet("DescKLines", OBJPROP_XDISTANCE, 21);
   ObjectSet("DescKLines", OBJPROP_YDISTANCE, 70);
  }
//+------------------------------------------------------------------+
打赏
版权所有转载请注明标题及链接:峰汇在线 » 多个周期最高K线与最低K线的收盘价 KLines.mq4
上一篇:
下一篇:
分享到: 更多 (0)

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

支付宝扫一扫打赏

微信扫一扫打赏