zyz 发表于 2014-12-15 16:56:10

请教高手,怎么让这两个单子按照一样的条件分别平仓?

{:soso_e183:}谢谢
源码如下:

         extern double SHORT=500;
      extern double LONG=520;
      extern double MID=180;
      int       bb=0, ss=0;
         input double TrailingStop=600;   
      double   total, ticket,Lots;

      int start()
      {
         double MacdCurrent, MacdPrevious, SignalCurrent;
         double SignalPrevious;
         double MacdCurrent1, MacdPrevious1, SignalCurrent1;
         double SignalPrevious1;
         int cnt;
         MacdCurrent=iMACD(NULL,0,SHORT,LONG,MID,PRICE_CLOSE,MODE_MAIN,1);
         MacdPrevious=iMACD(NULL,0,SHORT,LONG,MID,PRICE_CLOSE,MODE_MAIN,11);
         SignalCurrent=iMACD(NULL,0,SHORT,LONG,MID,PRICE_CLOSE,MODE_SIGNAL,1);
         SignalPrevious=iMACD(NULL,0,SHORT,LONG,MID,PRICE_CLOSE,MODE_SIGNAL,11);
         MacdCurrent1=iMACD(NULL,PERIOD_M15,SHORT,LONG,MID,PRICE_CLOSE,MODE_MAIN,1);
         MacdPrevious1=iMACD(NULL,PERIOD_M15,SHORT,LONG,MID,PRICE_CLOSE,MODE_MAIN,11);
         SignalCurrent1=iMACD(NULL,PERIOD_M15,SHORT,LONG,MID,PRICE_CLOSE,MODE_SIGNAL,1);
         SignalPrevious1=iMACD(NULL,PERIOD_M15,SHORT,LONG,MID,PRICE_CLOSE,MODE_SIGNAL,11);

         Lots=NormalizeDouble(AccountFreeMargin()*1/10000.0,1);
         total=OrdersTotal();
         if(total<1)
         { bb=0; ss=0;
          if(MacdCurrent>SignalCurrent && MacdPrevious<SignalPrevious )
         {
         ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"macd sample",16384,0,Red);
             if(ticket>0)
             {
             if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
               bb=1;

               }
               }
                  }
                  if((0<total<2)&&(OrderType()== OP_BUY)){
            Strateg(1);
         }


         if( MacdCurrent<SignalCurrent && MacdPrevious>SignalPrevious )
         {
         ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,"macd sample",16384,0,Green);
             if(ticket>0)
             {
             if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
               ss=1;


                  }                           
         return(0);
         }
          if((0<total<2)&&(OrderType()== OP_SELL)){
            Strateg(2);
         }
         for(cnt=0;cnt<total;cnt++)
         {
         OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
         if(OrderType()<=OP_SELL &&   // check for opened position
             OrderSymbol()==Symbol()) // check for symbol
         {
             if(ss=1&&OrderType()==OP_SELL)   // long position is opened
             {

             if( MacdCurrent<SignalCurrent && MacdPrevious>SignalPrevious )
               {
               OrderClose(OrderTicket(),OrderLots(),Bid,3,Green); // close position
               return(0); // exi               }
             }

             else // go to short position
             {
         if(MacdCurrent>SignalCurrent && MacdPrevious<SignalPrevious)
             {
               OrderClose(OrderTicket(),OrderLots(),Ask,3,Red); // close position
               return(0); // exit
             }
             }
             }
         return(0);
         }
         }
         if(OrderType()<=OP_BUY &&   // check for opened position
             OrderSymbol()==Symbol()) // check for symbol
         {
                if(bb=1&&OrderType()==OP_BUY)   // long position is opened
             {

             if( MacdCurrent<SignalCurrent && MacdPrevious>SignalPrevious )
               {
               OrderClose(OrderTicket(),OrderLots(),Bid,3,Red); // close position
               return(0); // exi               }
             }

             else // go to short position
             {
         if(MacdCurrent>SignalCurrent && MacdPrevious<SignalPrevious)
             {
               OrderClose(OrderTicket(),OrderLots(),Ask,3,Green); // close position
               return(0); // exit
             }
             }
       }
       }
       }
      //2222222222222222222222222222======================
      void Strateg (int vv)
         {
         total=OrdersTotal();
         if(total<2)
         {
         if (vv==1 && bb==1&&(OrderOpenPrice()-Point*TrailingStop>=Bid) )                     
         {
         ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,"macd sample",2007,0,Yellow);
             if(ticket>0)
             {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
             }
             return(0);
             }

         if (vv==2 && ss==1&&(Ask>=OrderOpenPrice()+Point*TrailingStop) )                     
         {
         ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"macd sample",2007,0,White);
             if(ticket>0)
             {
             if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
             }
             return(0);
         }

         }
         }

      // the end.


zyz 发表于 2014-12-15 22:15:28

高手指点一下的人都没有吗?

熙羽 发表于 2014-12-15 23:34:39

没听明白你的逻辑!

zyz 发表于 2014-12-16 10:16:16

因为这两个订单总是同时平仓

solove 发表于 2014-12-16 13:00:17

不懂啊,你要表达什么意思 ?

zyz 发表于 2014-12-16 15:47:34

我的意思是,一样的平仓条件;又同时持有一多一空两张订单,怎么样识别这两个订单

zyz 发表于 2014-12-16 21:02:44

难道没人能解决这个问题吗?

zyczh 发表于 2014-12-17 22:32:22

可以在建立单子的时候对单子加一个标注,平仓的时候按标注平仓即可。比如OrderSend里面是"macd sample-1"和"macd sample-2",则可在平仓的时候指定平1就是1平2就是2。

zyz 发表于 2014-12-18 06:09:40

谢谢哈,{:soso_e183:}zyczh

zyz 发表于 2014-12-18 07:32:43

按照标注平仓的具体表达式可以说一下吗?谢谢

1984712859 发表于 2014-12-22 02:06:22

520功德无量,学习,谢谢
页: [1]
查看完整版本: 请教高手,怎么让这两个单子按照一样的条件分别平仓?