kevanjj 发表于 2025-7-13 21:21:56

【CCI热力图】一键开启多品种多周期 CCI 热力图面板

指标名称:CCI热力图
版本:MT4 ver. 2.01(指标)
CCI热力图是一个 MetaTrader 4 (MT4) 指标,基于 CCI(Commodity Channel Index)指标,在图表上显示不同交易品种和时间框架的CCI热力图。该指标通过颜色直观地显示市场的 强势上升、弱势区域和强势下降,并提供交互按钮,方便用户开启/关闭热力图。

多品种、多时间框架支持:用户可指定多个交易品种和时间框架,热力图会显示对应的 CCI 信号。✅ CCI 热力图颜色区分:绿色(Strong Up) → CCI 超过 +200,表示强势上升。灰色(Neutral) → CCI 在 -200 到 +200 之间,市场中性。红色(Strong Down) → CCI 低于 -200,表示强势下降。 ✅ 可调节参数:允许用户修改 CCI 计算方式、颜色、按钮位置、窗口位置等。✅ 交互式按钮:图表上有一个 CCI 按钮,用户可点击按钮开启或关闭 CCI 热图。使用方法安装指标
[*]下载 CCI热力图.ex4 文件。
[*]打开 MT4 → 点击 "文件" → "打开数据文件夹"。
[*]进入 MQL4/Indicators/ 目录,将 CCI热力图.ex4 复制到该目录下。
[*]重启 MT4 或在 导航窗口(Ctrl+N) 的 指标列表 右键点击 刷新。

添加到图表
[*]打开 MT4 图表,选择任意交易品种。
[*]在 MT4 导航窗口找到 "CCI热力图" 指标。
[*]双击指标或拖动到图表上。
[*]设置参数(如交易品种、时间框架等)。
[*]点击“确定”,指标会加载在图表上。

使用 CCI 热图
[*]默认情况下,热图会自动显示。
[*]点击左上角 "CCI" 按钮 可切换热图的显示/隐藏状态。

适用交易策略✅ 趋势交易者:可以用来识别市场趋势,当多个时间框架的 CCI 都呈现 绿色(多头)或红色(空头) 时,寻找顺势交易机会。✅ 均值回归交易者:如果 CCI 过度超买或超卖(即绿色变红色或红色变绿色),可以考虑反转交易策略。✅ 多时间框架分析:不同时间框架上的 CCI 信号一致时,可以提高交易信号的可靠性。参数:部分代码展示://+------------------------------------------------------------------+//|                                                    CCI热力图.mq4 |//|                              Copyright © 2009-2024, www.QChaos.com |//|                                          https://www.qchaos.com/ |//+------------------------------------------------------------------+#property copyright "Copyright © 量化混沌, www.qchaos.com"#property link      "https://www.qchaos.com"#property version   "2.01"#property strict//------------------------------------------------------------------#property indicator_chart_window#property strict
extern string Symbols         = "GBPJPY;AUDJPY;NZDJPY;EURJPY;USDJPY;CHFJPY;";// 交易品种列表(用 ";" 分隔)extern string TimeFrames      = "M5;M15;M30;H1;H4";      // 时间周期列表(用 ";" 分隔)
//extern string TimeFrames      = "M1;M5;M15;M30;H1;H4;D1;W1;MN";      // 备用时间周期列表(用 ";" 分隔)extern int    CciPeriod         = 14;                                    // CCI 指标的周期extern ENUM_APPLIED_PRICE Price = PRICE_TYPICAL;                         // CCI 计算价格类型extern double lStrongUp         =200;                                  // CCI 强上升信号阈值extern double lStrongDown       = -200;                                  // CCI 强下降信号阈值extern int    BarToTest         = 0;                                     // 计算的K线索引(0 表示当前K线)extern colorStrongUp          = clrLimeGreen;                        // CCI 强上升时的颜色(绿色)extern colorNeutral         = clrDarkGray;                           // CCI 中性区域的颜色(灰色)extern colorStrongDown      = clrOrangeRed;                        // CCI 强下降时的颜色(红色)extern int    ColorSteps      = 41;                                    // 颜色渐变级数extern colorTextColor         = clrBlack;                              // 按钮文本颜色extern colorBorderColor       = clrBlack;                              // 按钮边框颜色extern colorFillColor         = clrSilver;                           // 按钮背景颜色extern int    Window            = 0;                                     // 指标显示窗口(0 代表主图窗口)extern ENUM_BASE_CORNERCorner = CORNER_LEFT_LOWER;                     // 指标显示位置(左下角)extern int    XShift            = 0;                                     // 水平偏移量extern int    YShift            = 0;                                     // 垂直偏移量extern string UniqueID          = "CCIHeatmap1";                         // 指标唯一标识符
// 按钮相关参数extern string             button_note1          = "------------------------------";// 按钮分隔线extern ENUM_BASE_CORNER   btn_corner            = CORNER_LEFT_UPPER; // 按钮固定在图表的左上角extern string             btn_text            = "CCI";            // 按钮文本extern string             btn_Font            = "Arial";            // 按钮字体extern int                btn_FontSize          = 10;               // 按钮字体大小extern color            btn_text_ON_color   = clrWhite;         // 按钮激活时的文本颜色(白色)extern color            btn_text_OFF_color    = clrRed;             // 按钮关闭时的文本颜色(红色)extern color            btn_background_color= clrDimGray;         // 按钮背景颜色(深灰色)extern color            btn_border_color      = clrBlack;         // 按钮边框颜色(黑色)extern int                button_x            = 20;               // 按钮的 X 轴偏移量extern int                button_y            = 13;               // 按钮的 Y 轴偏移量extern int                btn_Width             = 60;               // 按钮宽度extern int                btn_Height            = 20;               // 按钮高度extern string             button_note2          = "------------------------------";// 按钮分隔线
bool                      show_data             = true;string IndicatorName, IndicatorObjPrefix;//template code end1int    cpairsLen,ctimesLen, aTimes[];string cpairs[];colorcolors[];//+------------------------------------------------------------------------------------------------------------------+string GenerateIndicatorName(const string target) //don't change anything here{   string name = target;   int try         = 2;   while(WindowFind(name) != -1)   {      name = target + " #" + IntegerToString(try                                                ++);   }   return name;}//+------------------------------------------------------------------------------------------------------------------+string buttonId;
//+------------------------------------------------------------------+//|                                                                  |//+------------------------------------------------------------------+int OnInit(){   IndicatorName = GenerateIndicatorName(btn_text);   IndicatorObjPrefix = "__" + IndicatorName + "__";   IndicatorShortName(IndicatorName);   IndicatorDigits(Digits);
   double val;   if(GlobalVariableGet(IndicatorName + "_visibility", val))      show_data = val != 0;
// put init() here   Symbols = StringTrimLeft(StringTrimRight(Symbols));   if(StringSubstr(Symbols,StringLen(Symbols)-1,1) != ";")      Symbols = StringConcatenate(Symbols,";");
   TimeFrames = StringTrimLeft(StringTrimRight(TimeFrames));   if(StringSubstr(TimeFrames,StringLen(TimeFrames)-1,1) != ";")      TimeFrames = StringConcatenate(TimeFrames,";");

   int s = 0, i = StringFind(Symbols,";",s);   while(i > 0)   {      string current = StringSubstr(Symbols,s,i-s);      ArrayResize(cpairs,ArraySize(cpairs)+1);      cpairs = current;      s = i + 1;      i = StringFind(Symbols,";",s);   }   if(Corner==CORNER_LEFT_LOWER|| Corner==CORNER_RIGHT_LOWER)      invertArray(cpairs);   cpairsLen = ArraySize(cpairs);   s = 0;   i = StringFind(TimeFrames,";",s);   while(i > 0)   {      string current = StringSubstr(TimeFrames,s,i-s);      int time = stringToTimeFrame(current);      if(time > 0)      {         ArrayResize(aTimes,ArraySize(aTimes)+1);         aTimes = time;      }      s = i + 1;      i = StringFind(TimeFrames,";",s);   }   if(Corner==CORNER_RIGHT_UPPER || Corner==CORNER_RIGHT_LOWER)      invertiArray(aTimes);   ctimesLen = ArraySize(aTimes);
//////////
   if(ColorSteps%2==0)      ColorSteps++;   ArrayResize(colors,ColorSteps);   int half = ColorSteps/2;   for(i=0; i<half; i++)   {      colors = gradientColor(i+1,half,StrongUp,Neutral);      colors = gradientColor(i+1,half,StrongDown,Neutral);   }   colors = Neutral;
   ChartSetInteger(ChartID(), CHART_EVENT_MOUSE_MOVE, 1);   buttonId = IndicatorObjPrefix + "CCI面板2024";   createButton(buttonId, btn_text, btn_Width, btn_Height, btn_Font, btn_FontSize, btn_background_color, btn_border_color, btn_text_ON_color);   ObjectSetInteger(ChartID(), buttonId, OBJPROP_YDISTANCE, button_y);   ObjectSetInteger(ChartID(), buttonId, OBJPROP_XDISTANCE, button_x);
   return(INIT_SUCCEEDED);}//+------------------------------------------------------------------------------------------------------------------+//don't change anything herevoid createButton(string buttonID,string buttonText,int width,int height,string font,int fontSize,color bgColor,color borderColor,color txtColor){   ObjectDelete(ChartID(),buttonID);   ObjectCreate(ChartID(),buttonID,OBJ_BUTTON,0,0,0);   ObjectSetInteger(ChartID(),buttonID,OBJPROP_COLOR,txtColor);   ObjectSetInteger(ChartID(),buttonID,OBJPROP_BGCOLOR,bgColor);   ObjectSetInteger(ChartID(),buttonID,OBJPROP_BORDER_COLOR,borderColor);   ObjectSetInteger(ChartID(),buttonID,OBJPROP_XSIZE,width);   ObjectSetInteger(ChartID(),buttonID,OBJPROP_YSIZE,height);   ObjectSetString(ChartID(),buttonID,OBJPROP_FONT,font);   ObjectSetString(ChartID(),buttonID,OBJPROP_TEXT,buttonText);   ObjectSetInteger(ChartID(),buttonID,OBJPROP_FONTSIZE,fontSize);   ObjectSetInteger(ChartID(),buttonID,OBJPROP_SELECTABLE,0);   ObjectSetInteger(ChartID(),buttonID,OBJPROP_CORNER,btn_corner);   ObjectSetInteger(ChartID(),buttonID,OBJPROP_HIDDEN,1);   ObjectSetInteger(ChartID(),buttonID,OBJPROP_XDISTANCE,9999);   ObjectSetInteger(ChartID(),buttonID,OBJPROP_YDISTANCE,9999);}//+------------------------------------------------------------------------------------------------------------------+int deinit(){   ObjectsDeleteAll(ChartID(), IndicatorObjPrefix);
//put deinit() here   int idLength = StringLen(UniqueID);   for(int i = ObjectsTotal(); i>=0; i--)   { string name = ObjectName(i); if(StringSubstr(name,0,idLength) == UniqueID) ObjectDelete(name); }
   return(0);}//+------------------------------------------------------------------------------------------------------------------+//don't change anything herebool recalc = true;
//+------------------------------------------------------------------+//|                                                                  |//+------------------------------------------------------------------+void handleButtonClicks(){   if(ObjectGetInteger(ChartID(), buttonId, OBJPROP_STATE))   {      ObjectSetInteger(ChartID(), buttonId, OBJPROP_STATE, false);      show_data = !show_data;      GlobalVariableSet(IndicatorName + "_visibility", show_data ? 1.0 : 0.0);      recalc = true;      start();   }}//+------------------------------------------------------------------------------------------------------------------+void OnChartEvent(const int id, //don't change anything here                  const long &lparam,                  const double &dparam,                  const string &sparam){   handleButtonClicks();}//+------------------------------------------------------------------------------------------------------------------+string GetButtonState(string whichbutton){   bool selected = ObjectGetInteger(ChartID(),whichbutton,OBJPROP_STATE);   if(selected)   { return ("on"); }   else   {      return ("off");   }}//+------------------------------------------------------------------------------------------------------------------+int start(){   handleButtonClicks();   recalc = false;   int xshift=0, nxshift=0;   if(Corner==CORNER_RIGHT_LOWER || Corner==CORNER_RIGHT_UPPER)   {      xshift=49;      nxshift=66;   }   for(int i = 0; i < cpairsLen; i++)      ButtonCreate2(ChartID(),UniqueID+"t"+(string)i,Window,XShift+nxshift+2,YShift+30+i*15,66,14,Corner,cpairs,"Arial",9,TextColor,BorderColor,FillColor);   for(int i = 0; i < ctimesLen; i++)      ButtonCreate2(ChartID(),UniqueID+"h"+(string)i,Window,XShift+xshift+i*50+69,YShift+15,49,14,Corner,timeFrameToString(aTimes),"Arial",9,TextColor,BorderColor,FillColor);   for(int i = 0; i < cpairsLen; i++)      if(iClose(cpairs,0,0)!=0)         for(int t = 0; t < ctimesLen; t++)         {            double value    = iCCI(cpairs,aTimes,CciPeriod,Price,BarToTest);            int    step   = (int)((ColorSteps-1)*(MathMax(MathMin(value,lStrongUp),lStrongDown)-lStrongDown)/(lStrongUp-lStrongDown));            colortheColor = colors;            ButtonCreate2(ChartID(),UniqueID+(string)t+(string)i,Window,XShift+xshift+t*50+69,YShift+30+i*15,49,14,Corner," ","arial",10,theColor,BorderColor,theColor);         }   if(Corner==CORNER_RIGHT_UPPER || Corner==CORNER_RIGHT_LOWER)      ButtonCreate2(ChartID(),UniqueID+"title",Window,XShift+xshift+ctimesLen*50+19,YShift+30+cpairsLen*15,ctimesLen*50-1,14,Corner," CCI ("+(string)CciPeriod+")","arial",10,TextColor,BorderColor,FillColor);   else      ButtonCreate2(ChartID(),UniqueID+"title",Window,XShift+xshift+69,YShift+30+cpairsLen*15,ctimesLen*50-1,14,Corner," CCI ("+(string)CciPeriod+")","arial",10,TextColor,BorderColor,FillColor);//         ButtonCreate2(ChartID(),UniqueID+"title",Window,XShift+xshift+ctimesLen*50+19,YShift+30+cpairsLen*15,ctimesLen*50-1,14,Corner," Stochastic ("+(string)StoPeriod+","+(string)StoSmoothing+")","arial",10,TextColor,BorderColor,FillColor);//   elseButtonCreate2(ChartID(),UniqueID+"title",Window,XShift+xshift+69             ,YShift+30+cpairsLen*15,ctimesLen*50-1,14,Corner," Stochastic ("+(string)StoPeriod+","+(string)StoSmoothing+")","arial",10,TextColor,BorderColor,FillColor);
   if(!show_data)   {      ObjectSetInteger(ChartID(),buttonId,OBJPROP_COLOR,btn_text_OFF_color);      int idLength = StringLen(UniqueID);      for(int i = ObjectsTotal(); i>=0; i--)      { string name = ObjectName(i); if(StringSubstr(name,0,idLength) == UniqueID) ObjectDelete(name); }   }   else      ObjectSetInteger(ChartID(),buttonId,OBJPROP_COLOR,btn_text_ON_color);
   return(0);}
页: [1]
查看完整版本: 【CCI热力图】一键开启多品种多周期 CCI 热力图面板