[心得]發表 外匯mt4 程式交易程式碼. for EURUSD.
前幾天逛到的,抓來研究看看,
用mt4跑測試,標的是 EURUSD ,績效卻是本金不斷遞減,
隨便改一些參數,以及小部分程式碼後,發現竟然是能穩定遞增.
測試數據小節,固定下 0.1 手. 時間範圍的選項:不打勾.
用H1跑,下單次數 150 多次,獲利約 500 左右. (不同天,好像也不一樣)
用M5跑,下單次數約 100多次,獲利約300左右.
有些細節我還不是很清楚,算是拋磚引玉,有興趣的歡迎切磋.
// 改自網友 "聖杯" 的範例 by Andrew Chen ,於 高雄.台灣.
// andrewchen101@gmail.com
// 2010/1/29
// 原文網址 http://articles.mql4.com/cn/570
// 原作者資訊 Sergey Kovalyov, Dnepropetrovsk (Ukraine),sk@mail.dnepr.net,ICQ 64015987, http://autograf.dp.ua/
extern int TakeP =11; // 獲利
extern int StopL = 66; // 止損
extern int Distan = 12;
extern int Cls = 25;
extern int period_MA=16;
extern int Prots = 0;
//---------------------------------------------------------------------
int
Nom_bl,
Nom_sl,
total,
bl = 0,
sl = 0,
b = 0,
s = 0;
//---------------------------------------------------------------------
double
OP,
SL,
TP,
dist,
Level,
OP_bl,
OP_sl,
cls,
MA,
spred,
Lot;
int init()
{
Level=MarketInfo(Symbol(),MODE_STOPLEVEL);
Level=(Level+1)*Point;
SL=StopL*Point;
TP=Takep*Point;
dist=Distan*Point;
cls=Cls*Point;
spred=Ask-Bid;
return;
}
int start()
{
//====================================================================
total=OrdersTotal();
bl=0;
sl=0;
b=0;
s=0;
//---------------------------------------------------------------------
for (int i=total; i>=0; i--)
{
if (OrderSelect(i,SELECT_BY_POS)==true &&
OrderSymbol()==Symbol())
{
//---------------------------------------------------------------------
if (OrderType()==OP_BUY)
{
b =1;
Close_B(OrderTicket(),OrderLots());
}
//--------------------------------------------------------------------
if (OrderType()==OP_SELL)
{
s =1;
Close_S(OrderTicket(),OrderLots());
}
//-------------------------------------------------------------------
if (OrderType()==OP_BUYLIMIT)
{
OP_bl=NormalizeDouble(OrderOpenPrice(),Digits);
Nom_bl=OrderTicket();
bl=1;
}
//-------------------------------------------------------------------
if (OrderType()==OP_SELLLIMIT)
{
OP_sl=NormalizeDouble(OrderOpenPrice(),Digits);
Nom_sl=OrderTicket();
sl=1;
}
//------------------------------------------------------------------
}
}
//------------------------------------------------------------------
MA = iMA(NULL,0, period_MA, 0,MODE_LWMA, PRICE_TYPICAL, 0);
Open_order() ;
//==================================================================
return;
}
void Close_B(int Nomber, double lots)
{
if (NormalizeDouble(Bid-OrderOpenPrice(),Digits)>=cls)
{
OrderClose( Nomber, lots, Bid, 1, Yellow);
b = 0;
}
return;
}
void Close_S(int Nomber, double lots)
{
if (NormalizeDouble(OrderOpenPrice()-Ask,Digits)>=cls)
{
OrderClose( Nomber, lots, Ask, 1, Yellow);
s = 0;
}
return;
}
void Open_order()
{
if (b==0 && bl==0)
{
OP=MA-dist;
if(OP>Ask-Level) OP=Ask-Level;
OP=NormalizeDouble(OP,Digits);
OrderSend(Symbol(),OP_BUYLIMIT, Lots(),OP,3,OP-SL,OP+TP,"",0,0,Blue);// Open
bl=1;
}
if (s==0 && sl==0)
{
OP=MA+spred+dist;
if(OP<Bid+Level) OP=Bid+Level;
OP=NormalizeDouble(OP,Digits);
OrderSend(Symbol(),OP_SELLLIMIT,Lots(),OP,3,OP+SL,OP-TP,"",0,0,Red);
sl=1;
}
return;
}
double Lots()
{
Lot=0.1;
return(Lot);
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 219.81.196.201
如果要看 有語法亮度的版本,可到
http://groups.google.com/group/forex_base/web/%E8%81%96%E6%9D%AF+a1
※ 編輯: walking 來自: 219.81.196.201 (01/29 12:10)
推
01/29 12:13, , 1F
01/29 12:13, 1F
※ 編輯: walking 來自: 219.81.196.201 (01/29 12:20)
※ 編輯: walking 來自: 219.81.196.201 (01/29 12:23)
推
01/29 12:42, , 2F
01/29 12:42, 2F
→
01/29 17:38, , 3F
01/29 17:38, 3F
推
01/29 19:37, , 4F
01/29 19:37, 4F
→
01/30 00:08, , 5F
01/30 00:08, 5F
推
01/30 15:55, , 6F
01/30 15:55, 6F
→
01/30 21:59, , 7F
01/30 21:59, 7F
→
01/30 22:05, , 8F
01/30 22:05, 8F
→
01/30 22:06, , 9F
01/30 22:06, 9F
→
01/30 22:10, , 10F
01/30 22:10, 10F
→
01/30 22:13, , 11F
01/30 22:13, 11F
→
01/30 22:43, , 12F
01/30 22:43, 12F
→
01/30 23:09, , 13F
01/30 23:09, 13F
→
01/30 23:10, , 14F
01/30 23:10, 14F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):
Trading 近期熱門文章
57
160
PTT職涯區 即時熱門文章
167
281