示例#1
0
//+------------------------------------------------------------------+
//| Check for close order conditions                                 |
//+------------------------------------------------------------------+
void CheckForClose()
  {
   double ma;
//--- go trading only for first tiks of new bar
   if(Volume[0]>1) return;
//--- get Moving Average 
   ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0);
//---
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue;
      //--- check order type 
      if(OrderType()==OP_BUY)
        {
         if(Open[1]>ma && Close[1]<ma)
           {
            if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,White))
               Print("OrderClose error ",GetLastError());
           }
         break;
        }
      if(OrderType()==OP_SELL)
        {
         if(Open[1]<ma && Close[1]>ma)
           {
            if(!OrderClose(OrderTicket(),OrderLots(),Ask,3,White))
               Print("OrderClose error ",GetLastError());
           }
         break;
        }
     }
//---
  }
示例#2
0
void Execute(customer bj[],customer sh[],customer gz[])
{
    int n=0;
    scanf("%d",&n);
    while (n) {
        switch (n                                                                                                                                                                      ) {
            case 1:
                Airline(bj,sh,gz);
                //                Press();
                PrtMenu();
                Execute(bj,sh,gz);
                
            case 2:
                CustomInfo(bj,sh,gz);
                PrtMenu();
                Execute(bj,sh,gz);
                
            case 3:
                OrderTicket(bj,sh,gz);
                PrtMenu();
                Execute(bj,sh,gz);
            case 4:
                Refund(bj, sh, gz);
                //                Press();
                PrtMenu();
                Execute(bj,sh,gz);
            default:
                Execute(bj,sh,gz);
        }
    }
        printf("您已退出航空订票系统,欢迎下次再来!\n");
    
} // 执行结构
//+------------------------------------------------------------------+
//| Check for close order conditions                                 |
//+------------------------------------------------------------------+
void CheckForClose()
{
   double ma_cur;
   double ma_prev1;
   double ma_prev2;
   
//---- go trading only for first tiks of new bar
   if(Volume[0] > 1) {
     return;
   }
//---- get Moving Average
   ma_cur = iMA(NULL, 0, MA_PERIOD, 0, MODE_SMA, PRICE_CLOSE, 0);
   ma_prev1 = iMA(NULL, 0, MA_PERIOD, 0, MODE_SMA, PRICE_CLOSE, 1);
   ma_prev2 = iMA(NULL, 0, MA_PERIOD, 0, MODE_SMA, PRICE_CLOSE, 2);   
//----
   for(int i = 0;i < OrdersTotal();i++)
     {
       if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == false){
	      break;
       }
       if(OrderMagicNumber() != MAGICMA || OrderSymbol() != Symbol()){
	 continue;
       }
       //---- check order type 
       if(OrderType() == OP_BUY)
	 {
	   if(cross_below(ma_cur, ma_prev1) || touch_bottom(ma_cur, ma_prev1, ma_prev2) || OrderProfit() > AccountFreeMargin()*(-0.07)){
	     OrderClose(OrderTicket(), OrderLots(), Bid, 3, White);
	   }
	   break;
        }
      if(OrderType() == OP_SELL)
        {
	  if(cross_above(ma_cur, ma_prev1) || touch_top(ma_cur, ma_prev1, ma_prev2)|| OrderProfit() > AccountFreeMargin()*(-0.07)){
	    OrderClose(OrderTicket(), OrderLots(), Ask, 3, White);
	  }  
	  break;
        }
     }
//----
}
示例#4
0
void OrderTicket(customer bj[],customer sh[],customer gz[])
{
    //    FILE *fp=NULL;
    //    fp=fopen(CustomMess_PATH, "r+");
    int x=0;
    printf("请输入您要到达的城市\n");
    printf("1.北京 2.上海 3.广州\n");
    scanf("%d",&x);
    if (x==1) {
        for(int i=1;i<100;i++){
            if(bj[i].seatNum!=i+1){
                printf("请输入您的姓名:\n");
                scanf("%s",bj[i].name);
                strcpy(bj[i].flightNum, "CX6122");
                printf("您要订的航班号为:%s\n",bj[i].flightNum);
                printf("系统正在为您分配座位号:\n请稍后.......\n");
                sleep(2);
                bj[i].seatNum=i+1;
                printf("您的座位号为%d\n",bj[i].seatNum);
                break;
            }
        }
        
    }
    else if(x==2){
        for(int i=0;i<100;i++){
            if(sh[i].seatNum!=i+1){
                printf("请输入您的姓名:\n");
                scanf("%s",sh[i].name);
                strcpy(sh[i].flightNum, "CA418");
                printf("您要订的航班号为:%s\n",sh[i].flightNum);
                printf("系统正在为您分配座位号:\n请稍后.......\n");
                sleep(2);
                sh[i].seatNum=i+1;
                printf("您的座位号为%d\n",sh[i].seatNum);
                break;
                
            }
        }
    }
    else if(x==3){
        for(int i=0;i<100;i++){
            if(gz[i].seatNum!=i+1){
                printf("请输入您的姓名:\n");
                scanf("%s",gz[i].name);
                strcpy(gz[i].flightNum, "KA1428");
                printf("您要订的航班号为:%s\n",gz[i].flightNum);
                printf("系统正在为您分配座位号:\n请稍后.......\n");
                sleep(2);
                gz[i].seatNum=i+1;
                printf("您的座位号为%d\n",gz[i].seatNum);
                break;
            }
        }
    }
    else{
        printf("输入错误,请重新选择\n");
        sleep(1);
        OrderTicket(bj, sh, gz);
    }
    
} // 订票
示例#5
0
文件: ai.c 项目: bengelbert/ifsc
int start()
{
    int err = 0;
    int total = 0;
    int prevticket = 0;
    int modespread = MarketInfo(Symbol(), MODE_SPREAD);
    
    //----
    if (IsTradeAllowed()) {
        RefreshRates();
        modespread = MarketInfo(Symbol(), MODE_SPREAD);
    } else {
        return (0);
    }
    
    ObjectSetText(WT_INFO_NAME,
        "Perceptron("+gOrderbar+"): " +
        "Spread("+modespread+") "+
        ""+DoubleToStr(perceptron(), 2)+"",
        7, "Arial", White);

    // check for opened position
    total = OrdersTotal();
    
    //----
    for (int i = 0; i < total; i++) {
        OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
        // check for symbol & magic number
        if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
            prevticket = OrderTicket();
            
            gOrderbar = iBarShift(Symbol(), 0, OrderOpenTime());
            
            // long position is opened
            if (OrderType() == OP_BUY) {
                // check profit 
                if (Bid > (OrderStopLoss() + (sl * 2 + modespread) * Point)) {
                    if (perceptron() < 0) { // reverse
                        gOrderTicket = OrderSend(Symbol(), OP_SELL, OrderLots(), Bid, 3,
                            Ask + sl * Point, 0, "AI Rev", MagicNumber, 0, Red);
                        Sleep(10000);
                        //----
                        if (gOrderTicket >= 0) {
                            OrderCloseBy(gOrderTicket, prevticket, Blue);
                        } else {
                            err=GetLastError();
                            Print("error[1](",err,"): ",ErrorDescription(err));
                            
                            if (OrderStopLoss() < OrderOpenPrice()) {
                                if (!OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice(), 0, 0, Blue)) {
                                    Sleep(1000);
                                }
                            }
                            
                        }
                    } else { // trailing stop
                        if (!OrderModify(OrderTicket(), OrderOpenPrice(), Bid - sl * Point, 0, 0, Blue)) {
                            Sleep(1000);
                        }
                    }
                }
                // short position is opened
            } else {
                // check profit 
                if (Ask < (OrderStopLoss() - (sl * 2 + modespread) * Point)) {
                    if (perceptron() > 0) { // reverse
                        gOrderTicket = OrderSend(Symbol(), OP_BUY, OrderLots(), Ask, 3,
                            Bid - sl * Point, 0, "AI Rev", MagicNumber, 0, Blue);
                        Sleep(10000);
                        //----
                        if (gOrderTicket >= 0) {
                            OrderCloseBy(gOrderTicket, prevticket, Blue);
                        } else {
                            err=GetLastError();
                            Print("error[2](",err,"): ",ErrorDescription(err));
                            
                            if (OrderStopLoss() > OrderOpenPrice()) {
                                if (!OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice(), 0, 0, Blue)) {
                                    Sleep(1000);
                                }
                            }
                        }
                    } else { // trailing stop
                        if (!OrderModify(OrderTicket(), OrderOpenPrice(), Ask + sl * Point,
                            0, 0, Blue)) {
                            Sleep(1000);
                        }
                    }
                }
            }
            // exit
            return (0);
        }
    }

    if (gOrderbar == iBarShift(Symbol(), 0, 0)) {
        return (0);
    }

    lots = NormalizeDouble(AccountBalance() * aiGetRisk(Period()) / (sl + modespread), 2);
    if (lots < 0.01) lots = 0.01;
    
    // check for long or short position possibility
    if (perceptron() > 0) { //long
        gOrderTicket = OrderSend(Symbol(), OP_BUY, lots, Ask, 3, Bid - sl * Point, 0, "AI",
            MagicNumber, 0, Blue);
        //----
        if (gOrderTicket < 0) {
            Sleep(10000);
            err=GetLastError();
            Print("error[3](",err,"): ",ErrorDescription(err));
        }
    } else { // short
        gOrderTicket = OrderSend(Symbol(), OP_SELL, lots, Bid, 3, Ask + sl * Point, 0, "AI",
            MagicNumber, 0, Red);
        if (gOrderTicket < 0) {
            Sleep(10000);
            err=GetLastError();
            Print("error[4](",err,"): ",ErrorDescription(err));
        }
    }
    //--- exit
    return (0);
}