.[EA]一分钟下的G/U相关利差的

.[EA]一分钟下的G/U相关利差的 2010-05-13 11:50:52| 分类: 默认分类 | 标签: |字号大中小 订阅 .

//[EA]一分钟下的Spreader_v2.
//译后感觉:此EA为做G/U与相关货币的套利 ,取值正负值为学习收获

extern string HuoBi = "GBPUSD"; //货币对名称
extern double Lots = 1; //手数
extern double Profit = 100; //赢利目标

static int PrevTime = 0; //前一时间
static bool OpenBarsPriceOnly = true; //参数 判断
static int period = 30; //周期

//+------------------------------------------------------------------+

int init()
{
PrevTime = Time[0];
return(0);
}

//+------------------------------------------------------------------+

int deinit()
{
return(0);
}

//+------------------------------------------------------------------+

int start()
{
if (Period() != PERIOD_M1)
{
Alert("请改变时间框" + Symbol() + " 到一分钟!"); //提示必须使用一分钟图
return(0);
}

if ((Time[0] == PrevTime) && OpenBarsPriceOnly)
{
return(0);
}


PrevTime = Time[0]; //赋值给前一时间为 当前时间

int total = OrdersTotal(); //单总数
int currentticket = -1; //当前替克
int secondticket = -1; //第二替克

int currenttype = OP_SELL; //当前类型
int secondtype = OP_BUY; //第二类型

double currentprofit = 0; //当前赢利
double secondlots = 0; //第二手数

for (int i = 0; i < total; i++) //按单总数循环查找
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES); //选择交易中的订单
if (OrderSymbol() == Symbol()) //如果是当前货币对
{
currentticket = OrderTicket(); //赋值
currentprofit = currentprofit + OrderProfit(); //赋值
currenttype = OrderType(); //赋值
}
if (OrderSymbol() == HuoBi) //如果当前货币对为G/U
{
secondticket = OrderTicket(); //赋值
secondtype = OrderType(); //赋值
currentprofit = currentprofit + OrderProfit(); //赋值
secondlots = OrderLots(); //赋值
}
}



if ((secondticket < 0) && (currentticket >= 0)) //如果G/U替克<0 且当前货币对替克>=0
{
Comment("尝试平仓 " + Symbol()); //图表显示(试关掉位置在当前货币对)
if (currenttype == OP_BUY) //如果G/U类型为 买单
{
if (OrderClose(currentticket, Lots, Bid, 2, Blue)) //平仓当前货币对
{
OpenBarsPriceOnly = true; //将参数 赋为真
}
return(0); //返回
}
else //否则
{
if (OrderClose(currentticket, Lots, Ask, 2, Red)) //如果平仓成功
{
OpenBarsPriceOnly = true; //则将参数 为真
}
return(0);
}
}




if ((secondticket >= 0) && (currentticket >= 0)) //如果G/U替克>=0 且当前货币对替克也>=0
{
OpenBarsPriceOnly = false; //将参数 为假
if (currentprofit > Profit) //如果当前货币对替克>赢利目标
{
if (secondtype == OP_BUY) //如果G/U类型为买单
{
OrderClose(secondticket, //则平仓G/U
secondlots,
MarketInfo(HuoBi, MODE_BID),
2,
Blue);
return(0); //返回
}
else //否则平仓G/U的卖单
{
OrderClose(secondticket,
secondlots,
MarketInfo(HuoBi, MODE_ASK),
2,
Red);
return(0); //返回
}
}

Comment("定位为 " +Symbol() +" 且" +HuoBi +"是开仓的.\n赢利总额: $" +currentprofit); //窗口信息显示
return(0);
}

OpenBarsPriceOnly = true; //将参数 为真



if ((secondticket >= 0) && (currentticket < 0)) //如果G/U替克>=0 且当前货币对替克<0
{
Comment("尝试开仓" + Symbol()); //图表显示
if (secondtype == OP_SELL) //如果G/U类型为卖单
{
currentticket = OrderSend(Symbol(), //当前货币对替克为 发送订单买
OP_BUY,
Lots,
Ask,
2,
0,
0,
WindowExpertName(), // ?未解)
0,
0,
Blue);
}
else //否则
{
currentticket = OrderSend(Symbol(), //当前货币对替克为 发送计单卖
OP_SELL,
Lots,
Bid,
2,
0,
0,
WindowExpertName(),
0,
0,
Red);
}
return(0);
}

if (MarketInfo(Symbol(), MODE_LOTSIZE) != MarketInfo(HuoBi, MODE_LOTSIZE)) //如果市场规定的手数大小与G/U的手数大小不一致
{
Alert("Contracts size not equals. Change instruments"); //报警(合约大小不足,请更换?)
return(0);
}



double x1 = Close[0] - Close[period]; //定义X1 并赋值为 当前货币对的现在最新价-周期参数前的收盘价 (注意值有正负之分)
double x2 = Close[period] - Close[period * 2]; //定义X2 并赋值为 当前货币对的周期参数前的收盘价-双倍周期参数前的收盘价
double y1 = iClose(HuoBi, Period(), 0) - iClose(HuoBi, Period(), period); //定义Y1 并赋值为 G/U当前当前周期框值-当前时间框的参数前的值 (注意Period()和period不是一回事)
double y2 = iClose(HuoBi, Period(), period) - iClose(HuoBi, Period(), period * 2); //定义Y2 并赋值为 G/U当前时间框的参数平移值-双倍参数平移值


if ((x1 * x2) > 0) //如果当前货币对的两差相乘为正
{
Comment(Symbol() + " 趋势已找到"); //图表提示(发现趋势)
return(0); //返回
}

if ((y1 * y2) > 0) //如果G/U两差相乘为正值
{
Comment(HuoBi + " 趋势已发现"); //图表提示(发现趋势)
return(0); //返回
}


if ((x1 * y1) > 0) //如果当前货币对差值与G/U差值相乘为正值
{
double a = MathAbs(x1) + MathAbs(x2); //定义a 并赋值为 当前货币对两个差值的绝对值(距离)相加
double b = MathAbs(y1) + MathAbs(y2); //定义b 并赋值为 G/U的两个差值的绝对值相加

if ((a / b) > 3.0) return(0); //如果当前货币对的两段距离之和 除以 G/U的两段距离之和 大于3,则返回
if ((a / b) < 0.3) return(0); //如果当前货币对的两段距离之和 除以 G/U的两段距离之和 小于3.3,则返回

secondlots = NormalizeDouble(a * Lots / b, 2); //G/U使用手数初赋值为 参数手数乘以 a/b的两位小数精确化

double x3 = Close[0] - Close[1440]; //定义X3 并赋值为 当前货币对最新价-昨天的此时收盘价 (因必须使用一分钟图,把以参数为1440)
double y3 = iClose(HuoBi, Period(), 0) - iClose(HuoBi, Period(), 1440); //定义y3 并赋值为 G/U当前时间框的参数平移值-昨天平移值的收盘价

if ((x1 * b) > (y1 * a)) //如果当前货币对的短期差值乘以G/U的两段距之和 > G/U短期差值乘以当前货币对的两段距离之和
{
if ((x3 * b) < (y3 * a)) //并且如果当前货币对的日线差乘以G/U两段距之和 < G/U日线差乘以当前货币对两段距之和
{
Comment("False testimony"); //提示(失效证据)
return(0); //返回
}
currenttype = OP_BUY; //当前货币对类弄赋为 买单
}
else //否则
{
if ((x3 * b) > (y3 * a)) //如果当前货币对的日线差乘以G/U两段距之和 > G/U日线差乘以当前货币对两段距之和
{
Comment("False testimony"); //提示(无效证据)
return(0); //返回
}
}
}
else //否则
{
Comment("Negative correlation found"); //窗口显示(已发现负相关!)
return(0); //返回
}


if (currenttype == OP_SELL) //如果当前货币对类型为卖
{
secondticket = OrderSend(HuoBi, //则下单买G/U
OP_BUY,
secondlots,
MarketInfo(HuoBi, MODE_ASK), //(注意是G/U的货币的叫卖价格)
2,
0,
0,
WindowExpertName(),
0,
0,
Blue);
}
else //否则
{
secondticket = OrderSend(HuoBi, //下卖G/U
OP_SELL,
secondlots,
MarketInfo(HuoBi, MODE_BID),
2,
0,
0,
WindowExpertName(),
0,
0,
Red);
}

if (secondticket >= 0) //如果下单成功
{
OpenBarsPriceOnly = false; //将参数 赋为假
}

return(0); //一次循环结束,返回
}
//+------------------------------------------------------------------+
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值