指标名称:MTGM[color=rgba(0, 0, 0, 0.9)] 版本:MT4 ver. 2.01
[size=16.002px]"MultiTime Guppy Matrix (MTGM)",本指标结合了多组短期和长期移动平均线(MA),用于识别价格趋势的强度和潜在转折点。通过不同颜色的线条区分短期与长期趋势,并支持多时间框架分析。用户可通过按钮快速切换指标的显示与隐藏。
趋势方向:
交叉信号:
金叉: 短期MA上穿长期MA,可能为买入信号。 死叉: 短期MA下穿长期MA,可能为卖出信号。
斜率变化:
[size=16.002px]通过灵活调整参数,本指标可适应不同交易策略,帮助用户捕捉趋势变化与交易机会。 [size=16.002px]
参数:
部分代码展示: //+------------------------------------------------------------------+//| MultiTime Guppy Matrix.mq4 |//| Copyright © 2009-2024, www.QChaos.com |//| https://www.qchaos.com/ |//+------------------------------------------------------------------+#property indicator_chart_window#property indicator_buffers 36#property strict//------------------------------------------------------------------// 多时间框架枚举定义//------------------------------------------------------------------enum enTimeFrames { tf_cu = PERIOD_CURRENT, // 当前图表周期 tf_m1 = PERIOD_M1, // 1分钟周期 tf_m5 = PERIOD_M5, // 5分钟周期 tf_m15 = PERIOD_M15, // 15分钟周期 tf_m30 = PERIOD_M30, // 30分钟周期 tf_h1 = PERIOD_H1, // 1小时周期 tf_h4 = PERIOD_H4, // 4小时周期 tf_d1 = PERIOD_D1, // 日线周期 tf_w1 = PERIOD_W1, // 周线周期 tf_mn1 = PERIOD_MN1, // 月线周期 tf_n1 = -1, // 第一级更高时间框架(动态计算) tf_n2 = -2, // 第二级更高时间框架 tf_n3 = -3 // 第三级更高时间框架 };
//------------------------------------------------------------------// 主参数设置区域//------------------------------------------------------------------extern enTimeFrames TimeFrame = tf_cu; // 选择分析时间框架input string MainTermNote = "=== 主设置 ==="; // 参数分组标题extern ENUM_MA_METHOD MaMode = MODE_EMA; // 移动平均计算方法extern ENUM_APPLIED_PRICE MaPrice = PRICE_CLOSE; // 计算平均值的价格类型
//------------------------------------------------------------------// 短期均线组设置//------------------------------------------------------------------input string ShortTermNote = "=== 短期均线设置 ==="; // 分组标题input int ShortPeriod1 = 3; // 短期均线1周期input int ShortPeriod2 = 5; // 短期均线2周期input int ShortPeriod3 = 8; // 短期均线3周期input int ShortPeriod4 = 10; // 短期均线4周期input int ShortPeriod5 = 12; // 短期均线5周期input int ShortPeriod6 = 15; // 短期均线6周期extern color Upcolor = clrSpringGreen; // 看涨线颜色(春绿色)extern color Dncolor = clrCrimson; // 看跌线颜色(深红色)extern int LineWidth = 1; // 线宽设置extern bool ShowLines = true; // 是否显示短期均线
//------------------------------------------------------------------// 长期均线组设置//------------------------------------------------------------------input string LongTermNote = "=== 长期均线设置 ==="; // 分组标题input int LongPeriod1 = 30; // 长期均线1周期input int LongPeriod2 = 35; // 长期均线2周期input int LongPeriod3 = 40; // 长期均线3周期input int LongPeriod4 = 45; // 长期均线4周期input int LongPeriod5 = 50; // 长期均线5周期input int LongPeriod6 = 60; // 长期均线6周期extern color Upcolor2 = clrDodgerBlue; // 长期看涨线颜色(道奇蓝)extern color Dncolor2 = clrMagenta; // 长期看跌线颜色(品红色)extern int LineWidth2 = 2; // 长期线宽设置extern bool ShowLines2 = true; // 是否显示长期均线
//------------------------------------------------------------------// 按钮控制参数//------------------------------------------------------------------input string ButtonTermNote = "=== 按钮设置 ==="; // 分组标题extern int btn_Subwindow = 0; // 按钮所在子窗口(0=主图)extern ENUM_BASE_CORNER btn_corner = CORNER_LEFT_UPPER; // 按钮定位角落extern string btn_text = "MTGM"; // 按钮显示文本extern string btn_Font = "Arial"; // 按钮字体extern int btn_FontSize = 10; // 字体大小extern color btn_text_ON_color = clrLime; // 启用状态文字颜色extern color btn_text_OFF_color = clrRed; // 关闭状态文字颜色extern string btn_pressed = "MTGM OFF"; // 按下状态显示文本extern string btn_unpressed = "MTGM ON"; // 弹起状态显示文本extern color btn_background_color = clrDimGray; // 按钮背景色extern color btn_border_color = clrBlack; // 按钮边框颜色extern int button_x = 850; // 按钮X轴位置extern int button_y = 0; // 按钮Y轴位置extern int btn_Width = 90; // 按钮宽度extern int btn_Height = 20; // 按钮高度extern string soundBT = "tick.wav"; // 按钮点击音效
//------------------------------------------------------------------// 全局控制参数//------------------------------------------------------------------input bool Interpolate = true; // 是否启用跨周期插值计算bool show_data = true; // 数据展示开关状态string IndicatorName, IndicatorObjPrefix, buttonId; // 指标全局标识
//------------------------------------------------------------------// 数据缓冲区声明//------------------------------------------------------------------// 短期均线组数据缓冲区(6组)double ma[],mada[],madb[],slope[]; // 均线1:数据/上升线/下降线/斜率状态double ma2[],mada2[],madb2[],slope2[]; // 均线2double ma3[],mada3[],madb3[],slope3[]; // 均线3double ma4[],mada4[],madb4[],slope4[]; // 均线4double ma5[],mada5[],madb5[],slope5[]; // 均线5double ma6[],mada6[],madb6[],slope6[]; // 均线6
// 长期均线组数据缓冲区(6组)double ma7[],mada7[],madb7[],slope7[]; // 均线7double ma8[],mada8[],madb8[],slope8[]; // 均线8double ma9[],mada9[],madb9[],slope9[]; // 均线9double ma10[],mada10[],madb10[],slope10[]; // 均线10double ma11[],mada11[],madb11[],slope11[]; // 均线11double ma12[],mada12[],madb12[],slope12[]; // 均线12double count[]; // 通用计数器缓冲区
//------------------------------------------------------------------// 多时间框架调用宏定义//------------------------------------------------------------------string indicatorFileName;#define _mtfCall(_buff,_ind) iCustom(NULL,TimeFrame,indicatorFileName, \ PERIOD_CURRENT,MainTermNote,MaMode,MaPrice,ShortTermNote, \ ShortPeriod1,ShortPeriod2,ShortPeriod3,ShortPeriod4,ShortPeriod5,ShortPeriod6, \ Upcolor,Dncolor,LineWidth,ShowLines,LongTermNote, \ LongPeriod1,LongPeriod2,LongPeriod3,LongPeriod4,LongPeriod5,LongPeriod6, \ Upcolor2,Dncolor2,LineWidth2,ShowLines2,ButtonTermNote, \ btn_Subwindow,btn_corner,btn_text,btn_Font,btn_FontSize, \ btn_text_ON_color,btn_text_OFF_color,btn_pressed,btn_unpressed, \ btn_background_color,btn_border_color,button_x,button_y, \ btn_Width,btn_Height,soundBT,_buff,_ind) // 参数说明:// _buff - 目标缓冲区索引// _ind - 数据索引位置//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+string GenerateIndicatorName(const string target) { string name = target; int try = 2; while(WindowFind(name) != -1) { name = target + " #" + IntegerToString(try ++); } return name; }
//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+int init() { for(int i=0; i<indicator_buffers; i++) SetIndexStyle(i,DRAW_LINE); IndicatorBuffers(49); SetIndexBuffer(0,ma,INDICATOR_DATA); SetIndexStyle(0,ShowLines ? DRAW_LINE : DRAW_NONE,EMPTY,LineWidth,Upcolor); SetIndexBuffer(1,mada,INDICATOR_DATA); SetIndexStyle(1,ShowLines ? DRAW_LINE : DRAW_NONE,EMPTY,LineWidth,Dncolor); SetIndexBuffer(2,madb,INDICATOR_DATA); SetIndexStyle(2,ShowLines ? DRAW_LINE : DRAW_NONE,EMPTY,LineWidth,Dncolor);
SetIndexBuffer(3,ma2,INDICATOR_DATA); SetIndexStyle(3,ShowLines ? DRAW_LINE : DRAW_NONE,EMPTY,LineWidth,Upcolor); SetIndexBuffer(4,mada2,INDICATOR_DATA); SetIndexStyle(4,ShowLines ? DRAW_LINE : DRAW_NONE,EMPTY,LineWidth,Dncolor); SetIndexBuffer(5,madb2,INDICATOR_DATA); SetIndexStyle(5,ShowLines ? DRAW_LINE : DRAW_NONE,EMPTY,LineWidth,Dncolor);
SetIndexBuffer(6,ma3,INDICATOR_DATA); SetIndexStyle(6,ShowLines ? DRAW_LINE : DRAW_NONE,EMPTY,LineWidth,Upcolor); SetIndexBuffer(7,mada3,INDICATOR_DATA); SetIndexStyle(7,ShowLines ? DRAW_LINE : DRAW_NONE,EMPTY,LineWidth,Dncolor); SetIndexBuffer(8,madb3,INDICATOR_DATA); SetIndexStyle(8,ShowLines ? DRAW_LINE : DRAW_NONE,EMPTY,LineWidth,Dncolor);
SetIndexBuffer(9,ma4,INDICATOR_DATA); SetIndexStyle(9,ShowLines ? DRAW_LINE : DRAW_NONE,EMPTY,LineWidth,Upcolor); SetIndexBuffer(10,mada4,INDICATOR_DATA); SetIndexStyle(10,ShowLines ? DRAW_LINE : DRAW_NONE,EMPTY,LineWidth,Dncolor); SetIndexBuffer(11,madb4,INDICATOR_DATA); SetIndexStyle(11,ShowLines ? DRAW_LINE : DRAW_NONE,EMPTY,LineWidth,Dncolor);
SetIndexBuffer(12,ma5,INDICATOR_DATA); SetIndexStyle(12,ShowLines ? DRAW_LINE : DRAW_NONE,EMPTY,LineWidth,Upcolor); SetIndexBuffer(13,mada5,INDICATOR_DATA); SetIndexStyle(13,ShowLines ? DRAW_LINE : DRAW_NONE,EMPTY,LineWidth,Dncolor); SetIndexBuffer(14,madb5,INDICATOR_DATA); SetIndexStyle(14,ShowLines ? DRAW_LINE : DRAW_NONE,EMPTY,LineWidth,Dncolor);
SetIndexBuffer(15,ma6,INDICATOR_DATA); SetIndexStyle(15,ShowLines ? DRAW_LINE : DRAW_NONE,EMPTY,LineWidth,Upcolor); SetIndexBuffer(16,mada6,INDICATOR_DATA); SetIndexStyle(16,ShowLines ? DRAW_LINE : DRAW_NONE,EMPTY,LineWidth,Dncolor); SetIndexBuffer(17,madb6,INDICATOR_DATA); SetIndexStyle(17,ShowLines ? DRAW_LINE : DRAW_NONE,EMPTY,LineWidth,Dncolor);
SetIndexBuffer(18,ma7,INDICATOR_DATA); SetIndexStyle(18,ShowLines2 ? DRAW_LINE : DRAW_NONE,EMPTY,LineWidth2,Upcolor2); SetIndexBuffer(19,mada7,INDICATOR_DATA); SetIndexStyle(19,ShowLines2 ? DRAW_LINE : DRAW_NONE,EMPTY,LineWidth2,Dncolor2); SetIndexBuffer(20,madb7,INDICATOR_DATA); SetIndexStyle(20,ShowLines2 ? DRAW_LINE : DRAW_NONE,EMPTY,LineWidth2,Dncolor2);
SetIndexBuffer(21,ma8,INDICATOR_DATA); SetIndexStyle(21,ShowLines2 ? DRAW_LINE : DRAW_NONE,EMPTY,LineWidth2,Upcolor2); SetIndexBuffer(22,mada8,INDICATOR_DATA); SetIndexStyle(22,ShowLines2 ? DRAW_LINE : DRAW_NONE,EMPTY,LineWidth2,Dncolor2); SetIndexBuffer(23,madb8,INDICATOR_DATA); SetIndexStyle(23,ShowLines2 ? DRAW_LINE : DRAW_NONE,EMPTY,LineWidth2,Dncolor2);
SetIndexBuffer(24,ma9,INDICATOR_DATA); SetIndexStyle(24,ShowLines2 ? DRAW_LINE : DRAW_NONE,EMPTY,LineWidth2,Upcolor2); SetIndexBuffer(25,mada9,INDICATOR_DATA); SetIndexStyle(25,ShowLines2 ? DRAW_LINE : DRAW_NONE,EMPTY,LineWidth2,Dncolor2); SetIndexBuffer(26,madb9,INDICATOR_DATA); SetIndexStyle(26,ShowLines2 ? DRAW_LINE : DRAW_NONE,EMPTY,LineWidth2,Dncolor2);
SetIndexBuffer(27,ma10,INDICATOR_DATA); SetIndexStyle(27,ShowLines2 ? DRAW_LINE : DRAW_NONE,EMPTY,LineWidth2,Upcolor2); SetIndexBuffer(28,mada10,INDICATOR_DATA); SetIndexStyle(28,ShowLines2 ? DRAW_LINE : DRAW_NONE,EMPTY,LineWidth2,Dncolor2); SetIndexBuffer(29,madb10,INDICATOR_DATA); SetIndexStyle(29,ShowLines2 ? DRAW_LINE : DRAW_NONE,EMPTY,LineWidth2,Dncolor2);
SetIndexBuffer(30,ma11,INDICATOR_DATA); SetIndexStyle(30,ShowLines2 ? DRAW_LINE : DRAW_NONE,EMPTY,LineWidth2,Upcolor2); SetIndexBuffer(31,mada11,INDICATOR_DATA); SetIndexStyle(31,ShowLines2 ? DRAW_LINE : DRAW_NONE,EMPTY,LineWidth2,Dncolor2); SetIndexBuffer(32,madb11,INDICATOR_DATA); SetIndexStyle(32,ShowLines2 ? DRAW_LINE : DRAW_NONE,EMPTY,LineWidth2,Dncolor2);
SetIndexBuffer(33,ma12,INDICATOR_DATA); SetIndexStyle(33,ShowLines2 ? DRAW_LINE : DRAW_NONE,EMPTY,LineWidth2,Upcolor2); SetIndexBuffer(34,mada12,INDICATOR_DATA); SetIndexStyle(34,ShowLines2 ? DRAW_LINE : DRAW_NONE,EMPTY,LineWidth2,Dncolor2); SetIndexBuffer(35,madb12,INDICATOR_DATA); SetIndexStyle(35,ShowLines2 ? DRAW_LINE : DRAW_NONE,EMPTY,LineWidth2,Dncolor2);
SetIndexBuffer(36,slope); SetIndexBuffer(37,slope2); SetIndexBuffer(38,slope3); SetIndexBuffer(39,slope4); SetIndexBuffer(40,slope5); SetIndexBuffer(41,slope6); SetIndexBuffer(42,slope7); SetIndexBuffer(43,slope8); SetIndexBuffer(44,slope9); SetIndexBuffer(45,slope10); SetIndexBuffer(46,slope11); SetIndexBuffer(47,slope12); SetIndexBuffer(48,count);
indicatorFileName = WindowExpertName(); TimeFrame = (enTimeFrames)timeFrameValue(TimeFrame);
IndicatorName = GenerateIndicatorName(btn_text); IndicatorObjPrefix = "__" + IndicatorName + "__"; IndicatorShortName(WindowExpertName()); IndicatorDigits(Digits); double val; if(GlobalVariableGet(IndicatorName + "_visibility", val)) show_data = val != 0;
ChartSetInteger(ChartID(), CHART_EVENT_MOUSE_MOVE, 1); buttonId = IndicatorObjPrefix+btn_text; 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(0); }) |