- extern int shoudan=1;
- extern double shoushu=0.01;
- extern int Szhiyin=40;
- extern int jiacang=40;
- extern int beishu=2;
- extern int cishu=8;
- extern int zhisun=20;
- int a,chicangdan,kaicang;
- //+------------------------------------------------------------------+
- //| expert initialization function |
- //+------------------------------------------------------------------+
- int init()
- {
- //----
- //----
- return(0);
- }
- //+------------------------------------------------------------------+
- //| expert deinitialization function |
- //+------------------------------------------------------------------+
- int deinit()
- {
- //----
- //----
- return(0);
- }
- //+------------------------------------------------------------------+
- //| expert start function |
- //+------------------------------------------------------------------+
- int start()
- {
- //----
- if(Bars<100)
- {
- Print("bars less than 100");
- return(0);
- }
- Print("持仓单方向1为买,2为卖:",TheLastOrderType());
- chicangdan=GetHoldingOrderCnt();
- if(chicangdan<1)
- {
- if(TheLastOrderType()==-1)
- {
- if(shoudan==1)
- {
- mairu();
- Print("测试111");
- }
- if(shoudan==2)
- {
- Print("测试222");
- }
- }
- if(TheLastOrderType()==0)
- {
- Print("测试11");
- }
- if(TheLastOrderType()==1)
- {
- Print("测试22");
- return(0);
- }
- }
- //----
- return(0);
- }
- //+------------------------------------------------------------------+
- int TheLastOrderType()//返回最后历史单的方向 如果返回-1表示没有持仓
- {
- int P=-1;
- for(int i=OrdersTotal()-1;i>=0;i--)
- {
- OrderSelect(i, SELECT_BY_POS, MODE_HISTORY);
- if(OrderSymbol()==Symbol() && OrderMagicNumber()==123 )
- {
- P=OrderType();
- break;
- }
- }
- return(P);
- }
- //+------------------------------------------------------------------+
- int GetHoldingOrderCnt()
- {
- int j=0;
- for(int i=0;i<OrdersTotal();i++)
- {
- OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
- if(OrderSymbol()==Symbol() )
- {
- j=j+1;
- }
- }
- return(j);
- }
- void mairu()
- {
- kaicang=OrderSend(Symbol(),OP_BUY,shoushu,Ask,3,Ask-500*Point,Ask+Szhiyin*Point,"My order #2",123,0,Lime);
- }
- void maichu()
- {
- kaicang=OrderSend(Symbol(),OP_SELL,shoushu,Bid,3,Bid+500*Point,Bid-Szhiyin*Point,"My order #2",123,0,Magenta);
- }
|