|
|
本帖最后由 mancai 于 2-4-2010 09:44 AM 编辑
大家可以在这里分享,讨论,研发EA
我会把手头上的EA一一分享出来,只是找不到不会expired的上载空间
我只會寫一些非常簡單的EA,寫教學的確會笑死人
不過因爲我的分享,換來大家對我的真誠,EA都是cari的網友教我寫的
特別感謝my life my way 兄和其他在EA上對我給予指導的網友
icustom EA 教學 part 1
EA,template, indicators 下載點 (sample而已,別拿來用,包輸的)
http://www.savefile.com/files/1912577
打開裏面的mancai_EA_V3.mq4后會看到很長的code
首先是EA的parameter input
extern string Remark1 = "Use M15 TF chart";
extern bool UseMagicNumber = true;
extern int MagicNumber = 12345; (magic number,每一個pair都要放不一樣)
extern double TakeProfit = 10; (take profit 多少 pips)
extern double OrderLot = 0.1; (order的lot size)
extern int Slippage = 5;
extern int Spread = 0;
extern double StopLoss = 200.0; // in pips (stop loss 多少 pips)
extern double TrailingStop = 20; (trailing stop 多少 pips)
//extern double MinimumAccountBalance = 50;
buy和sell的 variable和condition
bool OpenBuySignal()
{
double rsi1 = iCustom(NULL, 0, "RSIs_mtf", 0, 14, 0, 0, 0, 2500, "a", "b", 0, 0);
double rsi_shifted1 = iCustom(NULL, 0, "RSIs_mtf", 0, 14, 0, 1, 0, 2500, "a", "b", 0, 1);
double macdValue1 = iCustom(NULL, 0, "MTF_MACD_inColor", 0, 5, 8, 9, 0, 3, 0);
//double macdValue1_op_shifted = iCustom(NULL, 0, "MTF_MACD_inColor", 0, 5, 8, 9, 0, 3, 1);
double macdValue1_norm = iCustom(NULL, 0, "MTF_MACD_inColor", 0, 5, 8, 9, 0, 0, 0);
double macdValue1_shifted = iCustom(NULL, 0, "MTF_MACD_inColor", 0, 5, 8, 9, 0, 0, 1);
double fxtrend1 = iCustom(NULL, 0, "Forex_Trend", 23, 0, 0);
double fxtrend1_shifted = iCustom(NULL, 0, "Forex_Trend", 23, 0, 1);
double flattr1 = iCustom(NULL, 0, "FLATTR",0, 5, 8, 9, 10000, 1, 0);
double fractal1 = iCustom(NULL, 0, "FractalVolty_v1", 1, 1, 1, 0, 0);
double macdx1_h4 = iCustom(NULL, 0, "#MTF_MACD X_H4", 5, 8, 0, 0);
if (rsi_shifted1 < rsi1 && macdValue1 == 0 && macdValue1_norm > macdValue1_shifted && fxtrend1 < 0.2 && fxtrend1 > fxtrend1_shifted && flattr1 == 1 && fractal1 > 0.001 && macdx1_h4 == 0)
{
return (true);
}else{
return (false);
}
}
bool OpenSellSignal()
{
double rsi2 = iCustom(NULL, 0, "RSIs_mtf", 0, 14, 0, 0, 0, 2500, "a", "b", 0, 0);
double rsi_shifted2 = iCustom(NULL, 0, "RSIs_mtf", 0, 14, 0, 1, 0, 2500, "a", "b", 0, 1);
double macdValue2 = iCustom(NULL, 0, "MTF_MACD_inColor", 0, 5, 8, 9, 0, 2, 0);
//double macdValue2_op_shifted = iCustom(NULL, 0, "MTF_MACD_inColor", 0, 5, 8, 9, 0, 2, 1);
double macdValue2_norm = iCustom(NULL, 0, "MTF_MACD_inColor", 0, 5, 8, 9, 0, 0, 0);
double macdValue2_shifted = iCustom(NULL, 0, "MTF_MACD_inColor", 0, 5, 8, 9, 0, 0, 1);
double fxtrend2 = iCustom(NULL, 0, "Forex_Trend", 23, 0, 0);
double fxtrend2_shifted = iCustom(NULL, 0, "Forex_Trend", 23, 0, 1);
double flattr2 = iCustom(NULL, 0, "FLATTR", 0, 5, 8, 9, 10000, 0, 0);
double fractal2 = iCustom(NULL, 0, "FractalVolty_v1", 1, 1, 1, 0, 0);
double macdx2_h4 = iCustom(NULL, 0, "#MTF_MACD X_H4", 5, 8, 1, 0);
if (rsi_shifted2 > rsi2 && macdValue2 == 0 && macdValue2_norm < macdValue2_shifted && fxtrend2 > -0.2 && fxtrend2_shifted > fxtrend2 && flattr2 == 1 && fractal2 > 0.001 && macdx2_h4 == 0)
{
return (true);
}else{
return (false);
}
}
buy和sell的close order condition
bool CloseBuySignal()
{
double macdValue2_m30 = iCustom(NULL, 0, "MTF_MACD_inColor", 30, 5, 8, 9, 0, 2, 0);
if (macdValue2_m30 == 0)
{
return (true);
}else{
return (false);
}
}
bool CloseSellSignal()
{
double macdValue1_m30 = iCustom(NULL, 0, "MTF_MACD_inColor", 30, 5, 8, 9, 0, 3, 0);
if (macdValue1_m30 == 0)
{
return (true);
}else{
return (false);
}
}
[ 本帖最后由 mancai 于 19-12-2008 06:38 PM 编辑 ] |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 1-12-2008 04:56 PM
|
显示全部楼层
icustom EA 教學 part 2
怎樣寫buy & sell的 variable 和 condition?
我選幾個sample:
flattr indicator buy variable
double flattr1 = iCustom(NULL, 0, "FLATTR",0, 5, 8, 9, 10000, 1, 0);
flattr indicator sell variable
double flattr1 = iCustom(NULL, 0, "FLATTR",0, 5, 8, 9, 10000, 0, 0);
第一個參數代表使用的currency symbol,NULL就是當前的currency symbol
第二個參數代表timeframe,0就是當前的timeframe
第三個參數代表custom indicator的名
第4和5是custom indicator的parameter,你可以從indicator的properties找到它有多少paramaters,parameter可以有很多個,所以這是應indicator而異。在這里0時indicator本身的當前timeframe,5是fast ema,8就是slow ema,9是macd MA, 10000是count bar。
最后第二個就是重點,這是注明你要讀取indicator的那一個value,一個custom indicator可以有8個buffer,所以說最多能有8個value可以選取來讀。value是從0至7。待會我會教如何找indicator的value。
最后一個就是選擇Bar,value 0就是當前的bar,即是最右邊那個,如果value是1的話就表示最右邊的第二個bar(shifted 1 bar)。
如何找indicator本身的的parameter呢?

double click你的indicator,去input那裏,有多少就放進去我highlight藍色的字裏面,它可以是數字,可以是true/false,也可以是一些remark,如果是remark可以用" "這個符號,裏面雖便填寫就可以了。
所以這個indicator的input parameter是0,5,8,9,10000。
如何找buy or sell的value?

建議一個一個attach進去chart裏看,因爲有些system幾個indicator mix在一個windows裏面,會很亂的。
然後用mouse指向你要寫得indicator,好像下面的圖,我要藍色買,紅色賣,黃色不做任何東西。

記住第一個是value = 0, 接下來是 1,2,3... 不是你所看到的一開始就是indicator 名字,然後直接2。
confirm value后就填在紫色的地方。
buy or sell的condition怎樣寫?
其實這個很個人的,比如我這樣寫
if (rsi_shifted1 < rsi1 && macdValue1 == 0 && macdValue1_norm > macdValue1_shifted && fxtrend1 < 0.2 && fxtrend1 > fxtrend1_shifted && flattr1 == 1 && fractal1 > 0.001 && macdx1_h4 == 0)
&& 是 and
|| 是 or
< 是 小過
> 是 大過
== 是 等於
我這樣寫是要 rsi shifted一個bar的要小過現在的rsi 和 MTF macd == 0 (藍色bar時) 和 MTF macd 現在的value要大過已經shifted一個bar的MTF macd 和 forextrend要大過0.2 和 forextrend現在的value要大過forextrend shifted一個bar的 和
flattr藍色 和 fractall 要 大過0.001 和 macdx藍色
buy和sell的close order condition
bool CloseBuySignal()
{
double macdValue2_m30 = iCustom(NULL, 0, "MTF_MACD_inColor", 30, 5, 8, 9, 0, 2, 0);
if (macdValue2_m30 == 0)
{
return (true);
}else{
return (false);
}
}
我這樣寫是因爲要一旦MTF macd M30紅色時就立刻close order。
=================================================================================
其實大家可以把全部variable列出來后,然後直接寫buy sell condition
我分開寫,有些buy有了,sell又出現,其實可以不用再寫的,只是我怕會亂才隨便給一個variable名字分開來寫的。
那些什麽在double后的rsi_shifted,macd_value1什麽的,自己可以define,但condition一定要用一樣的名字。
写完了compile没有error就可以开始backtest看performance了,如果EA不能开order或不能跑,可以在tester strategy那边的journal看看有什么error。
希望大家看得明白,可以做些簡單的EA來玩玩,我的料只有那麽多而已
會更多時再update大家,還有,如有教錯請糾正我
[ 本帖最后由 mancai 于 3-12-2008 07:44 AM 编辑 ] |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 1-12-2008 04:57 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 1-12-2008 04:58 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 1-12-2008 04:58 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 1-12-2008 04:58 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 1-12-2008 04:59 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 1-12-2008 04:59 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 1-12-2008 05:00 PM
|
显示全部楼层
|
请别按报告,因为EA需要分catagory,所以保留一些空间。 |
|
|
|
|
|
|
|
|
|
|
发表于 1-12-2008 09:27 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|
发表于 1-12-2008 09:42 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|
发表于 1-12-2008 09:52 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|
发表于 1-12-2008 11:36 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|
发表于 2-12-2008 12:27 PM
|
显示全部楼层
原帖由 mancai 于 1-12-2008 04:50 PM 发表 
大家可以在这里分享,讨论,研发EA
我会把手头上的EA一一分享出来,只是找不到不会expired的上载空间
用geocities之类的free hosting应该不会expired,但是有bandwith limitation.
geocities是每小时4mb。。。 |
|
|
|
|
|
|
|
|
|
|
发表于 2-12-2008 12:54 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|
发表于 2-12-2008 01:00 PM
|
显示全部楼层
好贴!
等待楼主更新你们最近测试的好东西。暂时我只是玩到merdekarama罢了。
节约空间,就在这里问。请问我参rojak的话会不会破坏其他的ea?
[ 本帖最后由 gn02305657 于 2-12-2008 01:02 PM 编辑 ] |
|
|
|
|
|
|
|
|
|
|
发表于 2-12-2008 01:22 PM
|
显示全部楼层
mancai兄开的必是好贴
本人就比较少用EA啦
manual至少在亏钱时只可以怨自己  |
|
|
|
|
|
|
|
|
|
|
发表于 2-12-2008 01:34 PM
|
显示全部楼层
|
谢谢大大的分享,在下感谢不尽,希望有机会和你会一会面 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 2-12-2008 01:40 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|
发表于 3-12-2008 12:47 AM
|
显示全部楼层
多謝你的教學,目前我在研究CodersGuruFullCourse的教學檔
希望可以自己寫出一個會發出alert的indicator
希望不會太難 |
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|