MT人工智能之三(EMA交叉趋势跟踪系统)
均线趋势跟踪系统的设计例子
/*[[
Name := EMA Cross + Filters
Author := hapsa, most of the codes are taken from Ivan_MA :)
Notes := Basic MA Cross + ATR, RSI, WPR Filters
Notes := Default settings for EURUSD, GBPUSD, USDCHF 30 Min
Notes := Play around! :)
Lots := 1.00
Stop Loss := 35
Take Profit := 90
Trailing Stop := 20
]]*/
DEFINES : Slippage(5), PLAY%(5), Money_M(0), PartialLots(1), Limit(500), FastPeriod(5), SlowPeriod(20);
Variable : iMASlowPrevious(0), iMaSlowCurrent(0), iMaFastPrevious(0), iMaFastCurrent(0);
Variable : Filter_WPR(0), Filter_ABS(0), Filter_ATR(0), Filter_RSI(0);
Variable : cnt(0), ILO(0), mode(0);
If Money_M <> 0 then
{
Ilo= ceil(equity*PLAY%/100/100)/10;
IF PartialLots = 0 then
{
If Ilo < 1 then Ilo = 1;
If Ilo > 1 then Ilo= ceil(ilo);
}
}
else
ilo = lots;
//Moving Average Settings
iMaSlowPrevious = iMAEx(SlowPeriod, MODE_EMA, 0, PRICE_CLOSE, 1);
iMaSlowCurrent = iMAEx(SlowPeriod, MODE_EMA, 0, PRICE_CLOSE, 0);
iMaFastPrevious = iMAEx(FastPeriod, MODE_EMA, 0, PRICE_CLOSE, 1);
iMaFastCurrent = iMAEx(FastPeriod, MODE_EMA, 0, PRICE_CLOSE, 0);
//Filters Settings
Filter_ATR = iATR(26,0);
Filter_RSI = iRSI(14,0);
Filter_WPR = iWPR(14,0);
Filter_ABS = ABS(Filter_WPR);
If TotalTrades<1 then
{
If FreeMargin<Limit then Exit;
// Long Entry Rules
If iMaFastPrevious<iMaSlowPrevious and iMaFastCurrent>iMASlowCurrent and Filter_ABS<25 and Filter_ATR>0.0013 and Filter_RSI>64 Then
{
SetOrder(OP_BUY,ilo,Ask,Slippage,Ask-stoploss*Point,Ask+TakeProfit*Point,BLUE);
Exit;
};
// Short Entry Rules
If iMaFastPrevious>iMaSlowPrevious and iMaFastCurrent<iMASlowCurrent and Filter_ABS>75 and Filter_ATR>0.0013 and Filter_RSI<36 Then
{
SetOrder(OP_SELL,ilo,Bid,Slippage,Bid+stoploss*Point,Bid-TakeProfit*Point,RED);
Exit;
};
Exit;
};
For cnt=1 to TotalTrades
{
mode=OrderValue(cnt,VAL_TYPE);
If mode=OP_BUY then
{
If iMaFastPrevious>iMaSlowPrevious and iMaFastCurrent<iMASlowCurrent then
{
CloseOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_LOTS),Bid,Slippage,Orange);
Exit;
};
};
If mode=OP_SELL then
{
If iMaFastPrevious<iMaSlowPrevious and iMaFastCurrent>iMASlowCurrent then
{
CloseOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_LOTS),Ask,Slippage,RED);
Exit;
};
};
};
For cnt=1 to TotalTrades
{
If Ord(cnt,VAL_TYPE)=OP_BUY then
{
If (Bid-Ord(cnt,VAL_OPENPRICE))>(TrailingStop*Point) then
{
If Ord(cnt,VAL_STOPLOSS)<(Bid-TrailingStop*Point) then
{
ModifyOrder(Ord(cnt,VAL_TICKET),Ord(cnt,VAL_OPENPRICE),Bid-TrailingStop*Point,Ord(cnt,VAL_TAKEPROFIT),BLUE);
Exit;
};
};
};
If Ord(cnt,VAL_TYPE)=OP_SELL then
{
If (Ord(cnt,VAL_OPENPRICE)-Ask)>(TrailingStop*Point) then
{
If Ord(cnt,VAL_STOPLOSS)>(Ask+TrailingStop*Point) or Ord(cnt,VAL_STOPLOSS)=0 then
{
ModifyOrder(Ord(cnt,VAL_TICKET),Ord(cnt,VAL_OPENPRICE),Ask+TrailingStop*Point,Ord(cnt,VAL_TAKEPROFIT),Red);
Exit;
};
};
};
};
[此帖子已被 hilow 在 2004-9-27 2:46:31 编辑过]
[ Last edited by 老正 on 2005-2-2 at 18:42 ]
发表于:2004-09-27 03:35只看该作者
2楼
好,仔细琢磨后再请教!
发表于:2005-02-01 08:27只看该作者
3楼
在 mt 中 如何表示 2条均线的交叉呢 飞狐中的 cross 函数
发表于:2005-02-02 06:46只看该作者
4楼
8错
发表于:2005-02-03 08:37只看该作者
5楼
请修改后重新发
代码中 好多乱码呀!?
发表于:2005-02-03 09:13只看该作者
6楼
很多错误
发表于:2005-02-04 14:41只看该作者
7楼
Originally posted by 北客 at 2005-2-3 16:37 请修改后重新发 代码中 好多乱码呀!?
韬客社区www.talkfx.co