|
我的多货币的均线共振ea已经基本完成 还有最后一个问题 有时间请看看!
按照我的策略 如果符合条件应该四个货币对 每个开一个单子,我的ea不知为何只开三个单子 我设定的是四个货币对每个开一个
eu gu uc 都开了 就是uj不开仓
代码结构都是一样的
//+------------------------------------------------------------------+
//| Designed by AAA, China |
//| Copyright 2007, OKwh & Dxdcn & AAA |
//| THIS EA IS reworded by rosh'indicator |
//+------------------------------------------------------------------+
#property copyright "Copyright 2007,AAA, China."
#property link "http"
#define MAGICMA 200810011231
//+------------------------------------------------------------------+
//| 策略: 在15分钟周期下 eu gu 1周期均线在60周期均线下方 且uc uj的1周期均线在60均线上方|
//| eu gu uc uj 每个货币对顺势开一个仓,同时设置止损、只赢 |
//| 四个条件都不满足 平仓离场 |
//+------------------------------------------------------------------+
//
extern double TakeProfit = 100; //止赢点数
extern double StopLoss = 60; //止损点数
extern double TrailingStop =40; //跟踪止赢点数设置
extern int maxOpen = 4; //最多开仓次数限制
//extern int bb = 0; //非零就允许跟踪止赢
//
extern double lots=0.1; //一次下单手数
int i, p2, xxx,p1, res1,res2,res3,res4; //时间控制, 仅当一个时间周期完成才检查条件
int buyeu=0,selleu=0,buygu=0,sellgu=0,buyuc=0,selluc=0,buyuj=0,selluj=0;
int init() //初始化
{
return(0);
}
int deinit() { return(0); } //反初始化
//主程序
int start()
{
CheckForOpen(); //开仓 平仓 条件检查 和操作
//if (bb>0) CTP(); //跟踪止赢
return(0);
}
//+------下面是各子程序--------------------------------------------+
//平仓持有的买单、、先结束买肥美
void CloseBuy()
{
double Bideu =MarketInfo("EURUSD",MODE_BID);
double Askeu =MarketInfo("EURUSD",MODE_ASK);
//
double Bidgu =MarketInfo("GBPUSD",MODE_BID);
double Askgu =MarketInfo("GBPUSD",MODE_ASK);
//
double Biduc =MarketInfo("USDCHF",MODE_BID);
double Askuc =MarketInfo("USDCHF",MODE_ASK);
//
double Biduj =MarketInfo("USDJPY",MODE_BID);
double Askuj =MarketInfo("USDJPY",MODE_ASK);
if (OrdersTotal( ) > 0 )
{
for(i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderMagicNumber()==MAGICMA+1)
{
OrderClose(OrderTicket(),OrderLots(),Bideu,4,White);
}
if(OrderMagicNumber()==MAGICMA+2)
{
OrderClose(OrderTicket(),OrderLots(),Bidgu,4,White);
}
if(OrderMagicNumber()==MAGICMA+3)
{
OrderClose(OrderTicket(),OrderLots(),Askuc,4,White);
}
if(OrderMagicNumber()==MAGICMA+4)
{
OrderClose(OrderTicket(),OrderLots(),Askuj,4,White);
}
if(OrderMagicNumber()==MAGICMA+5) //已开eu空仓
{
selleu=1; //标记
}
if(OrderMagicNumber()==MAGICMA+6) //已开gu空仓
{
sellgu=1;
}
if(OrderMagicNumber()==MAGICMA+7) //已开uc多仓
{
buyuc=1;
}
if(OrderMagicNumber()==MAGICMA+8) //已开uj多仓
{
buyuj=1;
}
}
}
}
//平仓持有的卖单、、先结束卖肥美
void CloseSell()
{
double Bideu =MarketInfo("EURUSD",MODE_BID);
double Askeu =MarketInfo("EURUSD",MODE_ASK);
//
double Bidgu =MarketInfo("GBPUSD",MODE_BID);
double Askgu =MarketInfo("GBPUSD",MODE_ASK);
//
double Biduc =MarketInfo("USDCHF",MODE_BID);
double Askuc =MarketInfo("USDCHF",MODE_ASK);
//
double Biduj =MarketInfo("USDJPY",MODE_BID);
double Askuj =MarketInfo("USDJPY",MODE_ASK);
if (OrdersTotal( ) > 0 )
{
for(i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderMagicNumber()==MAGICMA+5)
{
OrderClose(OrderTicket(),OrderLots(),Askeu,4,White);
}
if(OrderMagicNumber()==MAGICMA+6)
{
OrderClose(OrderTicket(),OrderLots(),Askgu,4,White);
}
if(OrderMagicNumber()==MAGICMA+7)
{
OrderClose(OrderTicket(),OrderLots(),Biduc,4,White);
}
if(OrderMagicNumber()==MAGICMA+8)
{
OrderClose(OrderTicket(),OrderLots(),Biduj,4,White);
}
if(OrderMagicNumber()==MAGICMA+1) //已开eu多仓
{
buyeu=1; //标记
}
if(OrderMagicNumber()==MAGICMA+2) //已开gu多仓
{
buygu=1;
}
if(OrderMagicNumber()==MAGICMA+3) //已开uc空仓
{
selluc=1;
}
if(OrderMagicNumber()==MAGICMA+4) //已开uj空仓
{
selluj=1;
}
}
}
}
//判断是否买或卖或平仓
int buyorsell() //在这个函数计算设置你的交易信号
{
double easyeu11,easyeu21,easygu11,easygu21,easyuc11,easyuc21,easyuj11,easyuj21;
//
easyeu11=iMA("EURUSD",PERIOD_M15,1,0,MODE_SMA,PRICE_TYPICAL,0);
easyeu21=iMA("EURUSD",PERIOD_M15,60,0,MODE_SMA,PRICE_TYPICAL,0);
easygu11=iMA("GBPUSD",PERIOD_M15,1,0,MODE_SMA,PRICE_TYPICAL,0);
easygu21=iMA("GBPUSD",PERIOD_M15,60,0,MODE_SMA,PRICE_TYPICAL,0);
easyuc11=iMA("USDCHF",PERIOD_M15,1,0,MODE_SMA,PRICE_TYPICAL,0);
easyuc21=iMA("USDCHF",PERIOD_M15,60,0,MODE_SMA,PRICE_TYPICAL,0);
easyuj11=iMA("USDJPY",PERIOD_M15,1,0,MODE_SMA,PRICE_TYPICAL,0);
easyuj21=iMA("USDJPY",PERIOD_M15,60,0,MODE_SMA,PRICE_TYPICAL,0);
Print(easyeu11,"-01-",easyeu21,"-02-",easygu11,"-03-",easygu21,"-04-",easyuc11,"-05-",easyuc21,"-06-",easyuj11,"-07-",easyuj21,"-08-");
if(easyeu21<easyeu11 && easygu21<easygu11 && easyuc11<easyuc21 && easyuj11<easyuj21 )
return (1); // 买肥美SELL USD
if( easyeu21>easyeu11 && easygu21>easygu11 && easyuc11>easyuc21 && easyuj11>easyuj21 )
return (-1); // 卖肥美 BUY USD
//
return (0); //不交易 NO ANY OPENNING
}
int nowbuyorsell = 0;
void CheckForOpen()
{
//if (Time[0] == lasttime ) return; //每时间周期检查一次 时间控制
//lasttime = Time[0];
nowbuyorsell = buyorsell(); //获取买卖信号
if (nowbuyorsell == 1) //买 先结束卖肥美 CLOSE BUY USD
CloseSell();
if (nowbuyorsell == -1) //卖 先结束买肥美 CLOSE SELL USD
CloseBuy();
if (OrdersTotal( ) > maxOpen) return ;
//如果已持有开仓次数达到最大,不做
if (nowbuyorsell==0) return; //不交易
TradeOK(); //去下单交易
}
void TradeOK() //去下单交易
{
//int error ;
double Bideu =MarketInfo("EURUSD",MODE_BID);
double Askeu =MarketInfo("EURUSD",MODE_ASK);
//
double Bidgu =MarketInfo("GBPUSD",MODE_BID);
double Askgu =MarketInfo("GBPUSD",MODE_ASK);
//
double Biduc =MarketInfo("USDCHF",MODE_BID);
double Askuc =MarketInfo("USDCHF",MODE_ASK);
//
double Biduj =MarketInfo("USDJPY",MODE_BID);
double Askuj =MarketInfo("USDJPY",MODE_ASK);
//
//
if (nowbuyorsell == 1) //买肥美 SELL USD
{
if (buyeu != 1 )
{
res1=OrderSend("EURUSD",OP_BUY,lots,Askeu,4,Askeu-StopLoss*Point,Askeu+TakeProfit*Point,"",MAGICMA+1,0,Blue); Sleep(5000);
}
if (buygu != 1 )
{
res2=OrderSend("GBPUSD",OP_BUY,lots,Askgu,4,Askgu-StopLoss*Point,Askgu+TakeProfit*Point,"",MAGICMA+2,0,Blue); Sleep(5000);
}
if ( selluc != 1)
{
res3=OrderSend("USDCHF",OP_SELL,lots,Biduc,4,Biduc+StopLoss*Point,Biduc-TakeProfit*Point,"",MAGICMA+3,0,Blue); Sleep(5000);
}
if ( selluj != 1)
{
res4=OrderSend("USDJPY",OP_SELL,lots,Biduj,4,Biduj+StopLoss*Point,Biduj-TakeProfit*Point,"",MAGICMA+4,0,Blue); Sleep(5000);
}
Print(" 买肥美short USD ",res1,res2,res3,res4);
//Sleep(5000);
return ;
}
if (nowbuyorsell == -1) //卖肥美 BUY USD
{
if (selleu != 1 && (iMA("EURUSD",PERIOD_M15,60,0,MODE_SMA,PRICE_TYPICAL,0))<= Bideu+20*Point)
{
res1=OrderSend("EURUSD",OP_SELL,lots,Bideu,4,Bideu+StopLoss*Point,Bideu-TakeProfit*Point,"",MAGICMA+5,0,Blue); Sleep(5000);
}
if (sellgu != 1)
{
res2=OrderSend("GBPUSD",OP_SELL,lots,Bidgu,4,Bidgu+StopLoss*Point,Bidgu-TakeProfit*Point,"",MAGICMA+6,0,Blue); Sleep(5000);
}
if (buyuc != 1)
{
res3=OrderSend("USDCHF",OP_BUY,lots,Askuc,4,Askuc-StopLoss*Point,Askuc+TakeProfit*Point,"",MAGICMA+7,0,Blue); Sleep(5000);
}
if (buyuj != 1)
{
res4=OrderSend("USDJPY",OP_BUY,lots,Askuj,4,Askuj-StopLoss*Point,Askuj+TakeProfit*Point,"",MAGICMA+8,0,Blue); Sleep(5000);
}
Print(" 卖肥美long USD ",res1,res2,res3,res4);
//Sleep(5000);
return ;
}
}
|
|