指标名称:交叉趋势带[color=rgba(0, 0, 0, 0.9)]
版本:MT4 ver. 2.01(指标)
交叉趋势带指标是一种技术分析工具,用于识别市场趋势的变化。该指标通过交叉来生成买入和卖出信号。指标的设计旨在帮助交易者识别潜在的买入和卖出机会,并通过声音和邮件提醒功能提供实时通知。特别扩大了信号箭头。
参数说明
TimeFrame: 时间框架,单位为分钟。默认值为当前图表的时间框架。 FastMA: 快速移动平均线的设置。 FastPrice: 价格模式(0...10)。 FastLength: 平滑周期,默认值为21。 FastMode: 移动平均线模式,默认值为10。 FastShift: 快速移动平均线的位移。 SlowMA: 慢速移动平均线的设置。 SlowPrice: 价格模式(0...10)。 SlowLength: 平滑周期,默认值为34。 SlowMode: 移动平均线模式,默认值为10。 SlowShift: 慢速移动平均线的位移。 ShowFilled: 是否显示填充区域,默认值为true。 CountBars: 计算的柱数,0表示所有柱。 Alerts: 警报和邮件设置。 AlertMode: 警报模式。 AlertShift: 警报位移,0表示当前柱,1表示前一柱。 SoundsNumber: 信号后声音的次数。 SoundsPause: 声音之间的暂停时间(秒)。 UpSound: 上升趋势声音文件。 DnSound: 下降趋势声音文件。 EmailMode: 邮件模式,0表示开启,1表示关闭。 EmailsNumber: 邮件发送次数。
使用方法指标功能买入信号: 白色,生成买入信号。 卖出信号: 红色,生成卖出信号。 声音提醒: 在信号生成时播放指定的声音文件。 邮件提醒: 在信号生成时发送邮件通知。
部分代码展示: //+------------------------------------------------------------------+//| 交叉趋势带.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 indicator_chart_window#property indicator_buffers 6#property indicator_color1 clrRed#property indicator_color2 clrWhite#property indicator_color3 clrDeepSkyBlue#property indicator_color4 clrRed#property indicator_color5 clrBlue#property indicator_color6 clrRed#property indicator_width1 12#property indicator_width2 12#property indicator_width3 1#property indicator_width4 1#property indicator_width5 15 #property indicator_width6 15//---- extern int TimeFrame = 0; // 时间框架,以分钟为单位extern string FastMA = "--- Fast MA ---"; // 快速移动平均线extern int FastPrice = 0; // 价格模式 (0...10)extern int FastLength = 21; // 平滑周期extern int FastMode = 10; // 参见上面的列表extern int FastShift = 0; // 快速移动平均线位移extern string SlowMA = "--- Slow MA ---"; // 慢速移动平均线extern int SlowPrice = 0; // 价格模式 (0...10)extern int SlowLength = 34; // 平滑周期extern int SlowMode = 10; // 参见上面的列表extern int SlowShift = 0; // 慢速移动平均线位移extern bool ShowFilled = true; // 是否显示填充extern int CountBars = 0; // 计算的柱数:0-所有柱extern string Alerts = "--- Alerts & E-Mails ---"; // 警报和电子邮件extern int AlertMode = 0; // 警报模式extern int AlertShift = 1; // 警报位移:0-当前柱,1-前一柱extern int SoundsNumber = 5; // 信号后的声音次数extern int SoundsPause = 5; // 声音之间的暂停时间(秒)extern string UpSound = "alert.wav"; // 上升趋势声音extern string DnSound = "alert2.wav"; // 下降趋势声音extern int EmailMode = 0; // 电子邮件模式:0-开,1-关extern int EmailsNumber = 1; // 电子邮件数量double uptrend[];double dntrend[];double fast[];double slow[];double buy[];double sell[];double trend[];double fastshift[];double slowshift[];double fastprice[];double slowprice[];double tmp[][2][2], ma[2][3];int cBars, draw_begin, fastsize, slowsize;datetime prevtime[2], preTime, ptime;string IndicatorName, TF, fast_name, slow_name;//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+int init(){ if(TimeFrame <= Period()) TimeFrame = Period(); TF = tf(TimeFrame); if(TF == "N/A") TimeFrame = Period(); IndicatorDigits(Digits);//---- IndicatorBuffers(11); SetIndexBuffer( 0, uptrend); SetIndexStyle(0,DRAW_HISTOGRAM); SetIndexBuffer( 1, dntrend); SetIndexStyle(1,DRAW_HISTOGRAM); SetIndexBuffer( 2, fast); SetIndexStyle(2, DRAW_LINE); SetIndexBuffer( 3, slow); SetIndexStyle(3, DRAW_LINE); SetIndexBuffer( 4, buy); SetIndexStyle(4, DRAW_ARROW); SetIndexArrow(4,233); SetIndexBuffer( 5, sell); SetIndexStyle(5, DRAW_ARROW); SetIndexArrow(5,234); SetIndexBuffer( 6, trend); SetIndexBuffer( 7,fastshift); SetIndexBuffer( 8,slowshift); SetIndexBuffer( 9,fastprice); SetIndexBuffer(10,slowprice);//---- fast_name = averageName(FastMode,fastsize); slow_name = averageName(SlowMode,slowsize); IndicatorName = WindowExpertName(); IndicatorShortName(IndicatorName+"["+TF+"]("+FastPrice+","+FastLength+","+fast_name+","+SlowPrice+","+SlowLength+","+slow_name+")"); SetIndexLabel(0,fast_name+"("+FastLength+")"); SetIndexLabel(1,slow_name+"("+SlowLength+")"); SetIndexLabel(2,"buySignal"); SetIndexLabel(3,"sellSignal");//---- if(CountBars == 0) cBars = iBars(NULL,TimeFrame)*TimeFrame/Period() - MathMax(FastLength,SlowLength); else cBars = CountBars*TimeFrame/Period(); draw_begin = Bars - cBars; SetIndexDrawBegin(0,draw_begin); SetIndexDrawBegin(1,draw_begin); SetIndexDrawBegin(2,draw_begin); SetIndexDrawBegin(3,draw_begin); SetIndexDrawBegin(4,draw_begin); SetIndexDrawBegin(5,draw_begin); //---- ArrayResize(tmp,MathMax(fastsize,slowsize)); return(0);}//-----int deinit(){ Comment(""); return(0);}//+------------------------------------------------------------------+//| Geo Crossover_signal |//+------------------------------------------------------------------+int start(){ int shift,limit, counted_bars=IndicatorCounted(); if(counted_bars > 0) limit = Bars - counted_bars - 1; if(counted_bars < 0) return(0); if(counted_bars < 1) { limit = Bars - 1; for(int i=limit;i>=0;i--) { fast = EMPTY_VALUE; slow = EMPTY_VALUE; buy = EMPTY_VALUE; sell = EMPTY_VALUE; } } if(FastShift < 0) int fastlimit = MathAbs(FastShift); else fastlimit = limit; if(SlowShift < 0) int slowlimit = MathAbs(SlowShift); else slowlimit = limit; int limit1 = MathMax(limit,MathMax(fastlimit,slowlimit)); if(TimeFrame != Period()) { limit = TimeFrame/Period()*(limit1+1); for(shift = 0;shift < limit;shift++) { int y = iBarShift(NULL,TimeFrame,Time[shift]); fast[shift] = iCustom(NULL,TimeFrame,IndicatorName,0,"",FastPrice,FastLength,FastMode,FastShift,"",SlowPrice,SlowLength,SlowMode,SlowShift,ShowFilled,CountBars, "",AlertMode,AlertShift,SoundsNumber,SoundsPause,UpSound,DnSound,EmailMode,EmailsNumber,2,y); slow[shift] = iCustom(NULL,TimeFrame,IndicatorName,0,"",FastPrice,FastLength,FastMode,FastShift,"",SlowPrice,SlowLength,SlowMode,SlowShift,ShowFilled,CountBars, "",AlertMode,AlertShift,SoundsNumber,SoundsPause,UpSound,DnSound,EmailMode,EmailsNumber,3,y); buy [shift] = iCustom(NULL,TimeFrame,IndicatorName,0,"",FastPrice,FastLength,FastMode,FastShift,"",SlowPrice,SlowLength,SlowMode,SlowShift,ShowFilled,CountBars, "",AlertMode,AlertShift,SoundsNumber,SoundsPause,UpSound,DnSound,EmailMode,EmailsNumber,4,y); sell[shift] = iCustom(NULL,TimeFrame,IndicatorName,0,"",FastPrice,FastLength,FastMode,FastShift,"",SlowPrice,SlowLength,SlowMode,SlowShift,ShowFilled,CountBars, "",AlertMode,AlertShift,SoundsNumber,SoundsPause,UpSound,DnSound,EmailMode,EmailsNumber,5,y); if(ShowFilled) { uptrend[shift] = iCustom(NULL,TimeFrame,IndicatorName,0,"",FastPrice,FastLength,FastMode,FastShift,"",SlowPrice,SlowLength,SlowMode,SlowShift,ShowFilled,CountBars, "",AlertMode,AlertShift,SoundsNumber,SoundsPause,UpSound,DnSound,EmailMode,EmailsNumber,0,y); dntrend[shift] = iCustom(NULL,TimeFrame,IndicatorName,0,"",FastPrice,FastLength,FastMode,FastShift,"",SlowPrice,SlowLength,SlowMode,SlowShift,ShowFilled,CountBars, "",AlertMode,AlertShift,SoundsNumber,SoundsPause,UpSound,DnSound,EmailMode,EmailsNumber,1,y); } } if(CountBars > 0) { SetIndexDrawBegin(0,Bars - cBars); SetIndexDrawBegin(1,Bars - cBars); SetIndexDrawBegin(2,Bars - cBars); SetIndexDrawBegin(3,Bars - cBars); SetIndexDrawBegin(4,Bars - cBars); SetIndexDrawBegin(5,Bars - cBars); } return(0); } else { for(shift=limit;shift>=0;shift--) { if(FastPrice <= 6) fastprice[shift] = iMA(NULL,0,1,0,0,FastPrice,shift); else if(FastPrice > 6 && FastPrice <= 10) fastprice[shift] = HeikenAshi(FastPrice-7,cBars + FastLength,shift); if(SlowPrice <= 6) slowprice[shift] = iMA(NULL,0,1,0,0,SlowPrice,shift); else if(SlowPrice > 6 && SlowPrice <= 10) slowprice[shift] = HeikenAshi(SlowPrice-7,cBars + SlowLength,shift); fastshift[shift] = allAveragesOnArray(0,fastprice,FastLength,FastMode,fastsize,cBars + FastLength,shift); slowshift[shift] = allAveragesOnArray(1,slowprice,SlowLength,SlowMode,slowsize,cBars + SlowLength,shift); } for(shift=limit1;shift>=0;shift--) { if(FastShift >=0 ||(FastShift < 0 && shift >= MathAbs(FastShift))) fast[shift] = fastshift[shift+FastShift]; if(SlowShift >=0 ||(SlowShift < 0 && shift >= MathAbs(SlowShift))) slow[shift] = slowshift[shift+SlowShift]; trend[shift] = trend[shift+1]; buy [shift] = EMPTY_VALUE; sell[shift] = EMPTY_VALUE; if(fast[shift] > slow[shift] && fast[shift] != EMPTY_VALUE && trend[shift+1] != 1) trend[shift] = 1; if(fast[shift] < slow[shift] && slow[shift] != EMPTY_VALUE && trend[shift+1] !=-1) trend[shift] =-1; double gap = 0.5*MathCeil(iATR(NULL,0,14,shift)/Point); if(trend[shift] != trend[shift+1]) { if(trend[shift] > 0) buy [shift] = MathMin(fast[shift],slow[shift]) - gap*Point; if(trend[shift] < 0) sell[shift] = MathMax(fast[shift],slow[shift]) + 2*gap*Point; } if(ShowFilled) { uptrend[shift] = slow[shift]; dntrend[shift] = fast[shift]; } } if(CountBars > 0) { SetIndexDrawBegin(0,Bars - cBars); SetIndexDrawBegin(1,Bars - cBars); SetIndexDrawBegin(2,Bars - cBars); SetIndexDrawBegin(3,Bars - cBars); SetIndexDrawBegin(4,Bars - cBars); SetIndexDrawBegin(5,Bars - cBars); } if(AlertMode > 0) { bool upTrend = trend[limit1+AlertShift] > 0 && trend[limit1+AlertShift+1] <= 0; bool dnTrend = trend[limit1+AlertShift] < 0 && trend[limit1+AlertShift+1] >= 0; if(upTrend || dnTrend) { if(isNewBar(TimeFrame)) { BoxAlert(upTrend," : BUY Signal @ " +DoubleToStr(Close[limit1+AlertShift],Digits)+", StopLoss @ "+DoubleToStr(buy [limit1+AlertShift],Digits)); BoxAlert(dnTrend," : SELL Signal @ "+DoubleToStr(Close[limit1+AlertShift],Digits)+", StopLoss @ "+DoubleToStr(sell[limit1+AlertShift],Digits)); } WarningSound(upTrend,SoundsNumber,SoundsPause,UpSound,Time[AlertShift]); WarningSound(dnTrend,SoundsNumber,SoundsPause,DnSound,Time[AlertShift]); if(EmailMode > 0) { EmailAlert(upTrend,"BUY" ," : BUY Signal @ " +DoubleToStr(Close[limit1+AlertShift],Digits)+", StopLoss @ "+DoubleToStr(buy [limit1+AlertShift],Digits),EmailsNumber); EmailAlert(dnTrend,"SELL"," : SELL Signal @ "+DoubleToStr(Close[limit1+AlertShift],Digits)+", StopLoss @ "+DoubleToStr(sell[limit1+AlertShift],Digits),EmailsNumber); } } } } return(0);} |