指标名称:半趋势买卖 HalfTrend
版本:MT4 ver. 1.03
该半趋势MT4指标使用移动平均线来计算准确的信号。作为一个趋势跟踪指标,线上外汇交易者可以在任何时间框架上应用它,以成功进行日内交易。由于该指标提供了不重绘的实时进入和退出箭头信号,外汇交易者认为它是最佳的趋势交易工具。
此外,半趋势MetaTrader 4指标还表明趋势的强度。在没有趋势的情况下,指标保持平坦。然而,如果存在趋势,则指标会朝该方向倾斜。更陡的斜率表明存在强烈的趋势。在强烈的上升趋势中,指标会变成蓝色并陡峭向上倾斜。相反,在强烈的下降趋势中,指标则会变成红色并陡峭向下倾斜。
用半趋势买卖MetaTrader 4指标进行交易?
上述图表显示了指标提供的买卖箭头信号。在买入情况下,首先,价格必须高于指标。其次,指标必须是蓝色的。第三,蓝色箭头信号必须从指标下方出现。
相反,在卖出情况下,价格必须低于指标。并且指标颜色应该是红色的,红色箭头的出现将验证卖出信号。
一旦确认进场并成功放置交易,交易者可以继续持有头寸,并在相反信号处退出。对于买入位置,可以在前一个低点下方设置止损。相反,对于卖出信号,交易者可以在前一个高点上方设置止损。
参数:
以下是参数的中文说明:
- Amplitude(振幅):较高的值提供更好的信号;但是,信号的数量将会减少。
- ShowBars(显示趋势柱):展示趋势柱。
- ShowArrows(显示箭头):显示信号箭头。蓝色箭头代表买入信号,红色箭头代表卖出信号。
- alertsOn(开启警告):开启MT4警告。
- alertsOnCurrent(当前蜡烛警告):True – 在当前蜡烛中警告信号。False – 在蜡烛关闭时警告。
- alertsMessage(警告消息):显示警告消息。
- alertsSound(声音警告):提供声音警告。
- alertsEmail(邮件警告):通过电子邮件发送MT4警告消息。
部分代码展示:
//+———————————————————————-+
//| Half Trend.mq4 |
//| Copyright © 2009-2024, http://www.QChaos.com |
//| https://www.qchaos.com/ |
//+——————————————————————+
property copyright "Copyright © 量化混沌, http://www.qchaos.com"
property link "https://www.qchaos.com"
property version "1.03"
property description "———————————————"
property description "EA、指标公式分享"
property description "EA、指标编写业务承接"
property description "———————————————"
property description "更多资源,关注公众号:量化程序"
property description "微 信:QChaos001"
property description "手机号:134-8068-5281"
property description "———————————————"
property indicator_chart_window
property indicator_buffers 6
property indicator_color1 DodgerBlue // up[]
property indicator_width1 2
property indicator_color2 Red // down[]
property indicator_width2 2
property indicator_color3 DodgerBlue // atrlo[]
property indicator_width3 1
property indicator_color4 Red // atrhi[]
property indicator_width4 1
property indicator_color5 DodgerBlue // arrup[]
property indicator_width5 1
property indicator_color6 Red // arrdwn[]
property indicator_width6 1
extern int Amplitude = 2;
extern bool ShowBars = true;
extern bool ShowArrows = true;
extern bool alertsOn = true;
extern bool alertsOnCurrent = false;
extern bool alertsMessage = true;
extern bool alertsSound = true;
extern bool alertsEmail = false;
bool nexttrend;
double minhighprice,maxlowprice;
double up[],down[],atrlo[],atrhi[],trend[];
double arrup[],arrdwn[];
//+——————————————————————+
//| |
//+——————————————————————+
int init()
{
IndicatorBuffers(7); // +1 buffer – trend[]
SetIndexBuffer(0,up);
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(1,down);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(2,atrlo);
SetIndexBuffer(3,atrhi);
SetIndexBuffer(6,trend);
SetIndexBuffer(4,arrup);
SetIndexBuffer(5,arrdwn);
SetIndexEmptyValue(0,0.0);
SetIndexEmptyValue(1,0.0);
SetIndexEmptyValue(6,0.0);
if(ShowBars)
{
SetIndexStyle(2,DRAW_HISTOGRAM, STYLE_SOLID);
SetIndexStyle(3,DRAW_HISTOGRAM, STYLE_SOLID);
}
else
{
SetIndexStyle(2,DRAW_NONE);
SetIndexStyle(3,DRAW_NONE);
}
if(ShowArrows)
{
SetIndexStyle(4,DRAW_ARROW,STYLE_SOLID); SetIndexArrow(4,233);
SetIndexStyle(5,DRAW_ARROW,STYLE_SOLID); SetIndexArrow(5,234);
}
else
{
SetIndexStyle(4,DRAW_NONE);
SetIndexStyle(5,DRAW_NONE);
}
nexttrend=0;
minhighprice= High[Bars-1];
maxlowprice = Low[Bars-1];
return (0);
}
//+——————————————————————+
//| |
//+——————————————————————+
class CFix { } ExtFix;
//+——————————————————————+
//| |
//+——————————————————————+
int start()
{
double atr,lowprice_i,highprice_i,lowma,highma;
int workbar=0;
int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars–;
int limit = MathMin(Bars-counted_bars,Bars-1);
for(int i=Bars-1; i>=0; i–)
{
lowprice_i=iLow(Symbol(),Period(),iLowest(Symbol(),Period(),MODE_LOW,Amplitude,i));
highprice_i=iHigh(Symbol(),Period(),iHighest(Symbol(),Period(),MODE_HIGH,Amplitude,i));
lowma=NormalizeDouble(iMA(NULL,0,Amplitude,0,MODE_SMA,PRICE_LOW,i),Digits());
highma=NormalizeDouble(iMA(NULL,0,Amplitude,0,MODE_SMA,PRICE_HIGH,i),Digits());
trend[i]=trend[i+1];
atr=iATR(Symbol(),0,100,i)/2;
arrup[i] = EMPTY_VALUE;
arrdwn[i] = EMPTY_VALUE;
if(nexttrend==1)
{
maxlowprice=MathMax(lowprice_i,maxlowprice);
if(highma<maxlowprice && Close[i]<Low[i+1])
{
trend[i]=1.0;
nexttrend=0;
minhighprice=highprice_i;
}
}
if(nexttrend==0)
{
minhighprice=MathMin(highprice_i,minhighprice);
if(lowma>minhighprice && Close[i]>High[i+1])
{
trend[i]=0.0;
nexttrend=1;
maxlowprice=lowprice_i;
}
}
if(trend[i]==0.0)
{
if(trend[i+1]!=0.0)
{
up[i]=down[i+1];
up[i+1]=up[i];
arrup[i] = up[i] – 2atr;
}
else
{
up[i]=MathMax(maxlowprice,up[i+1]);
}
atrhi[i] = up[i] – atr;
atrlo[i] = up[i];
down[i]=0.0;
}
else
{
if(trend[i+1]!=1.0)
{
down[i]=up[i+1];
down[i+1]=down[i];
arrdwn[i] = down[i] + 2atr;
}
else
{
down[i]=MathMin(minhighprice,down[i+1]);
}
atrhi[i] = down[i] + atr;
atrlo[i] = down[i];
up[i]=0.0;
}
}
manageAlerts();
return (0);
}