MT4 Files

Check-in [e8e4df9262]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Improved copy rates function
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:e8e4df92627bff572cdecd834f0104ee88917ad8
User & Date: onagano 2011-04-25 07:09:36
Context
2011-04-26
02:57
Added slightly fixed version of CounterADD2 EA check-in: 40ff258d16 user: onagano tags: trunk
2011-04-25
07:09
Improved copy rates function check-in: e8e4df9262 user: onagano tags: trunk
03:19
Added dumping code to avoid unpredictable binding error check-in: ec6e2b4d90 user: onagano tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to experts/MOB_executeOrder.mq4.

455
456
457
458
459
460
461


462
463
464
465
466
467
468
...
496
497
498
499
500
501
502
503
504
505







506
507
508
509
510
511
512
...
642
643
644
645
646
647
648









649
650
651
652
653
654
655
...
658
659
660
661
662
663
664






665
666
667
668
669
670
671
672
673
674





675
676
677
678
679
680
681
....
1029
1030
1031
1032
1033
1034
1035
1036




1037
1038
1039
1040
1041
1042
1043
....
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066

1067

1068





1069
1070
1071
1072
1073
1074
1075
   return (sql);
}

int selectOrders() {
   int rc = 0;

   rc = mob_selectToFetch(selectOrderStmt);


   while (mob_fetch(selectOrderStmt) != 0) {
   
      switch (ordOperation[0]) {
      case OPE_SEND:
         orderSend();
         break;
      case OPE_CLOSE:
................................................................................
         string mesg = "Unknown operation: " + ordOperation[0];
         Print(mesg);
         ordErrorNumber[0] = -1;
         mob_strcpy(ordErrorMessage, ordErrorMessageSize, mesg);
      }
      
      ordOperation[0] = - ordOperation[0];
      rc = mob_executeStatement(updateOrderStmt);
      Print("Operation ", - ordOperation[0], " done with #", ordErrorNumber[0], " (", ordErrorMessage, ")");
   }







   mob_fetchedAll(selectOrderStmt);
   
   return (rc);
}

void getServerResponse() {
   int err = GetLastError();
................................................................................
            break;
         }
      }
      // close all position
      if (ordLots[0] == 0.0) {
         ordLots[0] = OrderLots();
      }









      // closing
      if (OrderClose(
         ordTicket[0],
         ordLots[0],
         ordClosePrice[0],
         ordSlippage[0],
         ordArrowColor[0])) {
................................................................................
      }
   } else { // cannot select order
      getServerResponse();
   }
}

void orderCloseBy() {






   if (OrderCloseBy(
      ordTicket[0],
      ordOppositeTicket[0],
      ordArrowColor[0])) {
   } else {
      getServerResponse();
   }
}

void orderDelete() {





   if (OrderDelete(
      ordTicket[0],
      ordArrowColor[0])) {
   } else {
      getServerResponse();
   }
}
................................................................................
}

void copyRates() {
   string symbol = ordSymbol;
   int    period = ordType[0];
   string tableName = ExtTablePrefix + symbol + "_" + getPeriodSymbol(period);
   
   createTableIfNotExists(tableName, createBarTableSQL(tableName));





   int count      = mob_selectInt("select count(*) from " + tableName, -1);
   datetime dtMax = mob_selectDatetime("select max(time) from " + tableName, -1);
   datetime dtMin = mob_selectDatetime("select min(time) from " + tableName, -1);
   int start;
   int end;
   int rv;
................................................................................
      datetime dts[];
      ArrayCopySeries(dts, MODE_TIME, symbol, period);
      int iMax = ArrayBsearch(dts, dtMax, WHOLE_ARRAY, 0 , MODE_DESCEND);
      start = nBars - iMax;
      end = nBars - 1; // Exclude the latest bar.
      rv = copyRatesBetween(tableName, start, end, symbol, period, rates);
   }

   if (rv < 0) {
      getDatabaseResponse();

   }

   ordMagicNumber[0] = rv;





}

int copyRatesBetween(string tableName, int start, int end, string symbol, int period, double& rates[]) {
   int rv = 0;
   
   int insertBarStmt = mob_registerStatement(insertBarSQL(tableName));
   mob_setAutoCommit(false);







>
>







 







<

|
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>










>
>
>
>
>







 







|
>
>
>
>







 







<


>

>
|
>
>
>
>
>







455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
...
498
499
500
501
502
503
504

505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
...
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
...
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
....
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
....
1089
1090
1091
1092
1093
1094
1095

1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
   return (sql);
}

int selectOrders() {
   int rc = 0;

   rc = mob_selectToFetch(selectOrderStmt);
   if (rc < 0) return (rc);
   
   while (mob_fetch(selectOrderStmt) != 0) {
   
      switch (ordOperation[0]) {
      case OPE_SEND:
         orderSend();
         break;
      case OPE_CLOSE:
................................................................................
         string mesg = "Unknown operation: " + ordOperation[0];
         Print(mesg);
         ordErrorNumber[0] = -1;
         mob_strcpy(ordErrorMessage, ordErrorMessageSize, mesg);
      }
      
      ordOperation[0] = - ordOperation[0];

      Print("Operation ", - ordOperation[0], " done with #", ordErrorNumber[0], " (", ordErrorMessage, ")");

      rc = mob_executeStatement(updateOrderStmt);
      if (rc < 0) {
         mob_fetchedAll(selectOrderStmt);
         return (rc);
      }
   }
   
   mob_fetchedAll(selectOrderStmt);
   
   return (rc);
}

void getServerResponse() {
   int err = GetLastError();
................................................................................
            break;
         }
      }
      // close all position
      if (ordLots[0] == 0.0) {
         ordLots[0] = OrderLots();
      }
      
      Print("Closing ",
         ordTicket[0], ", ",
         ordLots[0], ", ",
         ordClosePrice[0], ", ",
         ordSlippage[0], ", ",
         ordArrowColor[0]
      );
      
      // closing
      if (OrderClose(
         ordTicket[0],
         ordLots[0],
         ordClosePrice[0],
         ordSlippage[0],
         ordArrowColor[0])) {
................................................................................
      }
   } else { // cannot select order
      getServerResponse();
   }
}

void orderCloseBy() {
   Print("Closing-by ",
      ordTicket[0], ", ",
      ordOppositeTicket[0], ", ",
      ordArrowColor[0]
   );
   
   if (OrderCloseBy(
      ordTicket[0],
      ordOppositeTicket[0],
      ordArrowColor[0])) {
   } else {
      getServerResponse();
   }
}

void orderDelete() {
   Print("Deleting ",
      ordTicket[0], ", ",
      ordArrowColor[0]
   );
   
   if (OrderDelete(
      ordTicket[0],
      ordArrowColor[0])) {
   } else {
      getServerResponse();
   }
}
................................................................................
}

void copyRates() {
   string symbol = ordSymbol;
   int    period = ordType[0];
   string tableName = ExtTablePrefix + symbol + "_" + getPeriodSymbol(period);
   
   int rc = createTableIfNotExists(tableName, createBarTableSQL(tableName));
   if (rc < 0) {
      getDatabaseResponse();
      return;
   }

   int count      = mob_selectInt("select count(*) from " + tableName, -1);
   datetime dtMax = mob_selectDatetime("select max(time) from " + tableName, -1);
   datetime dtMin = mob_selectDatetime("select min(time) from " + tableName, -1);
   int start;
   int end;
   int rv;
................................................................................
      datetime dts[];
      ArrayCopySeries(dts, MODE_TIME, symbol, period);
      int iMax = ArrayBsearch(dts, dtMax, WHOLE_ARRAY, 0 , MODE_DESCEND);
      start = nBars - iMax;
      end = nBars - 1; // Exclude the latest bar.
      rv = copyRatesBetween(tableName, start, end, symbol, period, rates);
   }

   if (rv < 0) {
      getDatabaseResponse();
      return;
   }
   
   ordErrorNumber[0] = rv;
   string mesg = "Copied " + rv + " bars";
   if (rv > 0) {
      mesg = mesg + " from " + TimeToStr(rates[nBars - start - 1][0]) + " to " + TimeToStr(rates[nBars - end][0]);
   }
   mob_strcpy(ordErrorMessage, ordErrorMessageSize, mesg);
}

int copyRatesBetween(string tableName, int start, int end, string symbol, int period, double& rates[]) {
   int rv = 0;
   
   int insertBarStmt = mob_registerStatement(insertBarSQL(tableName));
   mob_setAutoCommit(false);