客服热线:18391752892

[转帖]智能交易系统基础

   日期:2019-01-12     浏览:940    
RE //+------------------------------------------------------------------+
 //|                   Designed by OKwh, China   |
 //|              Copyright 2006, OKwh |
 //|                               |
 //+------------------------------------------------------------------+
 #property copyright Copyright 2006, OKwh
 #property link   
 #define MAGICMA 200610011231
 //+------------------------------------------------------------------+
 //| 注意没有指标文件那些property              |
 //+------------------------------------------------------------------+
 extern int whichmethod = 1;   //1~4 种下单方式
 extern double TakeProfit = 100;   
 extern   double StopLoss = 20;
 extern double MaximumRisk   = 0.3;
 extern double TrailingStop =25;
 extern   int maxOpen = 3;   //最多持仓限制
 extern   int maxLots = 5;   //最多单仓限制
 extern int bb = 0;      //非零就跟踪止赢
 extern double MATrendPeriod=26;//使用26均线
   
 int i, p2, xxx,p1, res;
 double Lots;
 datetime lasttime;
 int init()   //初始化
 {
 Lots = 1;
 lasttime = NULL;
 return(0);
 }
 int deinit() { return(0); } //反初始化
 //主程序
 int start()
 {
 CheckForOpen();
 if (bb 0)   CTP();   //跟踪止赢
 return(0);
 }
 //+------下面是各子程序--------------------------------------------+
 double LotsOptimized()   //确定下单量,开仓调用
 {
 double lot=Lots;
 int   orders=HistoryTotal();   // history orders total
 int   losses=0;          // number of losses orders without a break
 //MarketInfo(Symbol(),MODE_MINLOT);
 //MarketInfo(Symbol(),MODE_MAXLOT);
 //MarketInfo(Symbol(),MODE_LOTSTEP);
 lot=NormalizeDouble(MaximumRisk * AccountBalance()/AccountLeverage(),1);
 if(lotmaxLots) lot=maxLots;
 return(lot);
 }
   
 //平仓持有的买单
 void CloseBuy()
 {
 if (OrdersTotal( ) 0 )   
 {
    for(i=OrdersTotal()-1;i 0 )   
 {
    for(i=OrdersTotal()-1;i0 MacdCurrentSignalPrevious
      MaCurrent 19 ) return; //周五晚11点后不做
    }
   
 if (OrdersTotal( ) = maxOpen) return ;   
 //如果已持有开仓数达到最大,不做
 if (nowbuyorsell==0) return;   //不交易
 TradeOK();   //去下单交易
 }
 void TradeOK()   //去下单交易
 {
 int error ;
 if (nowbuyorsell == 1) //买
    {
     switch (whichmethod)
     {
     case 1:   res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,0,0, ,MAGICMA,0,Blue);break;
     case 2:   res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,Ask-StopLoss*Point,0, ,MAGICMA,0,Blue); break;
     case 3:   res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,0,Ask+TakeProfit*Point, ,MAGICMA,0,Blue);break;
     case 4:   res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point, ,MAGICMA,0,Blue);break;
     default : res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,0,0, ,MAGICMA,0,Blue);break;
     }
     if (res r /     {br /     if (OrderStopLoss() Bid - TrailingStop * MarketInfo(OrderSymbol(), MODE_POINT)) br /     {br /     bs = OrderModify(OrderTicket(), OrderOpenPrice(), Bid - TrailingStop * MarketInfo(OrderSymbol(), MODE_POINT), OrderTakeProfit(),0, Green);br /     }br /     }br /    } br /    else if (OrderType() == OP_SELL) br /    {br /     if ((OrderOpenPrice() - Ask) (TrailingStop * MarketInfo(OrderSymbol(), MODE_POINT)))
     {
     if ((OrderStopLoss()) (Ask + TrailingStop * MarketInfo(OrderSymbol(), MODE_POINT)))
     {   
     bs = OrderModify(OrderTicket(), OrderOpenPrice(),
        Ask + TrailingStop * MarketInfo(OrderSymbol(), MODE_POINT), OrderTakeProfit(),0, Tan);
 }
     }
    }
 }
 }
外汇交易有很大的风险性,本站所有资源均来自网络,请选择使用,如若出现亏损,本站不承担任何责任!

特别提示:本信息由相关企业自行提供,真实性未证实,仅供参考。请谨慎采用,风险自负。


0相关评论
相关行情
推荐行情
点击排行