下载MetaTrader 5
要添加评论,请登录注册
您已开发一个交易机器人吗?在市场中发布它并获利!
norland
11
norland 2010.11.29 16:02 

#property copyright "Copyright ?2010, fx198 Software Corp."
#property link "http://fx198.co.cc/"

#include <stdlib.mqh>
#include <WinUser32.mqh>

extern int Slip = 60;
extern double Lots = 0.1;
extern double g_lots_108 = 0.1;
extern int Ma = 25;
extern int Ma1 = 6;
extern int Ma2 = 14;
int g_cmd_96;
int g_ticket_100;
int gi_104 = 0;
double va_101;


int start() {
if (gi_104 == Time[0]) return (0);
int li_0 = GetHoldingOrderCnt();
int expiration=TimeCurrent( )+60*9;
double l_ima_4 = iMA(NULL, 0, Ma, 0, MODE_EMA, PRICE_CLOSE, 1);
if (li_0 <= 0) {

if (YesOrNo(0)) {
g_ticket_100 = OrderSend(Symbol(), OP_BUYLIMIT, g_lots_108, l_ima_4 + 10 * Point, Slip, l_ima_4 - 15 * Point, 0, "", 54321, expiration, Green);
if (g_ticket_100 > 0) {
if (OrderSelect(g_ticket_100, SELECT_BY_TICKET, MODE_TRADES)) Print("BUY order opened : ", OrderOpenPrice());
} else Print("Error opening BUY order : ", GetLastError());
}
if (YesOrNo(1)) {
g_ticket_100 = OrderSend(Symbol(), OP_SELLLIMIT, g_lots_108, l_ima_4 - 10 * Point, Slip, l_ima_4 + 15 * Point, 0, "", 54321, expiration, Green);
if (g_ticket_100 > 0) {
if (OrderSelect(g_ticket_100, SELECT_BY_TICKET, MODE_TRADES)) Print("SELL order opened : ", OrderOpenPrice());
} else Print("Error opening SELL order : ", GetLastError());
}
} else {
if (g_cmd_96 == OP_BUY) {
if (CloseYorN(0)) OrderClose(OrderTicket(), OrderLots(), Bid, Slip, Violet);
else {
if (iMA(NULL, 0, Ma, 0, MODE_EMA, PRICE_CLOSE, 1) > OrderStopLoss() + 30.0 * Point) OrderModify(OrderTicket(), OrderOpenPrice(), iMA(NULL, 0, Ma, 0, MODE_EMA, PRICE_CLOSE, 1) - 25.0 * Point, 0, 0, Green);
else return (0);
}
}
if (g_cmd_96 == OP_SELL) {
if (CloseYorN(1)) {
Print(">>>>");
OrderClose(OrderTicket(), OrderLots(), Ask, Slip, Violet);
Print("<<<<");
} else {
if (iMA(NULL, 0, Ma, 0, MODE_EMA, PRICE_CLOSE, 1) < OrderStopLoss() - 30.0 * Point) OrderModify(OrderTicket(), OrderOpenPrice(), iMA(NULL, 0, Ma, 0, MODE_EMA, PRICE_CLOSE, 1) + 25.0 * Point, 0, 0, Green);
else return (0);
}
}
return (0);
}
gi_104 = Time[0];
return (0);
}

int GetHoldingOrderCnt() {
int l_count_0 = 0;
for (int l_pos_4 = 0; l_pos_4 < OrdersTotal(); l_pos_4++) {
OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() == Symbol() && OrderMagicNumber() == 54321) {
l_count_0++;
g_cmd_96 = OrderType();
}
}
return (l_count_0);
}

bool YesOrNo(int ai_0) {
double l_ima_4 = iMA(NULL, 0, Ma, 0, MODE_EMA, PRICE_CLOSE, 1);
double l_ima_12 = iMA(NULL, 0, Ma1, 0, MODE_EMA, PRICE_CLOSE, 2);
double l_imacd_20 = iMACD(NULL, 0, 12, 26, 9, PRICE_CLOSE, MODE_MAIN, 0);
double l_imacd_28 = iMACD(NULL, 0, 12, 26, 9, PRICE_CLOSE, MODE_MAIN, 1);
switch (ai_0) {
case 0:
if (l_ima_4 - l_ima_12 == 0.0001) return (TRUE);
return (FALSE);
case 1:
if (l_ima_12 - l_ima_4 == 0.0001) return (TRUE);
return (FALSE);
}
return (FALSE);
}

bool CloseYorN(int ai_0) {
double l_imacd_4 = iMACD(NULL, 0, 12, 26, 9, PRICE_CLOSE, MODE_MAIN, 1);
double l_imacd_12 = iMACD(NULL, 0, 12, 26, 9, PRICE_CLOSE, MODE_MAIN, 2);
double l_imacd_20 = iMACD(NULL, 0, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 1);
double l_imacd_28 = iMACD(NULL, 0, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 2);
switch (ai_0) {
case 0:
if (l_imacd_4 - l_imacd_20 == 0) return (TRUE);
return (FALSE);
case 1:
if (Close[1] - iMA(NULL, 0, Ma, 0, MODE_EMA, PRICE_CLOSE, 0) == va_101) return (TRUE);
return (FALSE);
}
return (FALSE);
}

xpsandy
20
xpsandy 2010.11.30 10:19  

把后面CASE里的==改成>=看看

一般很少有完全等于的数值

norland
11
norland 2010.11.30 14:26  

终于有结果,真是太感谢了

具体的参数和条件还需要调整,目前测试结果还不是太理想

/
要添加评论,请登录注册