`
walksing
  • 浏览: 217099 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

.[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);                                                         //一次循环结束,返回
  }
//+------------------------------------------------------------------+
分享到:
评论

相关推荐

    EA_Asia_expertadvisormt4_www.ea.com./asia/_

    1. WALLSTREET_ASIA.dat 和 WALLSTREET_ASIA.dll 可能是与EA相关的数据文件和动态链接库,它们包含了EA运行所需的特定算法和功能。 2. WallStreet_ASIA_v1.4.ex4 和 WallStreet_ASIA_v1.4_Simple.ex4 是EA的可执行...

    链接:https://pan.baidu.com/s/1JvydgTFjcpwLdgstEysgEQ 提取码:sbgj

    这一变化对于备考苏州大学计算机专业的考生来说,无疑带来了新的挑战与机遇。 一、背景与原因 1. 原专业课难度较大:过去苏州大学计算机专业的自命题专业课难度相对较高,导致学生的平均分普遍偏低,大约在80分...

    注意问题

    jstl和Struts和Jsp 博文链接:https://weiye.iteye.com/blog/36834

    Go编程基础

    http://www.818u.com/beijing/yiliao/a16830434.html ...http://hz.h2h.cn/life/720837101.html?k=97ADA5107A8EA84DB313319F0401B7A0 http://hz.h2h.cn/life/820837102.html?k=1A090C197ACD417922AB8D1864D52CD3 ...

    2023年美赛备战必备数据库

    (https://pic4.zhimg.com/v2-f972b03330ea9b189441d25ff1ddcc0f_180x120.jpg)https://www.mql5.com/zh/economic-calendar/united-stateswww.mql5.com经济统计指标 - MBA智库百科wiki.mbalib.com 各国统计数据网站...

    【Android 文件管理】分区存储 ( MediaStore 文件操作 )

    【Android 文件管理】分区存储 ( MediaStore 文件操作 ) https://hanshuliang.blog.csdn.net/article/details/116948386 博客源码

    Unity CCG Kit V2.0.0 最新版

    官方地址:https://assetstore.unity.com/packages/templates/systems/ccg-kit-52739#releases

    解决fatal:remote error:You can’t push to git://github.com/username/*.git问题的办法

    解决fatal:remote error:You can’t push to git://github.com/username/*.git问题的办法 今天Git push的时候 fatal:remote error: You can't push to git://github....看来我是没有权限push啊。 解决方法: ...接

    Quartus-II-系列下载地址(包括NIOS-Modelsim).docx

    根据提供的文档信息,本文将对Quartus II系列软件及其配套工具NIOS II EDS(Embedded Design Suite)和ModelSim的各个版本进行详细介绍,并提供相关的下载链接。这将有助于读者了解不同版本之间的区别以及如何获取...

    关闭windows空链接

    关闭windows空链接,注册表关闭,直接导入即可。

    CppAMPLanguageAndProgrammingModel.pdf

    CppAMPLanguageAndProgrammingModel.pdf 目前还没有C++ AMP的书,Kate Gregory和Ade Miller正在写一本关于C++ AMP的书,希望很快能够看到它。下面推荐一些在线学习资料: C++ AMP open specification: ...

    TinyPic v4.0.3.26(蒙娜丽莎图片压缩软件)

    Tinypic调整图像大小,以便实现文件大小和图像质量之间的最佳折衷。 而不是1-2Mb图像缩小,质量损失最小,为20-80kB,因此可以通过邮件发送。 TinyPic是“Granny Compatible”,这意味着该软件是如此万无一失,每个...

    ios-映客直播、录制视频、键盘动画.zip

    1、[高仿映客之一项目结构(目录)设计](http://www.jianshu.com/p/ae927783c390) 2、[高仿映客之二怎样打造继承基类](http://www.jianshu.com/p/56c0f19ff895) 3、[高仿映客之三管理类的方式管理项目]...

    td818 root

    D818D升级软件(区分2.5G和3G开机画面)下载地址:http://www.bestsonny.com/Soft/UploadSoft/%C9%FD%BC%B6%C8%ED%BC%FE/TD818D%CF%B5%C1%D0%A3%A8%C7%F8%B7%D62.5G%BA%CD3G%BF%AA%BB%FA%BB%AD%C3%E6%A3%A9.rar ...

    【MinGW-w64 6.3】MATLAB可用编译器 win 64位系统

    安装步骤参考:https://jingyan.baidu.com/article/c843ea0b414cad37921e4a62.html 关联文章:https://blog.csdn.net/qq_51559922/article/details/128791247 查询自己的编译器安装情况: 在命令行输入:mex -setup ...

    酒店管理系统 JAVA+Vue.js+SpringBoot+MySQL

    项目录屏:https://www.bilibili.com/video/BV1zE421N7eA 启动教程:https://www.bilibili.com/video/BV1pW4y1P7GR 项目讲解视频:https://space.bilibili.com/417412814/channel/collectiondetail?sid=2242844

    BackTrack_3下载

    SHA1:471f0e41931366517ea8bffe910fb09a815e42c7 BackTrack 3 Final USB版 Name:: bt3final_usb.iso Size: 784 MB Download: http://cesium.di.uminho.pt/pub/backtrack/bt3final_usb.iso MD5: 5d27c768e9c2fef61...

    staruml_详细教程

    还有其他工具如PowerDesigner等1.Rational Rose是一种基于UML的建模工具。在面向对象应用程序开发领域,Rational Rose是影响其发展的一个重要因素。Rational Rose自推出以来就受到了业界的瞩目,并一直引领着可视化...

    M3u8DownLoader.zip

    根据提交的m3u8链接,下载里面的ts流视频,根据ffmpeg最终合并成mp4文件,解压后文件夹格式不要变,不要在中文文件夹里,执行 java -jar .\M3u8DownLoader.jar https://XXX/20190913/861_0e3fa8ea/index.m3u8即可

    Windows Mobile 5.0 SDK 下载地址收藏

    - **定义**:Windows Mobile 5.0 SDK是微软提供的一个工具集,用于帮助开发者创建、调试和测试Windows Mobile 5.0操作系统上的应用程序。 - **功能**:该SDK包含了各种API文档、示例代码、开发工具以及模拟器等,...

Global site tag (gtag.js) - Google Analytics