w09a5b3v 发表于 2011-12-8 08:03:07

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

&ltRE>//+------------------------------------------------------------------+
//|                           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);
}
      }
    }
}
}

q826418559 发表于 2012-11-22 00:02:14

i love you

jlnobody 发表于 2012-11-22 02:15:12

(*^__^*) 嘻嘻……   

gsy 发表于 2012-11-22 02:15:12

一楼的位置好啊..

御赐黄马甲 发表于 2012-11-22 02:15:12

我来看看!谢谢

红烧蛋疼 发表于 2012-11-22 02:15:12

有空一起交流一下

博信黄金 发表于 2012-11-22 02:15:12

我该不会是最后一个顶的吧

坑爹的外汇 发表于 2012-11-22 02:15:12

我来了~~~~~~~~~ 闪人~~~~~~~~~~~~~~~~

伊人146 发表于 2012-11-22 02:15:12

先看看怎么样!

一招 发表于 2013-6-14 10:44:35

这贴?不回都不行啊
页: [1] 2 3
查看完整版本: [转帖]智能交易系统基础