buy 函数,请教如何改成一根k 下一单

要添加评论,请登录注册
ricowang
22
ricowang  
int buy(double Lots,double sun,double ying,string comment,int magic)

    {


          

          int kaiguan=0; //初始化开关为打开

            for(int i=0;i<OrdersTotal();i++) //扫描订单总数

               {

                   if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) //选定当前持单

                     {

                       if((OrderComment()==comment)&&(OrderMagicNumber()==magic)) //如果当前持单注释和编号和设定的一致,则开关关闭不下单。    

                         {

                           kaiguan=1;                     

                         } 

                      }

               }

            if(kaiguan==0) //如果开关打开

              {

                   int ticket=OrderSend(Symbol( ) ,OP_BUY,Lots,Ask,滑点,0,0,comment,magic,0,White); //开仓买入多单,不设止盈止损(下单成功返回编号,失败返回-1)

                   if(ticket>0) //下单成功

                   {

                    if(OrderSelect(ticket, SELECT_BY_TICKET)==true) //选定订单如果编号一致

                      {

                       if((sun!=0)&&(ying!=0)) //不设止损止盈的情况

                        {

                          OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-sun*MarketInfo(Symbol(),MODE_POINT),OrderOpenPrice()+ying*MarketInfo(Symbol(),MODE_POINT),0,Red); 

                          //修改止盈止损

                        }

                       if((sun==0)&&(ying!=0)) //不设止损,设置止盈的情况

                        {

                          OrderModify(OrderTicket(),OrderOpenPrice(),0,OrderOpenPrice()+ying*MarketInfo(Symbol(),MODE_POINT),0,Red); 

                          //修改止盈

                        }

                       if((sun!=0)&&(ying==0)) //设置止损,不设止盈的情况

                        {

                          OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-sun*MarketInfo(Symbol(),MODE_POINT),0,0,Red); 

                          //修改止损

                        }

                      }

                   }

              return(ticket);

              }

             else

              {

               return(0);

              }

     }
Jiamin Huang
264
Jiamin Huang  
可以在下单前加入一个对当前K的时间的判断,如果有持仓,时间如果没变则不开新仓
Qian Gan
305
Qian Gan  
      datetime RefreshTime = 0;
      
      if(RefreshTime!=Time[0])
         {
            if(buy()>0) RefreshTime=Time[0];
         }
通过K线的的时间来判断
ricowang
22
ricowang  
Jiamin & Qian  感謝兩位 ^^
要添加评论,请登录注册