var ancestorid_294154='294154';
var isauth_294154='0';
var istop_294154='1';
var iselite_294154='4524555';
var iscommend_294154='1';
var islock_294154='0';
var title_294154='最近按4小时MACD做的,一定赚翻了';
var body_294154='4小时MACD在巨幅震荡市时通常极具威力,以下是最近三周的图表。个人认为这一有效性还会延续。用易富通做黄金的兄弟们,可以尝试使用MACD的EA指标进行自动交易。我正在编写程序,测试好后可以放在这里给大家分享。
PS: MACD全名移动平滑异同曲线,交易依据是两条速度不同的移动均线的交叉情况。当快速均线自下而上穿越慢速均线时做多,反之向下穿越时做空。有时候越简单的东西越有用,但我们往往认为自己主观判断力?直觉\"超越技术分析。

程序1: 更新的MACD指标文件(MT4自带的MACD指标图看上去很不习惯,因此我也做了更新),请建立一个新的指标文件,重命名为MACD_canonical.mq4,只要编译然后拖到指标窗口就可以看了。
//+------------------------------------------------------------------+
//| MACD_canonical.mq4 |
//| Copyright superflyingcat 2008/04/08 |
//+------------------------------------------------------------------+
#property copyright \"Copyright ?2004, MetaQuotes Software Corp.\"
#property link \"http://www.metaquotes.net/\"
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 Silver
#property indicator_color2 Black
#property indicator_color3 Red
#property indicator_color4 Green
#property indicator_width3 2
#property indicator_width4 2
//---- indicator parameters
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalSMA=9;
//---- indicator buffers
double MacdBuffer[];
double SignalBuffer[];
double DiffBuffer1[];
double DiffBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- drawing settings
SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_LINE);
SetIndexStyle(2,DRAW_HISTOGRAM);
SetIndexStyle(3,DRAW_HISTOGRAM);
SetIndexDrawBegin(1,SignalSMA);
IndicatorDigits(Digits+1);
//---- indicator buffers mapping
SetIndexBuffer(0,MacdBuffer);
SetIndexBuffer(1,SignalBuffer);
SetIndexBuffer(2,DiffBuffer1);
SetIndexBuffer(3,DiffBuffer2);
//---- name for DataWindow and indicator subwindow label
IndicatorShortName(\"MACD(\"+FastEMA+\",\"+SlowEMA+\",\"+SignalSMA+\")\");
SetIndexLabel(0,\"MACD\");
SetIndexLabel(1,\"Signal\");
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- macd counted in the 1-st buffer
for(int i=0; i<limit; i++)
MacdBuffer[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
//---- signal line counted in the 2-nd buffer
for(i=0; i<limit; i++)
SignalBuffer[i]=iMAOnArray(MacdBuffer,Bars,SignalSMA,0,MODE_SMA,i);
for(i=0; i<limit; i++) {
DiffBuffer1[i]=MacdBuffer[i]-SignalBuffer[i];
if (DiffBuffer1[i]<0) DiffBuffer1[i]=0;
}
for(i=0; i<limit; i++) {
DiffBuffer2[i]=MacdBuffer[i]-SignalBuffer[i];
if (DiffBuffer2[i]>0) DiffBuffer2[i]=0;
}
//---- done
return(0);
}
//+------------------------------------------------------------------+
程序2:更新的MACD自动交易程序MACD_modified.mq4, 这个程序本身需要调用前面的自定义指标MACD_canonical.
除了止赢/止损外,我定义了一个新的参数trade_once。如果为1则只进行一次交易(默认值),如果为0会进行多次交易。剩下的大家自己摸索了:-)
//+------------------------------------------------------------------+
//| MACD_modified.mq4 |
//| Copyright superflyingcat 2008/04/08 |
//+------------------------------------------------------------------+
extern double TakeProfit = 5000;
extern double Lots = 1;
extern double StopLoss = 2000;
extern int trade_once = 1;
extern double MACDOpenLevel=3;
extern double MACDCloseLevel=2;
extern double MATrendPeriod=26;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
double MacdCurrent, MacdPrevious, SignalCurrent;
double SignalPrevious, MaCurrent, MaPrevious;
int cnt, ticket, total;
static int opened_bar = 0;
static int opened = 0;
// initial data checks
// it is important to make sure that the expert works with a normal
// chart and the user did not make any mistakes setting external
// variables (Lots, StopLoss, TakeProfit,
// TrailingStop) in our case, we check TakeProfit
// on a chart of less than 100 bars
if(Bars<100)
{
Print(\"bars less than 100\");
return(0);
}
if(TakeProfit<10)
{
Print(\"TakeProfit less than 10\");
return(0); // check TakeProfit
}
// to simplify the coding and speed up access
// data are put into internal variables
MacdCurrent=iCustom(NULL,0,\"MACD_canonical\",0,0);
MacdPrevious=iCustom(NULL,0,\"MACD_canonical\",0,1);
SignalCurrent=iCustom(NULL,0,\"MACD_canonical\",1,0);
SignalPrevious=iCustom(NULL,0,\"MACD_canonical\",1,1);
// MaCurrent=iMA(NULL,0,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,0);
// MaPrevious=iMA(NULL,0,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,1);
total=OrdersTotal();
if(total<1)
{
// no opened orders identified
if(AccountFreeMargin()<(1000*Lots))
{
Print(\"We have no money. Free Margin = \", AccountFreeMargin());
return(0);
}
if(opened>0) {
Print(\"MACD already auto-traded!\");
return(0);
}
// check for long position (BUY) possibility
if(MacdCurrent>SignalCurrent && MacdPrevious<SignalPrevious)
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,\"macd sample\",16384,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) {
if (trade_once > 0) opened = 1;
Print(\"BUY order opened : \",OrderOpenPrice());
Print(\"Current bar: \", Bars);
opened_bar = Bars;
}
}
else Print(\"Error opening BUY order : \",GetLastError());
return(0);
}
// check for short position (SELL) possibility
if(MacdCurrent<SignalCurrent && MacdPrevious>SignalPrevious)
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,\"macd sample\",16384,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) {
if (trade_once > 0) opened = 1;
Print(\"SELL order opened : \",OrderOpenPrice());
Print(\"Current bar: \", Bars);
opened_bar = Bars;
}
}
else Print(\"Error opening SELL order : \",GetLastError());
return(0);
}
return(0);
}
// it is important to enter the market correctly,
// but it is more important to exit it correctly...
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL && // check for opened position
OrderSymbol()==Symbol()) // check for symbol
{
if(OrderType()==OP_BUY) // long position is opened
{
// should it be closed?
if(MacdCurrent<SignalCurrent && MacdPrevious>SignalPrevious)
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position
Print(\"Opened bar: \", opened_bar);
Print(\"Closed bar: \", Bars);
return(0); // exit
}
}
else // go to short position
{
// should it be closed?
if(MacdCurrent>SignalCurrent && MacdPrevious<SignalPrevious)
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position
Print(\"Opened bar: \", opened_bar);
Print(\"Closed bar: \", Bars);
return(0); // exit
}
}
}
}
return(0);
}
// the end.
';
var body1_294154='';
var sign_294154='
';
var cn_294154='superflyingcat@sohu';
var nickname_294154='超级飞猫';
var inputdate_294154='2008-04-02 18:56:44';
var mobile_294154='1';
var Upassportid_294154='superflyingcat@sohu.com';
var Usex_294154='1';
var Uartn_294154='97';
var Ueliten_294154='4';
var Ucommn_294154='6';
var Uloginn_294154='64';
var Ulinet_294154='1961';
var Uscore_294154='303';
var Upower_294154='14';
var Ulevel_294154='2';
var Urole_294154='30';
var Uwenji_294154='';
var isretain_294154='0';
var islianzai_294154='0';
var Uavatar_294154='';
var avatartype_294154='';
var avatarstr_294154='9/ba';
var Uawatarkey_294154='182832b4';