Jump to content

Need to Reverse this system


deadsoul

Recommended Posts

please help to revers function of this ea code...it always open buy stop above the price and sell stop under the price with stoploose and takeprofit...but i need it to be reversed please to open sell limit above the price and buy limit under the price ...

thanx in advance....

 

extern int PercentEquityToClose = 10;
extern int Dist = 500;
extern int TP = 500;
extern int SL = 500;
extern int kolOrder = 10;
extern double Lots = 0.1;
extern int Slippage = 1;
extern int Magic = 1;
extern bool TrailingProfit = TRUE;
extern int prchoose = 0;
extern int TrailingStop = 0;
extern string File_Name = "Ask.csv";
bool gi_unused_132 = FALSE;
double gd_136;
double gd_144;
double gd_152;
double gd_172;

int init() {
  gd_172 = AccountBalance();
  if (IsTesting() || IsOptimization()) gd_152 = Ask;
  else gd_152 = Fileread();
  return (0);
}

int start() {
  int li_0 = Dist;
  for (int li_4 = 1; li_4 <= kolOrder; li_4++) {
     if (SL > 0) gd_136 = gd_152 + li_0 * Point - SL * Point;
     else gd_136 = 0;
     if (TP > 0) gd_144 = gd_152 + li_0 * Point + TP * Point;
     else gd_144 = 0;
     if (!ExistOrders("", OP_BUYSTOP, Magic, 0, NormalizeDouble(gd_152 + li_0 * Point, Digits))) SetOrder("", OP_BUYSTOP, Lots, gd_152 + li_0 * Point, gd_136, gd_144, Magic);
     if (SL > 0) gd_136 = gd_152 - li_0 * Point + SL * Point;
     else gd_136 = 0;
     if (TP > 0) gd_144 = gd_152 - li_0 * Point - TP * Point;
     else gd_144 = 0;
     if (!ExistOrders("", OP_SELLSTOP, Magic, 0, NormalizeDouble(gd_152 - li_0 * Point, Digits))) SetOrder("", OP_SELLSTOP, Lots, gd_152 - li_0 * Point, gd_136, gd_144, Magic);
     li_0 += Dist;
  }
  if (gd_152 + Dist * Point < Ask) gd_152 += Dist * Point;
  if (gd_152 - Dist * Point > Ask) gd_152 -= Dist * Point;
  if (TrailingProfit) TProf();
  if (PercentEquityToClose != 0) {
     if (gd_172 / 100.0 * PercentEquityToClose + gd_172 <= AccountEquity()) {
        CPD("", -1, Magic);
        gd_172 = AccountBalance();
     }
  }
  return (0);
}

void CPBS() {
  bool l_ord_close_0;
  color l_color_4;
  double l_ord_lots_8;
  double l_ask_16;
  double l_bid_24;
  double l_price_32;
  int l_error_40;
  if (OrderType() == OP_BUY || OrderType() == OP_SELL) {
     for (int li_44 = 1; li_44 <= 1; li_44++) {
        if (!IsTesting() && !IsExpertEnabled() || IsStopped()) break;
        while (!IsTradeAllowed()) Sleep(5000);
        RefreshRates();
        l_ask_16 = MarketInfo(OrderSymbol(), MODE_ASK);
        l_bid_24 = MarketInfo(OrderSymbol(), MODE_BID);
        if (OrderType() == OP_BUY) l_price_32 = l_bid_24;
        else l_price_32 = l_ask_16;
        l_ord_lots_8 = OrderLots();
        l_ord_close_0 = OrderClose(OrderTicket(), l_ord_lots_8, l_price_32, Slippage, l_color_4);
        if (l_ord_close_0) break;
        l_error_40 = GetLastError();
        if (l_error_40 == 146/* TRADE_CONTEXT_BUSY */) while (IsTradeContextBusy()) Sleep(11000);
        Sleep(5000);
     }
  }
}

void CPD(string as_0 = "", int a_cmd_8 = -1, int a_magic_12 = -1) {
  int l_ord_total_20 = OrdersTotal();
  if (as_0 == "0") as_0 = Symbol();
  for (int l_pos_16 = l_ord_total_20 - 1; l_pos_16 >= 0; l_pos_16--) {
     if (OrderSelect(l_pos_16, SELECT_BY_POS, MODE_TRADES)) {
        if (OrderSymbol() == as_0 || as_0 == "" && a_cmd_8 < OP_BUY || OrderType() == a_cmd_8) {
           if (OrderType() == OP_BUY || OrderType() == OP_SELL)
              if (a_magic_12 < 0 || OrderMagicNumber() == a_magic_12) CPBS();
        }
     }
  }
}

void TProf() {
  int l_cmd_4;
  double l_price_8;
  double ld_16;
  bool li_24;
  double l_ord_open_price_32;
  int l_ticket_40;
  bool l_bool_44;
  if (prchoose == 0) prchoose = MarketInfo(Symbol(), MODE_STOPLEVEL);
  for (int li_0 = 1; li_0 <= OrdersTotal(); li_0++) {
     if (OrderSelect(li_0 - 1, SELECT_BY_POS) == TRUE) {
        l_cmd_4 = OrderType();
        l_price_8 = OrderStopLoss();
        while (true) {
           if (TrailingStop == 0) TrailingStop = MarketInfo(Symbol(), MODE_STOPLEVEL);
           ld_16 = TrailingStop;
           li_24 = FALSE;
           switch (l_cmd_4) {
           case OP_BUY:
              if (NormalizeDouble(l_price_8, Digits) < NormalizeDouble(Bid - ld_16 * Point, Digits) && MarketInfo(OrderSymbol(), MODE_BID) - OrderOpenPrice() >= prchoose * Point) {
                 l_price_8 = Bid - ld_16 * Point;
                 li_24 = TRUE;
              }
              break;
           case OP_SELL:
              if (NormalizeDouble(l_price_8, Digits) > NormalizeDouble(Ask + ld_16 * Point, Digits) || NormalizeDouble(l_price_8, Digits) == 0.0 && OrderOpenPrice() - MarketInfo(OrderSymbol(), MODE_ASK) >= prchoose * Point) {
                 l_price_8 = Ask + ld_16 * Point;
                 li_24 = TRUE;
              }
           }
           if (li_24 == FALSE) break;
           l_ord_open_price_32 = OrderOpenPrice();
           l_ticket_40 = OrderTicket();
           l_bool_44 = OrderModify(l_ticket_40, l_ord_open_price_32, l_price_8, OrderTakeProfit(), 0, Green);
           if (l_bool_44 != TRUE) continue;
           break;
        }
     }
  }
}

int SetOrder(string a_symbol_0, int a_cmd_8, double a_lots_12, double a_price_20, double a_price_28 = 0.0, double a_price_36 = 0.0, int a_magic_44 = 0, int a_datetime_48 = 0, string a_comment_52 = "") {
  color l_color_60;
  int l_datetime_64;
  double l_ask_68;
  double l_bid_76;
  double l_point_84;
  int l_error_92;
  int l_ticket_100;
  if (a_symbol_0 == "" || a_symbol_0 == "0") a_symbol_0 = Symbol();
  int l_stoplevel_104 = MarketInfo(a_symbol_0, MODE_STOPLEVEL);
  if (a_datetime_48 > 0 && a_datetime_48 < TimeCurrent()) a_datetime_48 = 0;
  for (int li_96 = 1; li_96 <= 1; li_96++) {
     if (!IsTesting() && !IsExpertEnabled() || IsStopped()) {
        Print("SetOrder(): ???à?îâêà ?à?î?û ô??ê?èè");
        break;
     }
     while (!IsTradeAllowed()) Sleep(5000);
     RefreshRates();
     l_datetime_64 = TimeCurrent();
     l_ticket_100 = OrderSend(a_symbol_0, a_cmd_8, a_lots_12, a_price_20, Slippage, a_price_28, a_price_36, a_comment_52, a_magic_44, a_datetime_48, l_color_60);
     if (l_ticket_100 > 0) return (l_ticket_100);
     l_error_92 = GetLastError();
     if (l_error_92 == 128/* TRADE_TIMEOUT */ || l_error_92 == 142 || l_error_92 == 143) {
        Sleep(66000);
        if (ExistOrders(a_symbol_0, a_cmd_8, a_magic_44, l_datetime_64)) break;
     } else {
        l_point_84 = MarketInfo(a_symbol_0, MODE_POINT);
        l_ask_68 = MarketInfo(a_symbol_0, MODE_ASK);
        l_bid_76 = MarketInfo(a_symbol_0, MODE_BID);
        if (l_ask_68 == 0.0 && l_bid_76 == 0.0) Comment("SetOrder(): ??îâ??ü?? â î?çî?? ?û?êà ?àëè÷è? ?è?âîëà " + a_symbol_0);
        if (l_error_92 == 130/* INVALID_STOPS */) {
           switch (a_cmd_8) {
           case OP_BUYLIMIT:
              if (a_price_20 > l_ask_68 - l_stoplevel_104 * l_point_84) a_price_20 = l_ask_68 - l_stoplevel_104 * l_point_84;
              if (a_price_28 > a_price_20 - (l_stoplevel_104 + 1) * l_point_84) a_price_28 = a_price_20 - (l_stoplevel_104 + 1) * l_point_84;
              if (a_price_36 > 0.0 && a_price_36 < a_price_20 + (l_stoplevel_104 + 1) * l_point_84) a_price_36 = a_price_20 + (l_stoplevel_104 + 1) * l_point_84;
              break;
           case OP_BUYSTOP:
              if (a_price_20 < l_ask_68 + (l_stoplevel_104 + 1) * l_point_84) a_price_20 = l_ask_68 + (l_stoplevel_104 + 1) * l_point_84;
              if (a_price_28 > a_price_20 - (l_stoplevel_104 + 1) * l_point_84) a_price_28 = a_price_20 - (l_stoplevel_104 + 1) * l_point_84;
              if (a_price_36 > 0.0 && a_price_36 < a_price_20 + (l_stoplevel_104 + 1) * l_point_84) a_price_36 = a_price_20 + (l_stoplevel_104 + 1) * l_point_84;
              break;
           case OP_SELLLIMIT:
              if (a_price_20 < l_bid_76 + l_stoplevel_104 * l_point_84) a_price_20 = l_bid_76 + l_stoplevel_104 * l_point_84;
              if (a_price_28 > 0.0 && a_price_28 < a_price_20 + (l_stoplevel_104 + 1) * l_point_84) a_price_28 = a_price_20 + (l_stoplevel_104 + 1) * l_point_84;
              if (a_price_36 > a_price_20 - (l_stoplevel_104 + 1) * l_point_84) a_price_36 = a_price_20 - (l_stoplevel_104 + 1) * l_point_84;
              break;
           case OP_SELLSTOP:
              if (a_price_20 > l_bid_76 - l_stoplevel_104 * l_point_84) a_price_20 = l_bid_76 - l_stoplevel_104 * l_point_84;
              if (a_price_28 > 0.0 && a_price_28 < a_price_20 + (l_stoplevel_104 + 1) * l_point_84) a_price_28 = a_price_20 + (l_stoplevel_104 + 1) * l_point_84;
              if (a_price_36 > a_price_20 - (l_stoplevel_104 + 1) * l_point_84) a_price_36 = a_price_20 - (l_stoplevel_104 + 1) * l_point_84;
           }
           Print("SetOrder(): ?êî???ê?è?îâà?û ???îâû? ??îâ?è");
        }
        if (l_error_92 == 2/* COMMON_ERROR */ || l_error_92 == 64/* ACCOUNT_DISABLED */ || l_error_92 == 65/* INVALID_ACCOUNT */ || l_error_92 == 133/* TRADE_DISABLED */) break;
        if (l_error_92 == 4/* SERVER_BUSY */ || l_error_92 == 131/* INVALID_TRADE_VOLUME */ || l_error_92 == 132/* MARKET_CLOSED */) {
           Sleep(300000);
           break;
        }
        if (l_error_92 == 8/* TOO_FREQUENT_REQUESTS */ || l_error_92 == 141/* TOO_MANY_REQUESTS */) Sleep(100000);
        if (l_error_92 == 139/* ORDER_LOCKED */ || l_error_92 == 140/* LONG_POSITIONS_ONLY_ALLOWED */ || l_error_92 == 148/* ERR_TRADE_TOO_MANY_ORDERS */) break;
        if (l_error_92 == 146/* TRADE_CONTEXT_BUSY */) while (IsTradeContextBusy()) Sleep(11000);
        if (l_error_92 == 147/* ERR_TRADE_EXPIRATION_DENIED */) a_datetime_48 = 0;
        else
           if (l_error_92 != 135/* PRICE_CHANGED */ && l_error_92 != 138/* REQUOTE */) Sleep(7700.0);
     }
  }
  return (0);
}

bool ExistOrders(string as_0 = "", int a_cmd_8 = -1, int a_magic_12 = -1, int ai_16 = 0, double ad_20 = 0.0) {
  int l_cmd_36;
  int l_ord_total_32 = OrdersTotal();
  if (as_0 == "0") as_0 = Symbol();
  for (int l_pos_28 = 0; l_pos_28 < l_ord_total_32; l_pos_28++) {
     if (OrderSelect(l_pos_28, SELECT_BY_POS, MODE_TRADES)) {
        l_cmd_36 = OrderType();
        if (l_cmd_36 > OP_SELL && l_cmd_36 < 6) {
           if (OrderSymbol() == as_0 || as_0 == "" && a_cmd_8 < OP_BUY || l_cmd_36 == a_cmd_8) {
              if (a_magic_12 < 0 || OrderMagicNumber() == a_magic_12) {
                 if (ai_16 <= OrderOpenTime()) {
                    if (ad_20 != 0.0)
                       if (NormalizeDouble(ad_20, Digits) == NormalizeDouble(OrderOpenPrice(), Digits)) return (TRUE);
                 }
              }
           }
        }
     }
  }
  return (FALSE);
}

void Filewrite(double ad_0 = 0.0) {
  int l_file_8 = FileOpen(File_Name, FILE_CSV|FILE_WRITE, ";");
  if (l_file_8 == -1) {
     Print("??è?êà ï?è î?ê?û?èè ôàéëà. ", "?îç?î??î, ôàéë çà??? ????è? ï?èëî???è??");
     return;
  }
  int li_12 = FileWrite(l_file_8, ad_0);
  if (li_12 < 0) {
     Print("??è?êà çàïè?è â ôàéë ", GetLastError());
     FileClose(l_file_8);
     return;
  }
  FileClose(l_file_8);
}

double Fileread() {
  int l_file_0 = FileOpen(File_Name, FILE_CSV|FILE_READ, ";");
  if (l_file_0 == -1) {
     Print("?àéë ëè?î çà???,ëè?î ??î ?? ??ù???â???, . ", "?îç?à?? ôàéë ?àé???à");
     Filewrite(Ask);
     return (Ask);
  }
  double ld_ret_4 = FileReadDouble(l_file_0);
  if (ld_ret_4 < 0.0) {
     Print("??è?êà ÷???è? èç ôàéëà ", GetLastError());
     return ((l_file_0));
  }
  FileClose(l_file_0);
  return (ld_ret_4);
}

Link to comment
Share on other sites

Re: all coders are invited

 

??? ?? ??? ?? ????? ???? ???? ?????? :D

 

Try this one, maybe it works ...

 

extern int PercentEquityToClose = 10;
extern int Dist = 500;
extern int TP = 500;
extern int SL = 500;
extern int kolOrder = 10;
extern double Lots = 0.1;
extern int Slippage = 1;
extern int Magic = 1;
extern bool TrailingProfit = TRUE;
extern int prchoose = 0;
extern int TrailingStop = 0;
extern string File_Name = "Ask.csv";
bool gi_unused_132 = FALSE;
double gd_136;
double gd_144;
double gd_152;
double gd_172;

int init() {
  gd_172 = AccountBalance();
  if (IsTesting() || IsOptimization()) gd_152 = Ask;
  else gd_152 = Fileread();
  return (0);
}

int start() {
  int li_0 = Dist;
  for (int li_4 = 1; li_4 <= kolOrder; li_4++) {
     if (SL > 0) gd_136 = gd_152 + li_0 * Point - SL * Point;
     else gd_136 = 0;
     if (TP > 0) gd_144 = gd_152 + li_0 * Point + TP * Point;
     else gd_144 = 0;
     if (!ExistOrders("", OP_BUYSTOP, Magic, 0, NormalizeDouble(gd_152 + li_0 * Point, Digits))) SetOrder("", OP_BUYSTOP, Lots, gd_152 + li_0 * Point, gd_136, gd_144, Magic);
     if (SL > 0) gd_136 = gd_152 - li_0 * Point + SL * Point;
     else gd_136 = 0;
     if (TP > 0) gd_144 = gd_152 - li_0 * Point - TP * Point;
     else gd_144 = 0;
     if (!ExistOrders("", OP_SELLSTOP, Magic, 0, NormalizeDouble(gd_152 - li_0 * Point, Digits))) SetOrder("", OP_SELLSTOP, Lots, gd_152 - li_0 * Point, gd_136, gd_144, Magic);
     li_0 += Dist;
  }
  if (gd_152 + Dist * Point < Ask) gd_152 += Dist * Point;
  if (gd_152 - Dist * Point > Ask) gd_152 -= Dist * Point;
  if (TrailingProfit) TProf();
  if (PercentEquityToClose != 0) {
     if (gd_172 / 100.0 * PercentEquityToClose + gd_172 <= AccountEquity()) {
        CPD("", -1, Magic);
        gd_172 = AccountBalance();
     }
  }
  return (0);
}

void CPBS() {
  bool l_ord_close_0;
  color l_color_4;
  double l_ord_lots_8;
  double l_ask_16;
  double l_bid_24;
  double l_price_32;
  int l_error_40;
  if (OrderType() == OP_BUY || OrderType() == OP_SELL) {
     for (int li_44 = 1; li_44 <= 1; li_44++) {
        if (!IsTesting() && !IsExpertEnabled() || IsStopped()) break;
        while (!IsTradeAllowed()) Sleep(5000);
        RefreshRates();
        l_ask_16 = MarketInfo(OrderSymbol(), MODE_ASK);
        l_bid_24 = MarketInfo(OrderSymbol(), MODE_BID);
        if (OrderType() == OP_BUY) l_price_32 = l_bid_24;
        else l_price_32 = l_ask_16;
        l_ord_lots_8 = OrderLots();
        l_ord_close_0 = OrderClose(OrderTicket(), l_ord_lots_8, l_price_32, Slippage, l_color_4);
        if (l_ord_close_0) break;
        l_error_40 = GetLastError();
        if (l_error_40 == 146/* TRADE_CONTEXT_BUSY */) while (IsTradeContextBusy()) Sleep(11000);
        Sleep(5000);
     }
  }
}

void CPD(string as_0 = "", int a_cmd_8 = -1, int a_magic_12 = -1) {
  int l_ord_total_20 = OrdersTotal();
  if (as_0 == "0") as_0 = Symbol();
  for (int l_pos_16 = l_ord_total_20 - 1; l_pos_16 >= 0; l_pos_16--) {
     if (OrderSelect(l_pos_16, SELECT_BY_POS, MODE_TRADES)) {
        if (OrderSymbol() == as_0 || as_0 == "" && a_cmd_8 < OP_BUY || OrderType() == a_cmd_8) {
           if (OrderType() == OP_BUY || OrderType() == OP_SELL)
              if (a_magic_12 < 0 || OrderMagicNumber() == a_magic_12) CPBS();
        }
     }
  }
}

void TProf() {
  int l_cmd_4;
  double l_price_8;
  double ld_16;
  bool li_24;
  double l_ord_open_price_32;
  int l_ticket_40;
  bool l_bool_44;
  if (prchoose == 0) prchoose = MarketInfo(Symbol(), MODE_STOPLEVEL);
  for (int li_0 = 1; li_0 <= OrdersTotal(); li_0++) {
     if (OrderSelect(li_0 - 1, SELECT_BY_POS) == TRUE) {
        l_cmd_4 = OrderType();
        l_price_8 = OrderStopLoss();
        while (true) {
           if (TrailingStop == 0) TrailingStop = MarketInfo(Symbol(), MODE_STOPLEVEL);
           ld_16 = TrailingStop;
           li_24 = FALSE;
           switch (l_cmd_4) {
           case OP_BUY:
              if (NormalizeDouble(l_price_8, Digits) < NormalizeDouble(Bid - ld_16 * Point, Digits) && MarketInfo(OrderSymbol(), MODE_BID) - OrderOpenPrice() >= prchoose * Point) {
                 l_price_8 = Bid - ld_16 * Point;
                 li_24 = TRUE;
              }
              break;
           case OP_SELL:
              if (NormalizeDouble(l_price_8, Digits) > NormalizeDouble(Ask + ld_16 * Point, Digits) || NormalizeDouble(l_price_8, Digits) == 0.0 && OrderOpenPrice() - MarketInfo(OrderSymbol(), MODE_ASK) >= prchoose * Point) {
                 l_price_8 = Ask + ld_16 * Point;
                 li_24 = TRUE;
              }
           }
           if (li_24 == FALSE) break;
           l_ord_open_price_32 = OrderOpenPrice();
           l_ticket_40 = OrderTicket();
           l_bool_44 = OrderModify(l_ticket_40, l_ord_open_price_32, l_price_8, OrderTakeProfit(), 0, Green);
           if (l_bool_44 != TRUE) continue;
           break;
        }
     }
  }
}

int SetOrder(string a_symbol_0, int a_cmd_8, double a_lots_12, double a_price_20, double a_price_28 = 0.0, double a_price_36 = 0.0, int a_magic_44 = 0, int a_datetime_48 = 0, string a_comment_52 = "") {
  color l_color_60;
  int l_datetime_64;
  double l_ask_68;
  double l_bid_76;
  double l_point_84;
  int l_error_92;
  int l_ticket_100;
  if (a_symbol_0 == "" || a_symbol_0 == "0") a_symbol_0 = Symbol();
  int l_stoplevel_104 = MarketInfo(a_symbol_0, MODE_STOPLEVEL);
  if (a_datetime_48 > 0 && a_datetime_48 < TimeCurrent()) a_datetime_48 = 0;
  for (int li_96 = 1; li_96 <= 1; li_96++) {
     if (!IsTesting() && !IsExpertEnabled() || IsStopped()) {
        Print("SetOrder(): ???à?îâêà ?à?î?û ô??ê?èè");
        break;
     }
     while (!IsTradeAllowed()) Sleep(5000);
     RefreshRates();
     l_datetime_64 = TimeCurrent();
     l_ticket_100 = OrderSend(a_symbol_0, a_cmd_8, a_lots_12, a_price_20, Slippage, a_price_28, a_price_36, a_comment_52, a_magic_44, a_datetime_48, l_color_60);
     if (l_ticket_100 > 0) return (l_ticket_100);
     l_error_92 = GetLastError();
     if (l_error_92 == 128/* TRADE_TIMEOUT */ || l_error_92 == 142 || l_error_92 == 143) {
        Sleep(66000);
        if (ExistOrders(a_symbol_0, a_cmd_8, a_magic_44, l_datetime_64)) break;
     } else {
        l_point_84 = MarketInfo(a_symbol_0, MODE_POINT);
        l_ask_68 = MarketInfo(a_symbol_0, MODE_ASK);
        l_bid_76 = MarketInfo(a_symbol_0, MODE_BID);
        if (l_ask_68 == 0.0 && l_bid_76 == 0.0) Comment("SetOrder(): ??îâ??ü?? â î?çî?? ?û?êà ?àëè÷è? ?è?âîëà " + a_symbol_0);
        if (l_error_92 == 130/* INVALID_STOPS */) {
           switch (a_cmd_8) {
           case OP_BUYLIMIT:
              if (a_price_20 > l_ask_68 - l_stoplevel_104 * l_point_84) a_price_20 = l_ask_68 - l_stoplevel_104 * l_point_84;
              if (a_price_28 > a_price_20 - (l_stoplevel_104 + 1) * l_point_84) a_price_28 = a_price_20 - (l_stoplevel_104 + 1) * l_point_84;
              if (a_price_36 > 0.0 && a_price_36 < a_price_20 + (l_stoplevel_104 + 1) * l_point_84) a_price_36 = a_price_20 + (l_stoplevel_104 + 1) * l_point_84;
              break;
           case OP_SELLLIMIT:
              if (a_price_20 < l_ask_68 + (l_stoplevel_104 + 1) * l_point_84) a_price_20 = l_ask_68 + (l_stoplevel_104 + 1) * l_point_84;
              if (a_price_28 > a_price_20 - (l_stoplevel_104 + 1) * l_point_84) a_price_28 = a_price_20 - (l_stoplevel_104 + 1) * l_point_84;
              if (a_price_36 > 0.0 && a_price_36 < a_price_20 + (l_stoplevel_104 + 1) * l_point_84) a_price_36 = a_price_20 + (l_stoplevel_104 + 1) * l_point_84;
              break;
           case OP_SELLLIMIT:
              if (a_price_20 < l_bid_76 + l_stoplevel_104 * l_point_84) a_price_20 = l_bid_76 + l_stoplevel_104 * l_point_84;
              if (a_price_28 > 0.0 && a_price_28 < a_price_20 + (l_stoplevel_104 + 1) * l_point_84) a_price_28 = a_price_20 + (l_stoplevel_104 + 1) * l_point_84;
              if (a_price_36 > a_price_20 - (l_stoplevel_104 + 1) * l_point_84) a_price_36 = a_price_20 - (l_stoplevel_104 + 1) * l_point_84;
              break;
           case OP_BUYLIMIT:
              if (a_price_20 > l_bid_76 - l_stoplevel_104 * l_point_84) a_price_20 = l_bid_76 - l_stoplevel_104 * l_point_84;
              if (a_price_28 > 0.0 && a_price_28 < a_price_20 + (l_stoplevel_104 + 1) * l_point_84) a_price_28 = a_price_20 + (l_stoplevel_104 + 1) * l_point_84;
              if (a_price_36 > a_price_20 - (l_stoplevel_104 + 1) * l_point_84) a_price_36 = a_price_20 - (l_stoplevel_104 + 1) * l_point_84;
           }
           Print("SetOrder(): ?êî???ê?è?îâà?û ???îâû? ??îâ?è");
        }
        if (l_error_92 == 2/* COMMON_ERROR */ || l_error_92 == 64/* ACCOUNT_DISABLED */ || l_error_92 == 65/* INVALID_ACCOUNT */ || l_error_92 == 133/* TRADE_DISABLED */) break;
        if (l_error_92 == 4/* SERVER_BUSY */ || l_error_92 == 131/* INVALID_TRADE_VOLUME */ || l_error_92 == 132/* MARKET_CLOSED */) {
           Sleep(300000);
           break;
        }
        if (l_error_92 == 8/* TOO_FREQUENT_REQUESTS */ || l_error_92 == 141/* TOO_MANY_REQUESTS */) Sleep(100000);
        if (l_error_92 == 139/* ORDER_LOCKED */ || l_error_92 == 140/* LONG_POSITIONS_ONLY_ALLOWED */ || l_error_92 == 148/* ERR_TRADE_TOO_MANY_ORDERS */) break;
        if (l_error_92 == 146/* TRADE_CONTEXT_BUSY */) while (IsTradeContextBusy()) Sleep(11000);
        if (l_error_92 == 147/* ERR_TRADE_EXPIRATION_DENIED */) a_datetime_48 = 0;
        else
           if (l_error_92 != 135/* PRICE_CHANGED */ && l_error_92 != 138/* REQUOTE */) Sleep(7700.0);
     }
  }
  return (0);
}

bool ExistOrders(string as_0 = "", int a_cmd_8 = -1, int a_magic_12 = -1, int ai_16 = 0, double ad_20 = 0.0) {
  int l_cmd_36;
  int l_ord_total_32 = OrdersTotal();
  if (as_0 == "0") as_0 = Symbol();
  for (int l_pos_28 = 0; l_pos_28 < l_ord_total_32; l_pos_28++) {
     if (OrderSelect(l_pos_28, SELECT_BY_POS, MODE_TRADES)) {
        l_cmd_36 = OrderType();
        if (l_cmd_36 > OP_SELL && l_cmd_36 < 6) {
           if (OrderSymbol() == as_0 || as_0 == "" && a_cmd_8 < OP_BUY || l_cmd_36 == a_cmd_8) {
              if (a_magic_12 < 0 || OrderMagicNumber() == a_magic_12) {
                 if (ai_16 <= OrderOpenTime()) {
                    if (ad_20 != 0.0)
                       if (NormalizeDouble(ad_20, Digits) == NormalizeDouble(OrderOpenPrice(), Digits)) return (TRUE);
                 }
              }
           }
        }
     }
  }
  return (FALSE);
}

void Filewrite(double ad_0 = 0.0) {
  int l_file_8 = FileOpen(File_Name, FILE_CSV|FILE_WRITE, ";");
  if (l_file_8 == -1) {
     Print("??è?êà ï?è î?ê?û?èè ôàéëà. ", "?îç?î??î, ôàéë çà??? ????è? ï?èëî???è??");
     return;
  }
  int li_12 = FileWrite(l_file_8, ad_0);
  if (li_12 < 0) {
     Print("??è?êà çàïè?è â ôàéë ", GetLastError());
     FileClose(l_file_8);
     return;
  }
  FileClose(l_file_8);
}

double Fileread() {
  int l_file_0 = FileOpen(File_Name, FILE_CSV|FILE_READ, ";");
  if (l_file_0 == -1) {
     Print("?àéë ëè?î çà???,ëè?î ??î ?? ??ù???â???, . ", "?îç?à?? ôàéë ?àé???à");
     Filewrite(Ask);
     return (Ask);
  }
  double ld_ret_4 = FileReadDouble(l_file_0);
  if (ld_ret_4 < 0.0) {
     Print("??è?êà ÷???è? èç ôàéëà ", GetLastError());
     return ((l_file_0));
  }
  FileClose(l_file_0);
  return (ld_ret_4);
}

 

? ?? ??? ? ??? ???? ?????? ????

 

Good luck deadsoul

Link to comment
Share on other sites

Re: all coders are invited

 

Hi deadsoul,

 

Eid Mubarak,

 

I will try to set this function up, but it is not a promise because I'm still studying this language. I think it all depends on the signals to be reversed.

 

I will let you know soon.

 

Best wishes,

 

-- 29 Nov 2009, 12:30 --

 

Hi brokensoul08,

 

Thanks for your help.

 

Please next time write in either English or Malaysian only, otherwise, you would get me in trouble that I let you write in Arabic. I know its your mother tongue, but you know the policies here are restricted only for Eng and Malay.

 

I'm sorry to say that, but I hope you understand. You can next time add English comments as well so you are safe. You may see some modifications to your post.

 

I would appreciate it if you follow the rules.

 

Best wishes from my deep deep heart.

a New Year 2011 has come, and the challenge has just started 8-)
Link to comment
Share on other sites

Re: all coders are invited

 

I bet you that, because of the spread, reversing the EA will still make it a loosing one. Or, it will make very little money.

 

Give me the backtest or forward test that you think would make great money if reversed and ill tell you how much it would make if reversed. I need the actual html. Dont forget to tell me the spread.

Link to comment
Share on other sites

Re: all coders are invited

 

I bet you that, because of the spread, reversing the EA will still make it a loosing one. Or, it will make very little money.

 

Give me the backtest or forward test that you think would make great money if reversed and ill tell you how much it would make if reversed. I need the actual html. Dont forget to tell me the spread.

 

hii tony...

you can back test it your self ..but only on everytick ...it gos strait down coz of the price action...

i wish if some coder can help reverse it ...i think it would be so great ea...

thank you for your notes....

Link to comment
Share on other sites

Re: all coders are invited

 

extern int PercentEquityToClose = 10;
extern int Dist = 500;
extern int TP = 500;
extern int SL = 500;
extern int kolOrder = 10;
extern double Lots = 0.1;
extern int Slippage = 1;
extern int Magic = 1;
extern bool TrailingProfit = TRUE;
extern int prchoose = 0;
extern int TrailingStop = 0;
extern string File_Name = "Ask.csv";
bool gi_unused_132 = FALSE;
double gd_136;
double gd_144;
double gd_152;
double gd_172;

int init() {
  gd_172 = AccountBalance();
  if (IsTesting() || IsOptimization()) gd_152 = Ask;
  else gd_152 = Fileread();
  return (0);
}

int start() {
  int li_0 = Dist;
  for (int li_4 = 1; li_4 <= kolOrder; li_4++) {
     if (SL > 0) gd_136 = gd_152 + li_0 * Point - SL * Point;
     else gd_136 = 0;
     if (TP > 0) gd_144 = gd_152 + li_0 * Point + TP * Point;
     else gd_144 = 0;
     if (!ExistOrders("", OP_SELLLIMIT, Magic, 0, NormalizeDouble(gd_152 + li_0 * Point, Digits))) SetOrder("", OP_BUYSTOP, Lots, gd_152 + li_0 * Point, gd_136, gd_144, Magic);
     if (SL > 0) gd_136 = gd_152 - li_0 * Point + SL * Point;
     else gd_136 = 0;
     if (TP > 0) gd_144 = gd_152 - li_0 * Point - TP * Point;
     else gd_144 = 0;
     if (!ExistOrders("", OP_BUYLIMIT, Magic, 0, NormalizeDouble(gd_152 - li_0 * Point, Digits))) SetOrder("", OP_SELLSTOP, Lots, gd_152 - li_0 * Point, gd_136, gd_144, Magic);
     li_0 += Dist;
  }
  if (gd_152 + Dist * Point < Ask) gd_152 += Dist * Point;
  if (gd_152 - Dist * Point > Ask) gd_152 -= Dist * Point;
  if (TrailingProfit) TProf();
  if (PercentEquityToClose != 0) {
     if (gd_172 / 100.0 * PercentEquityToClose + gd_172 <= AccountEquity()) {
        CPD("", -1, Magic);
        gd_172 = AccountBalance();
     }
  }
  return (0);
}

void CPBS() {
  bool l_ord_close_0;
  color l_color_4;
  double l_ord_lots_8;
  double l_ask_16;
  double l_bid_24;
  double l_price_32;
  int l_error_40;
  if (OrderType() == OP_BUY || OrderType() == OP_SELL) {
     for (int li_44 = 1; li_44 <= 1; li_44++) {
        if (!IsTesting() && !IsExpertEnabled() || IsStopped()) break;
        while (!IsTradeAllowed()) Sleep(5000);
        RefreshRates();
        l_ask_16 = MarketInfo(OrderSymbol(), MODE_ASK);
        l_bid_24 = MarketInfo(OrderSymbol(), MODE_BID);
        if (OrderType() == OP_BUY) l_price_32 = l_bid_24;
        else l_price_32 = l_ask_16;
        l_ord_lots_8 = OrderLots();
        l_ord_close_0 = OrderClose(OrderTicket(), l_ord_lots_8, l_price_32, Slippage, l_color_4);
        if (l_ord_close_0) break;
        l_error_40 = GetLastError();
        if (l_error_40 == 146/* TRADE_CONTEXT_BUSY */) while (IsTradeContextBusy()) Sleep(11000);
        Sleep(5000);
     }
  }
}

void CPD(string as_0 = "", int a_cmd_8 = -1, int a_magic_12 = -1) {
  int l_ord_total_20 = OrdersTotal();
  if (as_0 == "0") as_0 = Symbol();
  for (int l_pos_16 = l_ord_total_20 - 1; l_pos_16 >= 0; l_pos_16--) {
     if (OrderSelect(l_pos_16, SELECT_BY_POS, MODE_TRADES)) {
        if (OrderSymbol() == as_0 || as_0 == "" && a_cmd_8 < OP_BUY || OrderType() == a_cmd_8) {
           if (OrderType() == OP_BUY || OrderType() == OP_SELL)
              if (a_magic_12 < 0 || OrderMagicNumber() == a_magic_12) CPBS();
        }
     }
  }
}

void TProf() {
  int l_cmd_4;
  double l_price_8;
  double ld_16;
  bool li_24;
  double l_ord_open_price_32;
  int l_ticket_40;
  bool l_bool_44;
  if (prchoose == 0) prchoose = MarketInfo(Symbol(), MODE_STOPLEVEL);
  for (int li_0 = 1; li_0 <= OrdersTotal(); li_0++) {
     if (OrderSelect(li_0 - 1, SELECT_BY_POS) == TRUE) {
        l_cmd_4 = OrderType();
        l_price_8 = OrderStopLoss();
        while (true) {
           if (TrailingStop == 0) TrailingStop = MarketInfo(Symbol(), MODE_STOPLEVEL);
           ld_16 = TrailingStop;
           li_24 = FALSE;
           switch (l_cmd_4) {
           case OP_BUY:
              if (NormalizeDouble(l_price_8, Digits) < NormalizeDouble(Bid - ld_16 * Point, Digits) && MarketInfo(OrderSymbol(), MODE_BID) - OrderOpenPrice() >= prchoose * Point) {
                 l_price_8 = Bid - ld_16 * Point;
                 li_24 = TRUE;
              }
              break;
           case OP_SELL:
              if (NormalizeDouble(l_price_8, Digits) > NormalizeDouble(Ask + ld_16 * Point, Digits) || NormalizeDouble(l_price_8, Digits) == 0.0 && OrderOpenPrice() - MarketInfo(OrderSymbol(), MODE_ASK) >= prchoose * Point) {
                 l_price_8 = Ask + ld_16 * Point;
                 li_24 = TRUE;
              }
           }
           if (li_24 == FALSE) break;
           l_ord_open_price_32 = OrderOpenPrice();
           l_ticket_40 = OrderTicket();
           l_bool_44 = OrderModify(l_ticket_40, l_ord_open_price_32, l_price_8, OrderTakeProfit(), 0, Green);
           if (l_bool_44 != TRUE) continue;
           break;
        }
     }
  }
}

int SetOrder(string a_symbol_0, int a_cmd_8, double a_lots_12, double a_price_20, double a_price_28 = 0.0, double a_price_36 = 0.0, int a_magic_44 = 0, int a_datetime_48 = 0, string a_comment_52 = "") {
  color l_color_60;
  int l_datetime_64;
  double l_ask_68;
  double l_bid_76;
  double l_point_84;
  int l_error_92;
  int l_ticket_100;
  if (a_symbol_0 == "" || a_symbol_0 == "0") a_symbol_0 = Symbol();
  int l_stoplevel_104 = MarketInfo(a_symbol_0, MODE_STOPLEVEL);
  if (a_datetime_48 > 0 && a_datetime_48 < TimeCurrent()) a_datetime_48 = 0;
  for (int li_96 = 1; li_96 <= 1; li_96++) {
     if (!IsTesting() && !IsExpertEnabled() || IsStopped()) {
        Print("SetOrder(): ???à?îâêà ?à?î?û ô??ê?èè");
        break;
     }
     while (!IsTradeAllowed()) Sleep(5000);
     RefreshRates();
     l_datetime_64 = TimeCurrent();
     l_ticket_100 = OrderSend(a_symbol_0, a_cmd_8, a_lots_12, a_price_20, Slippage, a_price_28, a_price_36, a_comment_52, a_magic_44, a_datetime_48, l_color_60);
     if (l_ticket_100 > 0) return (l_ticket_100);
     l_error_92 = GetLastError();
     if (l_error_92 == 128/* TRADE_TIMEOUT */ || l_error_92 == 142 || l_error_92 == 143) {
        Sleep(66000);
        if (ExistOrders(a_symbol_0, a_cmd_8, a_magic_44, l_datetime_64)) break;
     } else {
        l_point_84 = MarketInfo(a_symbol_0, MODE_POINT);
        l_ask_68 = MarketInfo(a_symbol_0, MODE_ASK);
        l_bid_76 = MarketInfo(a_symbol_0, MODE_BID);
        if (l_ask_68 == 0.0 && l_bid_76 == 0.0) Comment("SetOrder(): ??îâ??ü?? â î?çî?? ?û?êà ?àëè÷è? ?è?âîëà " + a_symbol_0);
        if (l_error_92 == 130/* INVALID_STOPS */) {
           switch (a_cmd_8) {
           case OP_SELLSTOP:
              if (a_price_20 > l_ask_68 - l_stoplevel_104 * l_point_84) a_price_20 = l_ask_68 - l_stoplevel_104 * l_point_84;
              if (a_price_28 > a_price_20 - (l_stoplevel_104 + 1) * l_point_84) a_price_28 = a_price_20 - (l_stoplevel_104 + 1) * l_point_84;
              if (a_price_36 > 0.0 && a_price_36 < a_price_20 + (l_stoplevel_104 + 1) * l_point_84) a_price_36 = a_price_20 + (l_stoplevel_104 + 1) * l_point_84;
              break;
           case OP_SELLLIMIT:
              if (a_price_20 < l_ask_68 + (l_stoplevel_104 + 1) * l_point_84) a_price_20 = l_ask_68 + (l_stoplevel_104 + 1) * l_point_84;
              if (a_price_28 > a_price_20 - (l_stoplevel_104 + 1) * l_point_84) a_price_28 = a_price_20 - (l_stoplevel_104 + 1) * l_point_84;
              if (a_price_36 > 0.0 && a_price_36 < a_price_20 + (l_stoplevel_104 + 1) * l_point_84) a_price_36 = a_price_20 + (l_stoplevel_104 + 1) * l_point_84;
              break;
           case OP_BUYSTOP:
              if (a_price_20 < l_bid_76 + l_stoplevel_104 * l_point_84) a_price_20 = l_bid_76 + l_stoplevel_104 * l_point_84;
              if (a_price_28 > 0.0 && a_price_28 < a_price_20 + (l_stoplevel_104 + 1) * l_point_84) a_price_28 = a_price_20 + (l_stoplevel_104 + 1) * l_point_84;
              if (a_price_36 > a_price_20 - (l_stoplevel_104 + 1) * l_point_84) a_price_36 = a_price_20 - (l_stoplevel_104 + 1) * l_point_84;
              break;
           case OP_BUYLIMIT:
              if (a_price_20 > l_bid_76 - l_stoplevel_104 * l_point_84) a_price_20 = l_bid_76 - l_stoplevel_104 * l_point_84;
              if (a_price_28 > 0.0 && a_price_28 < a_price_20 + (l_stoplevel_104 + 1) * l_point_84) a_price_28 = a_price_20 + (l_stoplevel_104 + 1) * l_point_84;
              if (a_price_36 > a_price_20 - (l_stoplevel_104 + 1) * l_point_84) a_price_36 = a_price_20 - (l_stoplevel_104 + 1) * l_point_84;
           }
           Print("SetOrder(): ?êî???ê?è?îâà?û ???îâû? ??îâ?è");
        }
        if (l_error_92 == 2/* COMMON_ERROR */ || l_error_92 == 64/* ACCOUNT_DISABLED */ || l_error_92 == 65/* INVALID_ACCOUNT */ || l_error_92 == 133/* TRADE_DISABLED */) break;
        if (l_error_92 == 4/* SERVER_BUSY */ || l_error_92 == 131/* INVALID_TRADE_VOLUME */ || l_error_92 == 132/* MARKET_CLOSED */) {
           Sleep(300000);
           break;
        }
        if (l_error_92 == 8/* TOO_FREQUENT_REQUESTS */ || l_error_92 == 141/* TOO_MANY_REQUESTS */) Sleep(100000);
        if (l_error_92 == 139/* ORDER_LOCKED */ || l_error_92 == 140/* LONG_POSITIONS_ONLY_ALLOWED */ || l_error_92 == 148/* ERR_TRADE_TOO_MANY_ORDERS */) break;
        if (l_error_92 == 146/* TRADE_CONTEXT_BUSY */) while (IsTradeContextBusy()) Sleep(11000);
        if (l_error_92 == 147/* ERR_TRADE_EXPIRATION_DENIED */) a_datetime_48 = 0;
        else
           if (l_error_92 != 135/* PRICE_CHANGED */ && l_error_92 != 138/* REQUOTE */) Sleep(7700.0);
     }
  }
  return (0);
}

bool ExistOrders(string as_0 = "", int a_cmd_8 = -1, int a_magic_12 = -1, int ai_16 = 0, double ad_20 = 0.0) {
  int l_cmd_36;
  int l_ord_total_32 = OrdersTotal();
  if (as_0 == "0") as_0 = Symbol();
  for (int l_pos_28 = 0; l_pos_28 < l_ord_total_32; l_pos_28++) {
     if (OrderSelect(l_pos_28, SELECT_BY_POS, MODE_TRADES)) {
        l_cmd_36 = OrderType();
        if (l_cmd_36 > OP_SELL && l_cmd_36 < 6) {
           if (OrderSymbol() == as_0 || as_0 == "" && a_cmd_8 < OP_BUY || l_cmd_36 == a_cmd_8) {
              if (a_magic_12 < 0 || OrderMagicNumber() == a_magic_12) {
                 if (ai_16 <= OrderOpenTime()) {
                    if (ad_20 != 0.0)
                       if (NormalizeDouble(ad_20, Digits) == NormalizeDouble(OrderOpenPrice(), Digits)) return (TRUE);
                 }
              }
           }
        }
     }
  }
  return (FALSE);
}

void Filewrite(double ad_0 = 0.0) {
  int l_file_8 = FileOpen(File_Name, FILE_CSV|FILE_WRITE, ";");
  if (l_file_8 == -1) {
     Print("??è?êà ï?è î?ê?û?èè ôàéëà. ", "?îç?î??î, ôàéë çà??? ????è? ï?èëî???è??");
     return;
  }
  int li_12 = FileWrite(l_file_8, ad_0);
  if (li_12 < 0) {
     Print("??è?êà çàïè?è â ôàéë ", GetLastError());
     FileClose(l_file_8);
     return;
  }
  FileClose(l_file_8);
}

double Fileread() {
  int l_file_0 = FileOpen(File_Name, FILE_CSV|FILE_READ, ";");
  if (l_file_0 == -1) {
     Print("?àéë ëè?î çà???,ëè?î ??î ?? ??ù???â???, . ", "?îç?à?? ôàéë ?àé???à");
     Filewrite(Ask);
     return (Ask);
  }
  double ld_ret_4 = FileReadDouble(l_file_0);
  if (ld_ret_4 < 0.0) {
     Print("??è?êà ÷???è? èç ôàéëà ", GetLastError());
     return ((l_file_0));
  }
  FileClose(l_file_0);
  return (ld_ret_4);
} 

[spoiler:26ukmy10]Never trust, never fear, never beg[/spoiler:26ukmy10]
Link to comment
Share on other sites

Re: all coders are invited

 

@Cyrillic

thank you so much for trying...but its still the same..... #:-S

 

-- 30 Nov 2009, 16:28 --

 

at least can any one add a time filter for this please....

 

Hi deadsoul,

 

Good day,

 

This is system away harder than I thought, but I'm still trying.

 

I have to learn all these kind of stuff.

 

O.K, what kind of time filter?? is it Days or working time filter??

 

Please let me know.

 

Best wishes,

a New Year 2011 has come, and the challenge has just started 8-)
Link to comment
Share on other sites

Re: [Req] Need to Reverse this system

 

extern int PercentEquityToClose = 10;
extern int Dist = 500;
extern int TP = 500;
extern int SL = 500;
extern int kolOrder = 10;
extern double Lots = 0.1;
extern int Slippage = 1;
extern int Magic = 1;
extern bool TrailingProfit = TRUE;
extern int prchoose = 0;
extern int TrailingStop = 0;
extern string File_Name = "Ask.csv";
extern bool UseTimeFilter=false;
extern int StopTrade = 18;
extern int StartTrade = 19;
bool gi_unused_132 = FALSE;
double gd_136;
double gd_144;
double gd_152;
double gd_172;

int init() {
  gd_172 = AccountBalance();
  if (IsTesting() || IsOptimization()) gd_152 = Ask;
  else gd_152 = Fileread();
  return (0);
}

int start() {

    if (UseTimeFilter)
    {//check trading time
       if (Hour()>StopTrade && Hour()<StartTrade) 
       {Comment("No trading, danger time zone!");
       return(0);}//End of trading time check

  int li_0 = Dist;
  for (int li_4 = 1; li_4 <= kolOrder; li_4++) {
     if (SL > 0) gd_136 = gd_152 + li_0 * Point - SL * Point;
     else gd_136 = 0;
     if (TP > 0) gd_144 = gd_152 + li_0 * Point + TP * Point;
     else gd_144 = 0;
     if (!ExistOrders("", OP_BUYSTOP, Magic, 0, NormalizeDouble(gd_152 + li_0 * Point, Digits))) SetOrder("", OP_BUYSTOP, Lots, gd_152 + li_0 * Point, gd_136, gd_144, Magic);
     if (SL > 0) gd_136 = gd_152 - li_0 * Point + SL * Point;
     else gd_136 = 0;
     if (TP > 0) gd_144 = gd_152 - li_0 * Point - TP * Point;
     else gd_144 = 0;
     if (!ExistOrders("", OP_SELLSTOP, Magic, 0, NormalizeDouble(gd_152 - li_0 * Point, Digits))) SetOrder("", OP_SELLSTOP, Lots, gd_152 - li_0 * Point, gd_136, gd_144, Magic);
     li_0 += Dist;
  }
  if (gd_152 + Dist * Point < Ask) gd_152 += Dist * Point;
  if (gd_152 - Dist * Point > Ask) gd_152 -= Dist * Point;
  if (TrailingProfit) TProf();
  if (PercentEquityToClose != 0) {
     if (gd_172 / 100.0 * PercentEquityToClose + gd_172 <= AccountEquity()) {
        CPD("", -1, Magic);
        gd_172 = AccountBalance();
     }
  }
  return (0);
}

void CPBS() {
  bool l_ord_close_0;
  color l_color_4;
  double l_ord_lots_8;
  double l_ask_16;
  double l_bid_24;
  double l_price_32;
  int l_error_40;
  if (OrderType() == OP_BUY || OrderType() == OP_SELL) {
     for (int li_44 = 1; li_44 <= 1; li_44++) {
        if (!IsTesting() && !IsExpertEnabled() || IsStopped()) break;
        while (!IsTradeAllowed()) Sleep(5000);
        RefreshRates();
        l_ask_16 = MarketInfo(OrderSymbol(), MODE_ASK);
        l_bid_24 = MarketInfo(OrderSymbol(), MODE_BID);
        if (OrderType() == OP_BUY) l_price_32 = l_bid_24;
        else l_price_32 = l_ask_16;
        l_ord_lots_8 = OrderLots();
        l_ord_close_0 = OrderClose(OrderTicket(), l_ord_lots_8, l_price_32, Slippage, l_color_4);
        if (l_ord_close_0) break;
        l_error_40 = GetLastError();
        if (l_error_40 == 146/* TRADE_CONTEXT_BUSY */) while (IsTradeContextBusy()) Sleep(11000);
        Sleep(5000);
     }
  }
}

void CPD(string as_0 = "", int a_cmd_8 = -1, int a_magic_12 = -1) {
  int l_ord_total_20 = OrdersTotal();
  if (as_0 == "0") as_0 = Symbol();
  for (int l_pos_16 = l_ord_total_20 - 1; l_pos_16 >= 0; l_pos_16--) {
     if (OrderSelect(l_pos_16, SELECT_BY_POS, MODE_TRADES)) {
        if (OrderSymbol() == as_0 || as_0 == "" && a_cmd_8 < OP_BUY || OrderType() == a_cmd_8) {
           if (OrderType() == OP_BUY || OrderType() == OP_SELL)
              if (a_magic_12 < 0 || OrderMagicNumber() == a_magic_12) CPBS();
        }
     }
  }
}

void TProf() {
  int l_cmd_4;
  double l_price_8;
  double ld_16;
  bool li_24;
  double l_ord_open_price_32;
  int l_ticket_40;
  bool l_bool_44;
  if (prchoose == 0) prchoose = MarketInfo(Symbol(), MODE_STOPLEVEL);
  for (int li_0 = 1; li_0 <= OrdersTotal(); li_0++) {
     if (OrderSelect(li_0 - 1, SELECT_BY_POS) == TRUE) {
        l_cmd_4 = OrderType();
        l_price_8 = OrderStopLoss();
        while (true) {
           if (TrailingStop == 0) TrailingStop = MarketInfo(Symbol(), MODE_STOPLEVEL);
           ld_16 = TrailingStop;
           li_24 = FALSE;
           switch (l_cmd_4) {
           case OP_BUY:
              if (NormalizeDouble(l_price_8, Digits) < NormalizeDouble(Bid - ld_16 * Point, Digits) && MarketInfo(OrderSymbol(), MODE_BID) - OrderOpenPrice() >= prchoose * Point) {
                 l_price_8 = Bid - ld_16 * Point;
                 li_24 = TRUE;
              }
              break;
           case OP_SELL:
              if (NormalizeDouble(l_price_8, Digits) > NormalizeDouble(Ask + ld_16 * Point, Digits) || NormalizeDouble(l_price_8, Digits) == 0.0 && OrderOpenPrice() - MarketInfo(OrderSymbol(), MODE_ASK) >= prchoose * Point) {
                 l_price_8 = Ask + ld_16 * Point;
                 li_24 = TRUE;
              }
           }
           if (li_24 == FALSE) break;
           l_ord_open_price_32 = OrderOpenPrice();
           l_ticket_40 = OrderTicket();
           l_bool_44 = OrderModify(l_ticket_40, l_ord_open_price_32, l_price_8, OrderTakeProfit(), 0, Green);
           if (l_bool_44 != TRUE) continue;
           break;
        }
     }
  }
}

int SetOrder(string a_symbol_0, int a_cmd_8, double a_lots_12, double a_price_20, double a_price_28 = 0.0, double a_price_36 = 0.0, int a_magic_44 = 0, int a_datetime_48 = 0, string a_comment_52 = "") {
  color l_color_60;
  int l_datetime_64;
  double l_ask_68;
  double l_bid_76;
  double l_point_84;
  int l_error_92;
  int l_ticket_100;
  if (a_symbol_0 == "" || a_symbol_0 == "0") a_symbol_0 = Symbol();
  int l_stoplevel_104 = MarketInfo(a_symbol_0, MODE_STOPLEVEL);
  if (a_datetime_48 > 0 && a_datetime_48 < TimeCurrent()) a_datetime_48 = 0;
  for (int li_96 = 1; li_96 <= 1; li_96++) {
     if (!IsTesting() && !IsExpertEnabled() || IsStopped()) {
        Print("SetOrder(): ???à?îâêà ?à?î?û ô??ê?èè");
        break;
     }
     while (!IsTradeAllowed()) Sleep(5000);
     RefreshRates();
     l_datetime_64 = TimeCurrent();
     l_ticket_100 = OrderSend(a_symbol_0, a_cmd_8, a_lots_12, a_price_20, Slippage, a_price_28, a_price_36, a_comment_52, a_magic_44, a_datetime_48, l_color_60);
     if (l_ticket_100 > 0) return (l_ticket_100);
     l_error_92 = GetLastError();
     if (l_error_92 == 128/* TRADE_TIMEOUT */ || l_error_92 == 142 || l_error_92 == 143) {
        Sleep(66000);
        if (ExistOrders(a_symbol_0, a_cmd_8, a_magic_44, l_datetime_64)) break;
     } else {
        l_point_84 = MarketInfo(a_symbol_0, MODE_POINT);
        l_ask_68 = MarketInfo(a_symbol_0, MODE_ASK);
        l_bid_76 = MarketInfo(a_symbol_0, MODE_BID);
        if (l_ask_68 == 0.0 && l_bid_76 == 0.0) Comment("SetOrder(): ??îâ??ü?? â î?çî?? ?û?êà ?àëè÷è? ?è?âîëà " + a_symbol_0);
        if (l_error_92 == 130/* INVALID_STOPS */) {
           switch (a_cmd_8) {
           case OP_BUYLIMIT:
              if (a_price_20 > l_ask_68 - l_stoplevel_104 * l_point_84) a_price_20 = l_ask_68 - l_stoplevel_104 * l_point_84;
              if (a_price_28 > a_price_20 - (l_stoplevel_104 + 1) * l_point_84) a_price_28 = a_price_20 - (l_stoplevel_104 + 1) * l_point_84;
              if (a_price_36 > 0.0 && a_price_36 < a_price_20 + (l_stoplevel_104 + 1) * l_point_84) a_price_36 = a_price_20 + (l_stoplevel_104 + 1) * l_point_84;
              break;
           case OP_BUYSTOP:
              if (a_price_20 < l_ask_68 + (l_stoplevel_104 + 1) * l_point_84) a_price_20 = l_ask_68 + (l_stoplevel_104 + 1) * l_point_84;
              if (a_price_28 > a_price_20 - (l_stoplevel_104 + 1) * l_point_84) a_price_28 = a_price_20 - (l_stoplevel_104 + 1) * l_point_84;
              if (a_price_36 > 0.0 && a_price_36 < a_price_20 + (l_stoplevel_104 + 1) * l_point_84) a_price_36 = a_price_20 + (l_stoplevel_104 + 1) * l_point_84;
              break;
           case OP_SELLLIMIT:
              if (a_price_20 < l_bid_76 + l_stoplevel_104 * l_point_84) a_price_20 = l_bid_76 + l_stoplevel_104 * l_point_84;
              if (a_price_28 > 0.0 && a_price_28 < a_price_20 + (l_stoplevel_104 + 1) * l_point_84) a_price_28 = a_price_20 + (l_stoplevel_104 + 1) * l_point_84;
              if (a_price_36 > a_price_20 - (l_stoplevel_104 + 1) * l_point_84) a_price_36 = a_price_20 - (l_stoplevel_104 + 1) * l_point_84;
              break;
           case OP_SELLSTOP:
              if (a_price_20 > l_bid_76 - l_stoplevel_104 * l_point_84) a_price_20 = l_bid_76 - l_stoplevel_104 * l_point_84;
              if (a_price_28 > 0.0 && a_price_28 < a_price_20 + (l_stoplevel_104 + 1) * l_point_84) a_price_28 = a_price_20 + (l_stoplevel_104 + 1) * l_point_84;
              if (a_price_36 > a_price_20 - (l_stoplevel_104 + 1) * l_point_84) a_price_36 = a_price_20 - (l_stoplevel_104 + 1) * l_point_84;
           }
           Print("SetOrder(): ?êî???ê?è?îâà?û ???îâû? ??îâ?è");
        }
        if (l_error_92 == 2/* COMMON_ERROR */ || l_error_92 == 64/* ACCOUNT_DISABLED */ || l_error_92 == 65/* INVALID_ACCOUNT */ || l_error_92 == 133/* TRADE_DISABLED */) break;
        if (l_error_92 == 4/* SERVER_BUSY */ || l_error_92 == 131/* INVALID_TRADE_VOLUME */ || l_error_92 == 132/* MARKET_CLOSED */) {
           Sleep(300000);
           break;
        }
        if (l_error_92 == 8/* TOO_FREQUENT_REQUESTS */ || l_error_92 == 141/* TOO_MANY_REQUESTS */) Sleep(100000);
        if (l_error_92 == 139/* ORDER_LOCKED */ || l_error_92 == 140/* LONG_POSITIONS_ONLY_ALLOWED */ || l_error_92 == 148/* ERR_TRADE_TOO_MANY_ORDERS */) break;
        if (l_error_92 == 146/* TRADE_CONTEXT_BUSY */) while (IsTradeContextBusy()) Sleep(11000);
        if (l_error_92 == 147/* ERR_TRADE_EXPIRATION_DENIED */) a_datetime_48 = 0;
        else
           if (l_error_92 != 135/* PRICE_CHANGED */ && l_error_92 != 138/* REQUOTE */) Sleep(7700.0);
     }
  }
  return (0);
}

bool ExistOrders(string as_0 = "", int a_cmd_8 = -1, int a_magic_12 = -1, int ai_16 = 0, double ad_20 = 0.0) {
  int l_cmd_36;
  int l_ord_total_32 = OrdersTotal();
  if (as_0 == "0") as_0 = Symbol();
  for (int l_pos_28 = 0; l_pos_28 < l_ord_total_32; l_pos_28++) {
     if (OrderSelect(l_pos_28, SELECT_BY_POS, MODE_TRADES)) {
        l_cmd_36 = OrderType();
        if (l_cmd_36 > OP_SELL && l_cmd_36 < 6) {
           if (OrderSymbol() == as_0 || as_0 == "" && a_cmd_8 < OP_BUY || l_cmd_36 == a_cmd_8) {
              if (a_magic_12 < 0 || OrderMagicNumber() == a_magic_12) {
                 if (ai_16 <= OrderOpenTime()) {
                    if (ad_20 != 0.0)
                       if (NormalizeDouble(ad_20, Digits) == NormalizeDouble(OrderOpenPrice(), Digits)) return (TRUE);
                 }
              }
           }
        }
     }
  }
  return (FALSE);
}

void Filewrite(double ad_0 = 0.0) {
  int l_file_8 = FileOpen(File_Name, FILE_CSV|FILE_WRITE, ";");
  if (l_file_8 == -1) {
     Print("??è?êà ï?è î?ê?û?èè ôàéëà. ", "?îç?î??î, ôàéë çà??? ????è? ï?èëî???è??");
     return;
  }
  int li_12 = FileWrite(l_file_8, ad_0);
  if (li_12 < 0) {
     Print("??è?êà çàïè?è â ôàéë ", GetLastError());
     FileClose(l_file_8);
     return;
  }
  FileClose(l_file_8);
}

double Fileread() {
  int l_file_0 = FileOpen(File_Name, FILE_CSV|FILE_READ, ";");
  if (l_file_0 == -1) {
     Print("?àéë ëè?î çà???,ëè?î ??î ?? ??ù???â???, . ", "?îç?à?? ôàéë ?àé???à");
     Filewrite(Ask);
     return (Ask);
  }
  double ld_ret_4 = FileReadDouble(l_file_0);
  if (ld_ret_4 < 0.0) {
     Print("??è?êà ÷???è? èç ôàéëà ", GetLastError());
     return ((l_file_0));
  }
  FileClose(l_file_0);
  return (ld_ret_4);
}

 

Hi Deadsoul,

 

Good day,

 

I added the time filter and I hope it is going to be working. I've not tried it yet, but if there is any problem, please let me know.

 

Best wishes,

a New Year 2011 has come, and the challenge has just started 8-)
Link to comment
Share on other sites

Re: [Req] Need to Reverse this system

 

Hi deadsoul,

 

Good day,

 

This is the code including new different time filter. I hope it is going to be working ;) .

 

Best wishes,

 

extern int PercentEquityToClose = 10;
extern int Dist = 500;
extern int TP = 500;
extern int SL = 500;
extern int StartHour = 22;
extern int StopHour = 2;
extern int kolOrder = 10;
extern double Lots = 0.1;
extern int Slippage = 1;
extern int Magic = 1;
extern bool TrailingProfit = TRUE;
extern int prchoose = 0;
extern int TrailingStop = 0;
extern string File_Name = "Ask.csv";
bool gi_unused_132 = FALSE;
double gd_136;
double gd_144;
double gd_152;
double gd_172;

int init() {
  gd_172 = AccountBalance();
  if (IsTesting() || IsOptimization()) gd_152 = Ask;
  else gd_152 = Fileread();
  return (0);
}

int start() {

if (!IsTradingTime()) return (0);

  int li_0 = Dist;
  for (int li_4 = 1; li_4 <= kolOrder; li_4++) {
     if (SL > 0) gd_136 = gd_152 + li_0 * Point - SL * Point;
     else gd_136 = 0;
     if (TP > 0) gd_144 = gd_152 + li_0 * Point + TP * Point;
     else gd_144 = 0;
     if (!ExistOrders("", OP_BUYSTOP, Magic, 0, NormalizeDouble(gd_152 + li_0 * Point, Digits))) SetOrder("", OP_BUYSTOP, Lots, gd_152 + li_0 * Point, gd_136, gd_144, Magic);
     if (SL > 0) gd_136 = gd_152 - li_0 * Point + SL * Point;
     else gd_136 = 0;
     if (TP > 0) gd_144 = gd_152 - li_0 * Point - TP * Point;
     else gd_144 = 0;
     if (!ExistOrders("", OP_SELLSTOP, Magic, 0, NormalizeDouble(gd_152 - li_0 * Point, Digits))) SetOrder("", OP_SELLSTOP, Lots, gd_152 - li_0 * Point, gd_136, gd_144, Magic);
     li_0 += Dist;
  }
  if (gd_152 + Dist * Point < Ask) gd_152 += Dist * Point;
  if (gd_152 - Dist * Point > Ask) gd_152 -= Dist * Point;
  if (TrailingProfit) TProf();
  if (PercentEquityToClose != 0) {
     if (gd_172 / 100.0 * PercentEquityToClose + gd_172 <= AccountEquity()) {
        CPD("", -1, Magic);
        gd_172 = AccountBalance();
     }
  }
  return (0);
}

void CPBS() {
  bool l_ord_close_0;
  color l_color_4;
  double l_ord_lots_8;
  double l_ask_16;
  double l_bid_24;
  double l_price_32;
  int l_error_40;
  if (OrderType() == OP_BUY || OrderType() == OP_SELL) {
     for (int li_44 = 1; li_44 <= 1; li_44++) {
        if (!IsTesting() && !IsExpertEnabled() || IsStopped()) break;
        while (!IsTradeAllowed()) Sleep(5000);
        RefreshRates();
        l_ask_16 = MarketInfo(OrderSymbol(), MODE_ASK);
        l_bid_24 = MarketInfo(OrderSymbol(), MODE_BID);
        if (OrderType() == OP_BUY) l_price_32 = l_bid_24;
        else l_price_32 = l_ask_16;
        l_ord_lots_8 = OrderLots();
        l_ord_close_0 = OrderClose(OrderTicket(), l_ord_lots_8, l_price_32, Slippage, l_color_4);
        if (l_ord_close_0) break;
        l_error_40 = GetLastError();
        if (l_error_40 == 146/* TRADE_CONTEXT_BUSY */) while (IsTradeContextBusy()) Sleep(11000);
        Sleep(5000);
     }
  }
}

void CPD(string as_0 = "", int a_cmd_8 = -1, int a_magic_12 = -1) {
  int l_ord_total_20 = OrdersTotal();
  if (as_0 == "0") as_0 = Symbol();
  for (int l_pos_16 = l_ord_total_20 - 1; l_pos_16 >= 0; l_pos_16--) {
     if (OrderSelect(l_pos_16, SELECT_BY_POS, MODE_TRADES)) {
        if (OrderSymbol() == as_0 || as_0 == "" && a_cmd_8 < OP_BUY || OrderType() == a_cmd_8) {
           if (OrderType() == OP_BUY || OrderType() == OP_SELL)
              if (a_magic_12 < 0 || OrderMagicNumber() == a_magic_12) CPBS();
        }
     }
  }
}

void TProf() {
  int l_cmd_4;
  double l_price_8;
  double ld_16;
  bool li_24;
  double l_ord_open_price_32;
  int l_ticket_40;
  bool l_bool_44;
  if (prchoose == 0) prchoose = MarketInfo(Symbol(), MODE_STOPLEVEL);
  for (int li_0 = 1; li_0 <= OrdersTotal(); li_0++) {
     if (OrderSelect(li_0 - 1, SELECT_BY_POS) == TRUE) {
        l_cmd_4 = OrderType();
        l_price_8 = OrderStopLoss();
        while (true) {
           if (TrailingStop == 0) TrailingStop = MarketInfo(Symbol(), MODE_STOPLEVEL);
           ld_16 = TrailingStop;
           li_24 = FALSE;
           switch (l_cmd_4) {
           case OP_BUY:
              if (NormalizeDouble(l_price_8, Digits) < NormalizeDouble(Bid - ld_16 * Point, Digits) && MarketInfo(OrderSymbol(), MODE_BID) - OrderOpenPrice() >= prchoose * Point) {
                 l_price_8 = Bid - ld_16 * Point;
                 li_24 = TRUE;
              }
              break;
           case OP_SELL:
              if (NormalizeDouble(l_price_8, Digits) > NormalizeDouble(Ask + ld_16 * Point, Digits) || NormalizeDouble(l_price_8, Digits) == 0.0 && OrderOpenPrice() - MarketInfo(OrderSymbol(), MODE_ASK) >= prchoose * Point) {
                 l_price_8 = Ask + ld_16 * Point;
                 li_24 = TRUE;
              }
           }
           if (li_24 == FALSE) break;
           l_ord_open_price_32 = OrderOpenPrice();
           l_ticket_40 = OrderTicket();
           l_bool_44 = OrderModify(l_ticket_40, l_ord_open_price_32, l_price_8, OrderTakeProfit(), 0, Green);
           if (l_bool_44 != TRUE) continue;
           break;
        }
     }
  }
}

int SetOrder(string a_symbol_0, int a_cmd_8, double a_lots_12, double a_price_20, double a_price_28 = 0.0, double a_price_36 = 0.0, int a_magic_44 = 0, int a_datetime_48 = 0, string a_comment_52 = "") {
  color l_color_60;
  int l_datetime_64;
  double l_ask_68;
  double l_bid_76;
  double l_point_84;
  int l_error_92;
  int l_ticket_100;
  if (a_symbol_0 == "" || a_symbol_0 == "0") a_symbol_0 = Symbol();
  int l_stoplevel_104 = MarketInfo(a_symbol_0, MODE_STOPLEVEL);
  if (a_datetime_48 > 0 && a_datetime_48 < TimeCurrent()) a_datetime_48 = 0;
  for (int li_96 = 1; li_96 <= 1; li_96++) {
     if (!IsTesting() && !IsExpertEnabled() || IsStopped()) {
        Print("SetOrder(): ???à?îâêà ?à?î?û ô??ê?èè");
        break;
     }
     while (!IsTradeAllowed()) Sleep(5000);
     RefreshRates();
     l_datetime_64 = TimeCurrent();
     l_ticket_100 = OrderSend(a_symbol_0, a_cmd_8, a_lots_12, a_price_20, Slippage, a_price_28, a_price_36, a_comment_52, a_magic_44, a_datetime_48, l_color_60);
     if (l_ticket_100 > 0) return (l_ticket_100);
     l_error_92 = GetLastError();
     if (l_error_92 == 128/* TRADE_TIMEOUT */ || l_error_92 == 142 || l_error_92 == 143) {
        Sleep(66000);
        if (ExistOrders(a_symbol_0, a_cmd_8, a_magic_44, l_datetime_64)) break;
     } else {
        l_point_84 = MarketInfo(a_symbol_0, MODE_POINT);
        l_ask_68 = MarketInfo(a_symbol_0, MODE_ASK);
        l_bid_76 = MarketInfo(a_symbol_0, MODE_BID);
        if (l_ask_68 == 0.0 && l_bid_76 == 0.0) Comment("SetOrder(): ??îâ??ü?? â î?çî?? ?û?êà ?àëè÷è? ?è?âîëà " + a_symbol_0);
        if (l_error_92 == 130/* INVALID_STOPS */) {
           switch (a_cmd_8) {
           case OP_BUYLIMIT:
              if (a_price_20 > l_ask_68 - l_stoplevel_104 * l_point_84) a_price_20 = l_ask_68 - l_stoplevel_104 * l_point_84;
              if (a_price_28 > a_price_20 - (l_stoplevel_104 + 1) * l_point_84) a_price_28 = a_price_20 - (l_stoplevel_104 + 1) * l_point_84;
              if (a_price_36 > 0.0 && a_price_36 < a_price_20 + (l_stoplevel_104 + 1) * l_point_84) a_price_36 = a_price_20 + (l_stoplevel_104 + 1) * l_point_84;
              break;
           case OP_BUYSTOP:
              if (a_price_20 < l_ask_68 + (l_stoplevel_104 + 1) * l_point_84) a_price_20 = l_ask_68 + (l_stoplevel_104 + 1) * l_point_84;
              if (a_price_28 > a_price_20 - (l_stoplevel_104 + 1) * l_point_84) a_price_28 = a_price_20 - (l_stoplevel_104 + 1) * l_point_84;
              if (a_price_36 > 0.0 && a_price_36 < a_price_20 + (l_stoplevel_104 + 1) * l_point_84) a_price_36 = a_price_20 + (l_stoplevel_104 + 1) * l_point_84;
              break;
           case OP_SELLLIMIT:
              if (a_price_20 < l_bid_76 + l_stoplevel_104 * l_point_84) a_price_20 = l_bid_76 + l_stoplevel_104 * l_point_84;
              if (a_price_28 > 0.0 && a_price_28 < a_price_20 + (l_stoplevel_104 + 1) * l_point_84) a_price_28 = a_price_20 + (l_stoplevel_104 + 1) * l_point_84;
              if (a_price_36 > a_price_20 - (l_stoplevel_104 + 1) * l_point_84) a_price_36 = a_price_20 - (l_stoplevel_104 + 1) * l_point_84;
              break;
           case OP_SELLSTOP:
              if (a_price_20 > l_bid_76 - l_stoplevel_104 * l_point_84) a_price_20 = l_bid_76 - l_stoplevel_104 * l_point_84;
              if (a_price_28 > 0.0 && a_price_28 < a_price_20 + (l_stoplevel_104 + 1) * l_point_84) a_price_28 = a_price_20 + (l_stoplevel_104 + 1) * l_point_84;
              if (a_price_36 > a_price_20 - (l_stoplevel_104 + 1) * l_point_84) a_price_36 = a_price_20 - (l_stoplevel_104 + 1) * l_point_84;
           }
           Print("SetOrder(): ?êî???ê?è?îâà?û ???îâû? ??îâ?è");
        }
        if (l_error_92 == 2/* COMMON_ERROR */ || l_error_92 == 64/* ACCOUNT_DISABLED */ || l_error_92 == 65/* INVALID_ACCOUNT */ || l_error_92 == 133/* TRADE_DISABLED */) break;
        if (l_error_92 == 4/* SERVER_BUSY */ || l_error_92 == 131/* INVALID_TRADE_VOLUME */ || l_error_92 == 132/* MARKET_CLOSED */) {
           Sleep(300000);
           break;
        }
        if (l_error_92 == 8/* TOO_FREQUENT_REQUESTS */ || l_error_92 == 141/* TOO_MANY_REQUESTS */) Sleep(100000);
        if (l_error_92 == 139/* ORDER_LOCKED */ || l_error_92 == 140/* LONG_POSITIONS_ONLY_ALLOWED */ || l_error_92 == 148/* ERR_TRADE_TOO_MANY_ORDERS */) break;
        if (l_error_92 == 146/* TRADE_CONTEXT_BUSY */) while (IsTradeContextBusy()) Sleep(11000);
        if (l_error_92 == 147/* ERR_TRADE_EXPIRATION_DENIED */) a_datetime_48 = 0;
        else
           if (l_error_92 != 135/* PRICE_CHANGED */ && l_error_92 != 138/* REQUOTE */) Sleep(7700.0);
     }
  }
  return (0);
}

bool ExistOrders(string as_0 = "", int a_cmd_8 = -1, int a_magic_12 = -1, int ai_16 = 0, double ad_20 = 0.0) {
  int l_cmd_36;
  int l_ord_total_32 = OrdersTotal();
  if (as_0 == "0") as_0 = Symbol();
  for (int l_pos_28 = 0; l_pos_28 < l_ord_total_32; l_pos_28++) {
     if (OrderSelect(l_pos_28, SELECT_BY_POS, MODE_TRADES)) {
        l_cmd_36 = OrderType();
        if (l_cmd_36 > OP_SELL && l_cmd_36 < 6) {
           if (OrderSymbol() == as_0 || as_0 == "" && a_cmd_8 < OP_BUY || l_cmd_36 == a_cmd_8) {
              if (a_magic_12 < 0 || OrderMagicNumber() == a_magic_12) {
                 if (ai_16 <= OrderOpenTime()) {
                    if (ad_20 != 0.0)
                       if (NormalizeDouble(ad_20, Digits) == NormalizeDouble(OrderOpenPrice(), Digits)) return (TRUE);
                 }
              }
           }
        }
     }
  }
  return (FALSE);
}

void Filewrite(double ad_0 = 0.0) {
  int l_file_8 = FileOpen(File_Name, FILE_CSV|FILE_WRITE, ";");
  if (l_file_8 == -1) {
     Print("??è?êà ï?è î?ê?û?èè ôàéëà. ", "?îç?î??î, ôàéë çà??? ????è? ï?èëî???è??");
     return;
  }
  int li_12 = FileWrite(l_file_8, ad_0);
  if (li_12 < 0) {
     Print("??è?êà çàïè?è â ôàéë ", GetLastError());
     FileClose(l_file_8);
     return;
  }
  FileClose(l_file_8);
}

double Fileread() {
  int l_file_0 = FileOpen(File_Name, FILE_CSV|FILE_READ, ";");
  if (l_file_0 == -1) {
     Print("?àéë ëè?î çà???,ëè?î ??î ?? ??ù???â???, . ", "?îç?à?? ôàéë ?àé???à");
     Filewrite(Ask);
     return (Ask);
  }
  double ld_ret_4 = FileReadDouble(l_file_0);
  if (ld_ret_4 < 0.0) {
     Print("??è?êà ÷???è? èç ôàéëà ", GetLastError());
     return ((l_file_0));
  }
  FileClose(l_file_0);
  return (ld_ret_4);
}
//---------------------------------------------

//+------------------------------------------------------------------+
//| trading time function                                                                |
//+------------------------------------------------------------------+ 
bool IsTradingTime() 
{
if (DayOfWeek() == 0 || DayOfWeek() == 5) return (False);
if (DayOfWeek() == 1 && Hour() < StartHour) return (False);
if (StartHour < StopHour && (Hour() < StartHour || Hour() >= StopHour)) return (False);
if (StartHour > StopHour && (Hour() < StartHour && Hour() >= StopHour)) return (False);
if (StopHour == 0) StopHour = 24;
if (Hour() == StopHour - 1 && Minute() >= 50) return (False);
return (True);
}

a New Year 2011 has come, and the challenge has just started 8-)
Link to comment
Share on other sites

Re: [Req] Need to Reverse this system

 

@scarface

thank you so much ...the time filter works like magic...i appreciate your efforts with me ...

thanks again bro.... :)>-

 

Hi Deadsoul,

 

Good day,

 

I'm glad to hear that it worked.

 

Now, I try all the times from now on to improve my mql4 skills as fast as possible so I can meet the forum needs.

 

Best wishes,

a New Year 2011 has come, and the challenge has just started 8-)
Link to comment
Share on other sites

  • 3 weeks later...

Re: all coders are invited

 

Hi Guys!

 

Could you help me reversing this one? (a modified version of Ilan)

 

http://www.mediafire.com/?myw4tddmznj

 

It has a reverse option but I can't understand the use... or put it to work!

 

Anyway, the point is to reverse it: when the trigger "says" buy, we sell - and when "says" sell, we buy

.

If possible, I'd like also to add an option to reverse the strategy: usually Ilan versions uses a anti-trend pyramid, and I would like instead, when price goes against us, instead of continue adding lots of same type to the initial entry, I'd like to add inverse type lots.

Meaning: if our initial entry is long and price goes against us, start adding short positions and close all open orders until we have a basketpercent or a basketpips profit. If we are short, do he inverse.

 

Friendly Regards,

 

LV

Link to comment
Share on other sites

Re: all coders are invited

 

Hi Guys!

 

Could you help me reversing this one? (a modified version of Ilan)

 

http://www.mediafire.com/?myw4tddmznj

 

It has a reverse option but I can't understand the use... or put it to work!

 

Anyway, the point is to reverse it: when the trigger "says" buy, we sell - and when "says" sell, we buy

.

If possible, I'd like also to add an option to reverse the strategy: usually Ilan versions uses a anti-trend pyramid, and I would like instead, when price goes against us, instead of continue adding lots of same type to the initial entry, I'd like to add inverse type lots.

Meaning: if our initial entry is long and price goes against us, start adding short positions and close all open orders until we have a basketpercent or a basketpips profit. If we are short, do he inverse.

 

Friendly Regards,

 

LV

 

Hi Lordvader,

 

Good day,

 

Can you kindly upload the EA to another link. I have difficulty downloading the file.

 

Please let me know whenever you do that.

 

Best wishes,

 

-- 23 Dec 2009, 22:36 --

 

 

LV

 

Hi,

 

Good day,

 

I checked the EA and there is no problem with it at all. All you have to do in order to reverse the signals is:

 

change this: ReverseSystem = FALSE TO ReverseSystem = True

 

You can do that from the EA properties window.

 

It works 100%, and if there is any other problem, please let me know.

 

Best wishes,

a New Year 2011 has come, and the challenge has just started 8-)
Link to comment
Share on other sites

Re: all coders are invited

 

Hi Scarface,

 

I've tested it, trying the EA attached to 2 EurUsd M1 charts, with ReverseSystem option disabled in 1st chart and enabled in 2nd chart, and both open a same type order (in this case 2 sell orders) - shouldn't I have one sell and one buy order?

 

Best regards,

 

LV

 

Hi,

 

If you want to verify whether it is working or not, try to backtest it with the Reverse option enabled, and then disabled and check the difference.

 

I will test it now and see whether it works or not.

 

Best wishes,

 

-- 24 Dec 2009, 16:49 --

 

Hi Lordvader,

 

Good day,

 

Look like someone was trying to add the ReverseSystem Function, but couldn't. It was a nice shot.

 

However, it wasn't as complicated as that person thought.

 

Here it is, try it and let me know.

 

I guess there is a slight problem that the 1st Sell position doesn't close and I don't know why.

 

I will check it again whenever I have time.

 

hxxp://xxxx.multiupload.com/KUIARGPEL8

 

 

If there is anything else I can do, please let me know.

 

Best wishes,

a New Year 2011 has come, and the challenge has just started 8-)
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...