BTC USD 75,470.9 Gold USD 4,282.65
Time now: Jun 1, 12:00 AM

Please help me I need help to change expert mt4 to mt5

loveh999

Fun Poster
Messages
114
Joined
Oct 29, 2008
Messages
114
Reaction score
15
Points
15
Hi I need change code expert mt4 to mt5
please help me

Code:
#property copyright "Copyright © 2009, Trader12."
#property link      "Trader12"


extern string  Info = "If Your Broker Allwed Hedge";
extern string  Info_1 = "You Cant Choose BUY & SELL In one Chart";
extern string  Info_2 = "You Must Open Two Chart If Use BUY & SELL In One Time";
extern string  Info_3 = "You Must Change Magic Number If Use BUY & SELL & Pair";
extern bool Tradebuy = true;
extern bool Tradesell = true;
extern double AmountmoneyLose = 10;
extern int magic = 9999;
int gi_80 = 5000;
extern int slipp = 3;
extern int Dalta = 5;
extern string Set_MA_1 = "Moving Average 1";
extern int Period1 = 13;
extern int MA_SHIFT1 = 0;
extern int MA_METHOD1 = 1;
extern string Set_MA_2 = "Moving Average 2";
extern int Period2 = 21;
extern int MA_SHIFT2 = 0;
extern int MA_METHOD2 = 1;
extern string Set_Double = "You Can Choose Lot & Step & Target Profit For 40 Double";
extern double Lot1 = 0.01;
extern int step1 = 200;
extern int TP1 = 200;
extern double Lot2 = 0.01;
extern int step2 = 200;
extern int TP2 = 200;
extern double Lot3 = 0.02;
extern int step3 = 200;
extern int TP3 = 200;
extern double Lot4 = 0.04;
extern int step4 = 200;
extern int TP4 = 200;
extern double Lot5 = 0.08;
extern int step5 = 200;
extern int TP5 = 200;
extern double Lot6 = 0.16;
extern int step6 = 200;
extern int TP6 = 200;
extern double Lot7 = 0.30;
extern int step7 = 200;
extern int TP7 = 200;
extern double Lot8 = 0.60;
extern int step8 = 200;
extern int TP8 = 200;
extern double Lot9 = 0.68;
extern int step9 = 200;
extern int TP9 = 200;
extern double Lot10 = 0.76;
extern int step10 = 20;
extern int TP10 = 30;
extern double Lot11 = 0.84;
extern int step11 = 20;
extern int TP11 = 35;
extern double Lot12 = 0.92;
extern int step12 = 20;
extern int TP12 = 40;
extern double Lot13 = 1.00;
extern int step13 = 20;
extern int TP13 = 45;
extern double Lot14 = 1.08;
extern int step14 = 20;
extern int TP14 = 50;
extern double Lot15 = 1.14;
extern int step15 = 20;
extern int TP15 = 55;
extern double Lot16 = 1.22;
extern int step16 = 20;
extern int TP16 = 60;
extern double Lot17 = 1.30;
extern int step17 = 20;
extern int TP17 = 65;
extern double Lot18 = 1.38;
extern int step18 = 20;
extern int TP18 = 70;
extern double Lot19 = 1.46;
extern int step19 = 20;
extern int TP19 = 75;
extern double Lot20 = 1.54;
extern int step20 = 20;
extern int TP20 = 80;
extern double Lot21 = 6.8;
extern int step21 = 500;
extern int TP21 = 40;
extern double Lot22 = 6.8;
extern int step22 = 30;
extern int TP22 = 40;
extern double Lot23 = 6.8;
extern int step23 = 30;
extern int TP23 = 40;
extern double Lot24 = 6.8;
extern int step24 = 30;
extern int TP24 = 40;
extern double Lot25 = 6.8;
extern int step25 = 30;
extern int TP25 = 40;
extern double Lot26 = 6.8;
extern int step26 = 30;
extern int TP26 = 40;
extern double Lot27 = 6.8;
extern int step27 = 30;
extern int TP27 = 40;
extern double Lot28 = 6.8;
extern int step28 = 30;
extern int TP28 = 40;
extern double Lot29 = 6.8;
extern int step29 = 30;
extern int TP29 = 40;
extern double Lot30 = 6.8;
extern int step30 = 30;
extern int TP30 = 40;
extern double Lot31 = 6.8;
extern int step31 = 30;
extern int TP31 = 40;
extern double Lot32 = 6.8;
extern int step32 = 30;
extern int TP32 = 40;
extern double Lot33 = 6.8;
extern int step33 = 30;
extern int TP33 = 40;
extern double Lot34 = 6.8;
extern int step34 = 30;
extern int TP34 = 40;
extern double Lot35 = 6.8;
extern int step35 = 30;
extern int TP35 = 40;
extern double Lot36 = 6.8;
extern int step36 = 30;
extern int TP36 = 40;
extern double Lot37 = 6.8;
extern int step37 = 30;
extern int TP37 = 40;
extern double Lot38 = 6.8;
extern int step38 = 30;
extern int TP38 = 40;
extern double Lot39 = 6.8;
extern int step39 = 30;
extern int TP39 = 40;
extern double Lot40 = 6.8;
extern int step40 = 30;
extern int TP40 = 40;
double g_price_812;
double g_price_828;
double g_price_836;
double g_price_844;
double g_price_852;
int g_ticket_860 = 0;
int g_ticket_864 = 0;
int gi_unused_868 = 0;
int gi_unused_872 = 0;
int g_ticket_876 = 0;
int g_ticket_880 = 0;
double g_ord_takeprofit_884 = 0.0;
double g_ord_takeprofit_892 = 0.0;
double g_ord_lots_900 = 0.0;
double g_ord_lots_908 = 0.0;
double g_ord_lots_916 = 0.0;
double g_ord_open_price_924 = 0.0;
double g_ord_open_price_932 = 0.0;
double gd_940 = 0.0;
double gd_948 = 0.0;
double gd_unused_956 = 0.0;
int gi_972 = 16711680;
int gi_1036 = 10;

void objectCreate(string a_name_0, int a_x_8, int a_y_12, string a_text_16 = "-", int a_fontsize_24 = 40, string a_fontname_28 = "Arial", color a_color_36 = -1) {
   int l_window_40 = WindowOnDropped();
   ObjectCreate(a_name_0, OBJ_LABEL, l_window_40, 0, 0);
   ObjectSet(a_name_0, OBJPROP_CORNER, 0);
   ObjectSet(a_name_0, OBJPROP_COLOR, a_color_36);
   ObjectSet(a_name_0, OBJPROP_XDISTANCE, a_x_8);
   ObjectSet(a_name_0, OBJPROP_YDISTANCE, a_y_12);
   ObjectSetText(a_name_0, a_text_16, a_fontsize_24, a_fontname_28, a_color_36);
}

int init() {
   gd_unused_956 = Lot1;
   return (0);
}

int deinit() {
   ObjectDelete("Info");
   ObjectDelete("Info1");
   ObjectDelete("Mode");
   ObjectDelete("Risk");
   Comment("");
   return (0);
}

int start() {
   Comment("\n MovingaverageMultiplyExpert",
         "\n trader12 åÏíå ãä "
         + "\n"
         + "------------------------------------------------"
         + "\n"
         + "  BROKER INFORMATION:"
         + "\n"
         + "    Broker Company:           " + AccountCompany()
         + "\n"
         + "------------------------------------------------"
         + "\n"
         + "  ACCOUNT INFORMATION:"
         + "\n"
         + "    Account Type:              " + AccountServer()
         + "\n"
         + "    Account Name:             " + AccountName()
         + "\n"
         + "    Account Number:          " + AccountNumber()
         + "\n"
         + "    Account Leverage:         " + DoubleToStr(AccountLeverage(), 0)
         + "\n"
         + "    Account Balance:           " + DoubleToStr(AccountBalance(), 2)
         + "\n"
         + "    Account Currency:         " + AccountCurrency()
         + "\n"
         + "    Account Equity:            " + DoubleToStr(AccountEquity(), 2)
         + "\n"
         + "------------------------------------------------"
         + "\n"
         + "  ORDERS INFORMATION:"
         + "\n"
         + "    Working & Pinding Order:     " + DoubleToStr(OrdersTotal(), 0)
         + "\n"
         + "    Orders History Total:      " + OrdersHistoryTotal()
         + "\n"
         + "------------------------------------------------"
         + "\n"
         + "  MARGIN INFORMATION:"
         + "\n"
         + "    Free Margin:                " + DoubleToStr(AccountFreeMargin(), 2)
         + "\n"
         + "    Used Margin:                " + DoubleToStr(AccountMargin(), 2)
         + "\n"
         + "------------------------------------------------"
         + "\n"
         + "    PAIRS:                      " + Symbol()
         + "\n"
         + "    SPREAD:                     " + DoubleToStr(MarketInfo(Symbol(), MODE_SPREAD), 0) + " pips"
         + "\n"
         + "    Min Lot                        "  + DoubleToStr(MarketInfo(Symbol(), MODE_MINLOT), 2)
         + "\n"
         + "    Max Lot                        " + DoubleToStr(MarketInfo(Symbol(), MODE_MAXLOT), 2)
         + "\n"
         + "------------------------------------------------"
         + "\n"
         + "  Actual Server Time         " + TimeToStr(TimeCurrent(), TIME_DATE | TIME_SECONDS)
         + "\n"
         + "------------------------------------------------");
   double MA1 = iCustom(NULL, 0, "Moving Averages", Period1, MA_SHIFT1, MA_METHOD1, 0, 0);
   double MA2 = iCustom(NULL, 0, "Moving Averages", Period2, MA_SHIFT2, MA_METHOD2, 0, 0);
   double ld_16 = MA2 + Dalta * Point;
   double ld_24 = MA1 + Dalta * Point;
   int li_32 = OrdersTotals(magic);
   double ld_36 = Profit(magic);
   if (MA1 < MA2 && ld_36 > AmountmoneyLose && li_32 != 0) {
      closebuy(magic);
      DeletePendingOrdersbuy(magic);
      return (0);
   }
   if (MA1 > MA2 && ld_36 > AmountmoneyLose && li_32 != 0) {
      closesell(magic);
      DeletePendingOrderssell(magic);
      return (0);
   }
   if (MA1 < ld_16 && li_32 == 0 && Tradebuy) return (0);
   if (MA2 < ld_24 && li_32 == 0 && Tradesell) return (0);
   if (Tradesell && Tradebuy == TRUE ) {
      Alert("Tradebuy=true æ Tradesell=trueáÇ íãßä ÃÎÊíÇÑ  ");
      return (0);
   }
   Ticket();
   double l_lots_44 = getlot();
   int li_52 = TP();
   int li_56 = Step();
   if (g_ticket_860 == 0) {
      if (g_ticket_876 != 0) OrderDelete(g_ticket_876);
      g_price_828 = Ask - gi_80 * Point;
      if (gi_80 <= 0) g_price_828 = 0;
      g_price_844 = Ask + li_52 * Point;
      if (Tradebuy) OrderSend(Symbol(), OP_BUY, Lot1, Ask, slipp, g_price_828, g_price_844, "magic = " + magic, magic, 0, CLR_NONE);
   }
   if (g_ticket_864 == 0) {
      if (g_ticket_880 != 0) OrderDelete(g_ticket_880);
      g_price_836 = Bid + gi_80 * Point;
      if (gi_80 <= 0) g_price_836 = 0;
      g_price_852 = Bid - li_52 * Point;
      if (Tradesell) OrderSend(Symbol(), OP_SELL, Lot1, Bid, slipp, g_price_836, g_price_852, "magic = " + magic, magic, 0, CLR_NONE);
   }
   if (g_ticket_860 != 0 && g_ticket_876 == 0) {
      g_price_812 = g_ord_open_price_924 - li_56 * Point;
      g_price_828 = g_price_812 - gi_80 * Point;
      if (gi_80 <= 0) g_price_828 = 0;
      g_price_844 = g_price_812 + li_52 * Point;
      OrderSend(Symbol(), OP_BUYLIMIT, l_lots_44, g_price_812, slipp, g_price_828, g_price_844, "magic = " + magic, magic, 0, CLR_NONE);
   }
   if (g_ticket_864 != 0 && g_ticket_880 == 0) {
      g_price_812 = g_ord_open_price_932 + li_56 * Point;
      g_price_836 = g_price_812 + gi_80 * Point;
      if (gi_80 <= 0) gi_80 = 0;
      g_price_852 = g_price_812 - li_52 * Point;
      OrderSend(Symbol(), OP_SELLLIMIT, l_lots_44, g_price_812, slipp, g_price_836, g_price_852, "magic = " + magic, magic, 0, CLR_NONE);
   }
   TrailingStopTp(g_ord_open_price_924, g_ord_takeprofit_884, g_ord_open_price_932, g_ord_takeprofit_892, g_ticket_860, g_ticket_864);
   if (!IsTesting()) {
      objectCreate("Info", 240, 10, "-", gi_1036, "Arial", gi_972);
      objectCreate("Info1", 240, 10, "-", gi_1036, "Arial", gi_972);
      objectCreate("Mode", 840, 30, "-", gi_1036, "Arial", gi_972);
      objectCreate("Risk", 50, 70, "-", gi_1036, "Arial", gi_972);
      if (MA1 > MA2) ObjectSetText("Info", "The Two MA Indicator Confirm The Buy Mode", 20, "Arial", Red);
      else
         if (MA2 < MA1) ObjectSetText("Info1", "The Two MA Indicator Confirm The Sell Mode", 20, "Arial", Green);
      if (Tradesell) ObjectSetText("Mode", "Sell Mode ", 20, "Arial", Olive);
      else
         if (Tradebuy) ObjectSetText("Mode", "Buy Mode", 20, "Arial", Olive);
      if ((MA1 > MA2 && g_ticket_864 != 0) || (g_ticket_860 != 0 && MA1 < MA2)) ObjectSetText("Risk", "Risk!!!! waiting for Closeorders Mode", 40, "Arial", Red);
   }
   return (0);
}

int OrdersTotals(int a_magic_0) {
   int l_count_4 = 0;
   int l_ord_total_8 = OrdersTotal();
   for (int l_pos_12 = 0; l_pos_12 < l_ord_total_8; l_pos_12++) {
      OrderSelect(l_pos_12, SELECT_BY_POS, MODE_TRADES);
      if (OrderMagicNumber() == a_magic_0 && OrderSymbol() == Symbol() && OrderType() == OP_BUY || OrderType() == OP_SELL) l_count_4++;
   }
   return (l_count_4);
}

double getlot() {
   double ld_ret_0;
   int li_8 = OrdersTotals(magic);
   switch (li_8) {
   case 0:
      ld_ret_0 = Lot1;
      break;
   case 1:
      ld_ret_0 = Lot2;
      break;
   case 2:
      ld_ret_0 = Lot3;
      break;
   case 3:
      ld_ret_0 = Lot4;
      break;
   case 4:
      ld_ret_0 = Lot5;
      break;
   case 5:
      ld_ret_0 = Lot6;
      break;
   case 6:
      ld_ret_0 = Lot7;
      break;
   case 7:
      ld_ret_0 = Lot8;
      break;
   case 8:
      ld_ret_0 = Lot9;
      break;
   case 9:
      ld_ret_0 = Lot10;
      break;
   case 10:
      ld_ret_0 = Lot11;
      break;
   case 11:
      ld_ret_0 = Lot12;
      break;
   case 12:
      ld_ret_0 = Lot13;
      break;
   case 13:
      ld_ret_0 = Lot14;
      break;
   case 14:
      ld_ret_0 = Lot15;
      break;
   case 15:
      ld_ret_0 = Lot16;
      break;
   case 16:
      ld_ret_0 = Lot17;
      break;
   case 17:
      ld_ret_0 = Lot18;
      break;
   case 18:
      ld_ret_0 = Lot19;
      break;
   case 19:
      ld_ret_0 = Lot20;
      break;
   case 20:
      ld_ret_0 = Lot21;
      break;
   case 21:
      ld_ret_0 = Lot22;
      break;
   case 22:
      ld_ret_0 = Lot23;
      break;
   case 23:
      ld_ret_0 = Lot24;
      break;
   case 24:
      ld_ret_0 = Lot25;
      break;
   case 25:
      ld_ret_0 = Lot26;
      break;
   case 26:
      ld_ret_0 = Lot27;
      break;
   case 27:
      ld_ret_0 = Lot28;
      break;
   case 28:
      ld_ret_0 = Lot29;
      break;
   case 29:
      ld_ret_0 = Lot30;
      break;
   case 30:
      ld_ret_0 = Lot31;
      break;
   case 31:
      ld_ret_0 = Lot32;
      break;
   case 32:
      ld_ret_0 = Lot33;
      break;
   case 33:
      ld_ret_0 = Lot34;
      break;
   case 34:
      ld_ret_0 = Lot35;
      break;
   case 35:
      ld_ret_0 = Lot36;
      break;
   case 36:
      ld_ret_0 = Lot37;
      break;
   case 37:
      ld_ret_0 = Lot38;
      break;
   case 38:
      ld_ret_0 = Lot39;
      break;
   case 39:
      ld_ret_0 = Lot40;
   }
   return (ld_ret_0);
}

int TP() {
   double ld_ret_0;
   int li_8 = OrdersTotals(magic);
   switch (li_8) {
   case 0:
      ld_ret_0 = TP1;
      break;
   case 1:
      ld_ret_0 = TP2;
      break;
   case 2:
      ld_ret_0 = TP3;
      break;
   case 3:
      ld_ret_0 = TP4;
      break;
   case 4:
      ld_ret_0 = TP5;
      break;
   case 5:
      ld_ret_0 = TP6;
      break;
   case 6:
      ld_ret_0 = TP7;
      break;
   case 7:
      ld_ret_0 = TP8;
      break;
   case 8:
      ld_ret_0 = TP9;
      break;
   case 9:
      ld_ret_0 = TP10;
      break;
   case 10:
      ld_ret_0 = TP11;
      break;
   case 11:
      ld_ret_0 = TP12;
      break;
   case 12:
      ld_ret_0 = TP13;
      break;
   case 13:
      ld_ret_0 = TP14;
      break;
   case 14:
      ld_ret_0 = TP15;
      break;
   case 15:
      ld_ret_0 = TP16;
      break;
   case 16:
      ld_ret_0 = TP17;
      break;
   case 17:
      ld_ret_0 = TP18;
      break;
   case 18:
      ld_ret_0 = TP19;
      break;
   case 19:
      ld_ret_0 = TP20;
      break;
   case 20:
      ld_ret_0 = TP21;
      break;
   case 21:
      ld_ret_0 = TP22;
      break;
   case 22:
      ld_ret_0 = TP23;
      break;
   case 23:
      ld_ret_0 = TP24;
      break;
   case 24:
      ld_ret_0 = TP25;
      break;
   case 25:
      ld_ret_0 = TP26;
      break;
   case 26:
      ld_ret_0 = TP27;
      break;
   case 27:
      ld_ret_0 = TP28;
      break;
   case 28:
      ld_ret_0 = TP29;
      break;
   case 29:
      ld_ret_0 = TP30;
      break;
   case 30:
      ld_ret_0 = TP31;
      break;
   case 31:
      ld_ret_0 = TP32;
      break;
   case 32:
      ld_ret_0 = TP33;
      break;
   case 33:
      ld_ret_0 = TP34;
      break;
   case 34:
      ld_ret_0 = TP35;
      break;
   case 35:
      ld_ret_0 = TP36;
      break;
   case 36:
      ld_ret_0 = TP37;
      break;
   case 37:
      ld_ret_0 = TP38;
      break;
   case 38:
      ld_ret_0 = TP39;
      break;
   case 39:
      ld_ret_0 = TP40;
   }
   return (ld_ret_0);
}

int Step() {
   double ld_ret_0;
   int li_8 = OrdersTotals(magic);
   switch (li_8) {
   case 0:
      ld_ret_0 = step1;
      break;
   case 1:
      ld_ret_0 = step2;
      break;
   case 2:
      ld_ret_0 = step3;
      break;
   case 3:
      ld_ret_0 = step4;
      break;
   case 4:
      ld_ret_0 = step5;
      break;
   case 5:
      ld_ret_0 = step6;
      break;
   case 6:
      ld_ret_0 = step7;
      break;
   case 7:
      ld_ret_0 = step8;
      break;
   case 8:
      ld_ret_0 = step9;
      break;
   case 9:
      ld_ret_0 = step10;
      break;
   case 10:
      ld_ret_0 = step11;
      break;
   case 11:
      ld_ret_0 = step12;
      break;
   case 12:
      ld_ret_0 = step13;
      break;
   case 13:
      ld_ret_0 = step14;
      break;
   case 14:
      ld_ret_0 = step15;
      break;
   case 15:
      ld_ret_0 = step16;
      break;
   case 16:
      ld_ret_0 = step17;
      break;
   case 17:
      ld_ret_0 = step18;
      break;
   case 18:
      ld_ret_0 = step19;
      break;
   case 19:
      ld_ret_0 = step20;
      break;
   case 20:
      ld_ret_0 = step21;
      break;
   case 21:
      ld_ret_0 = step22;
      break;
   case 22:
      ld_ret_0 = step23;
      break;
   case 23:
      ld_ret_0 = step24;
      break;
   case 24:
      ld_ret_0 = step25;
      break;
   case 25:
      ld_ret_0 = step26;
      break;
   case 26:
      ld_ret_0 = step27;
      break;
   case 27:
      ld_ret_0 = step28;
      break;
   case 28:
      ld_ret_0 = step29;
      break;
   case 29:
      ld_ret_0 = step30;
      break;
   case 30:
      ld_ret_0 = step31;
      break;
   case 31:
      ld_ret_0 = step32;
      break;
   case 32:
      ld_ret_0 = step33;
      break;
   case 33:
      ld_ret_0 = step34;
      break;
   case 34:
      ld_ret_0 = step35;
      break;
   case 35:
      ld_ret_0 = step36;
      break;
   case 36:
      ld_ret_0 = step37;
      break;
   case 37:
      ld_ret_0 = step38;
      break;
   case 38:
      ld_ret_0 = step39;
      break;
   case 39:
      ld_ret_0 = step40;
   }
   return (ld_ret_0);
}

int DeletePendingOrderssell(int a_magic_0) {
   int l_ord_total_4 = OrdersTotal();
   for (int l_pos_8 = l_ord_total_4 - 1; l_pos_8 >= 0; l_pos_8--) {
      OrderSelect(l_pos_8, SELECT_BY_POS, MODE_TRADES);
      if (OrderMagicNumber() == a_magic_0 && OrderSymbol() == Symbol() && OrderType() == OP_SELLLIMIT) OrderDelete(OrderTicket());
   }
   return (0);
}

int DeletePendingOrdersbuy(int a_magic_0) {
   int l_ord_total_4 = OrdersTotal();
   for (int l_pos_8 = l_ord_total_4 - 1; l_pos_8 >= 0; l_pos_8--) {
      OrderSelect(l_pos_8, SELECT_BY_POS, MODE_TRADES);
      if (OrderMagicNumber() == a_magic_0 && OrderSymbol() == Symbol() && OrderType() == OP_BUYLIMIT) OrderDelete(OrderTicket());
   }
   return (0);
}

void closebuy(int a_magic_0) {
   for (int l_pos_4 = 0; l_pos_4 < OrdersTotal(); l_pos_4++) {
      OrderSelect(l_pos_4, SELECT_BY_POS);
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == a_magic_0 && OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, 9, Yellow);
   }
}

void closesell(int a_magic_0) {
   for (int l_pos_4 = 0; l_pos_4 < OrdersTotal(); l_pos_4++) {
      OrderSelect(l_pos_4, SELECT_BY_POS);
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == a_magic_0 && OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, 9, Yellow);
   }
}

double Profit(int a_magic_0) {
   double ld_ret_4 = 0;
   int l_ord_total_12 = OrdersTotal();
   for (int l_pos_16 = 0; l_pos_16 < l_ord_total_12; l_pos_16++) {
      OrderSelect(l_pos_16, SELECT_BY_POS, MODE_TRADES);
      if (OrderMagicNumber() == a_magic_0 && OrderSymbol() == Symbol() && OrderType() == OP_BUY || OrderType() == OP_SELL) ld_ret_4 += OrderProfit();
   }
   return (ld_ret_4);
}

double TrailingStopTp(double ad_0, double ad_8, double ad_16, double ad_24, int ai_32, int ai_36) {
   double l_ord_takeprofit_40;
   double l_price_48;
   double l_ord_takeprofit_56;
   double l_price_64;
   for (int l_pos_72 = 0; l_pos_72 < OrdersTotal(); l_pos_72++) {
      OrderSelect(l_pos_72, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() == Symbol() && OrderType() == OP_BUY && ai_32 != 0 && OrderMagicNumber() == magic) {
         l_price_48 = ad_0 - gi_80 * Point;
         if (gi_80 <= 0) gi_80 = 0;
         if (ai_32 != OrderTicket()) l_ord_takeprofit_40 = ad_8;
         else l_ord_takeprofit_40 = OrderTakeProfit();
         if (l_ord_takeprofit_40 != OrderTakeProfit() || l_price_48 != OrderStopLoss()) OrderModify(OrderTicket(), OrderOpenPrice(), l_price_48, l_ord_takeprofit_40, 0, CLR_NONE);
      }
      if (OrderSymbol() == Symbol() && OrderType() == OP_SELL && ai_36 != 0 && OrderMagicNumber() == magic) {
         l_price_64 = ad_16 + gi_80 * Point;
         if (gi_80 <= 0) l_price_64 = 0;
         if (ai_36 != OrderTicket()) l_ord_takeprofit_56 = ad_24;
         else l_ord_takeprofit_56 = OrderTakeProfit();
         if (l_ord_takeprofit_56 != OrderTakeProfit() || l_price_64 != OrderStopLoss()) OrderModify(OrderTicket(), OrderOpenPrice(), l_price_64, l_ord_takeprofit_56, 0, CLR_NONE);
      }
   }
   return (0.0);
}

void Ticket() {
   g_ticket_860 = 0;
   g_ticket_864 = 0;
   gi_unused_868 = 0;
   gi_unused_872 = 0;
   g_ticket_876 = 0;
   g_ticket_880 = 0;
   g_ord_takeprofit_884 = 0;
   g_ord_takeprofit_892 = 0;
   g_ord_lots_900 = 0;
   g_ord_lots_908 = 0;
   g_ord_lots_916 = 0;
   g_ord_open_price_924 = 0;
   g_ord_open_price_932 = 0;
   gd_940 = 0;
   gd_948 = 0;
   for (int l_pos_0 = 0; l_pos_0 < OrdersTotal(); l_pos_0++) {
      OrderSelect(l_pos_0, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic) {
         if (OrderType() == OP_BUY && g_ticket_860 < OrderTicket()) {
            g_ord_lots_900 = OrderLots();
            g_ord_open_price_924 = OrderOpenPrice();
            g_ticket_860 = OrderTicket();
            g_ord_takeprofit_884 = OrderTakeProfit();
            if (OrderLots() == Lot1) gd_940 = OrderOpenPrice() - gi_80 * Point;
         }
         if (OrderType() == OP_SELL && g_ticket_864 < OrderTicket()) {
            g_ord_lots_908 = OrderLots();
            g_ord_open_price_932 = OrderOpenPrice();
            g_ticket_864 = OrderTicket();
            g_ord_takeprofit_892 = OrderTakeProfit();
            if (OrderLots() == Lot1) gd_948 = OrderOpenPrice() + gi_80 * Point;
         }
         if (OrderType() == OP_BUYLIMIT) {
            g_ticket_876 = OrderTicket();
            g_ord_lots_916 = OrderLots();
         }
         if (OrderType() == OP_SELLLIMIT) {
            g_ticket_880 = OrderTicket();
            g_ord_lots_916 = OrderLots();
         }
      }
   }
}
 

Attachments

I fix and change by chatgpt more code but I have 1 error
Code:
#property copyright "Copyright © 2009, Trader12."
#property link      "Trader12"

#include <Trade\Trade.mqh>
CTrade trade;

input string  Info      = "If Your Broker Allwed Hedge";
input string  Info_1    = "You Cant Choose BUY & SELL In one Chart";
input string  Info_2    = "You Must Open Two Chart If Use BUY & SELL In One Time";
input string  Info_3    = "You Must Change Magic Number If Use BUY & SELL & Pair";

input bool    Tradebuy  = true;
input bool    Tradesell = true;

input double  AmountmoneyLose = 10;
input int     magic           = 9999;
int           gi_80           = 5000;   // stays normal variable, not input
input int     slipp           = 3;
input int     Dalta           = 5;

input string  Set_MA_1  = "Moving Average 1";
input int     Period1   = 13;
input int     MA_SHIFT1 = 0;
input int     MA_METHOD1= 1;

input string  Set_MA_2  = "Moving Average 2";
input int     Period2   = 21;
input int     MA_SHIFT2 = 0;
input int     MA_METHOD2= 1;

input string  Set_Double = "You Can Choose Lot & Step & Target Profit For 40 Double";

input double Lot1 = 0.01;
input int    step1 = 200;
input int    TP1 = 200;

input double Lot2 = 0.01;
input int    step2 = 200;
input int    TP2 = 200;

input double Lot3 = 0.02;
input int    step3 = 200;
input int    TP3 = 200;

input double Lot4 = 0.04;
input int    step4 = 200;
input int    TP4 = 200;

input double Lot5 = 0.08;
input int    step5 = 200;
input int    TP5 = 200;

input double Lot6 = 0.16;
input int    step6 = 200;
input int    TP6 = 200;

input double Lot7 = 0.30;
input int    step7 = 200;
input int    TP7 = 200;

input double Lot8 = 0.60;
input int    step8 = 200;
input int    TP8 = 200;

input double Lot9 = 0.68;
input int    step9 = 200;
input int    TP9 = 200;

input double Lot10 = 0.76;
input int    step10 = 20;
input int    TP10 = 30;

input double Lot11 = 0.84;
input int    step11 = 20;
input int    TP11 = 35;

input double Lot12 = 0.92;
input int    step12 = 20;
input int    TP12 = 40;

input double Lot13 = 1.00;
input int    step13 = 20;
input int    TP13 = 45;

input double Lot14 = 1.08;
input int    step14 = 20;
input int    TP14 = 50;

input double Lot15 = 1.14;
input int    step15 = 20;
input int    TP15 = 55;

input double Lot16 = 1.22;
input int    step16 = 20;
input int    TP16 = 60;

input double Lot17 = 1.30;
input int    step17 = 20;
input int    TP17 = 65;

input double Lot18 = 1.38;
input int    step18 = 20;
input int    TP18 = 70;

input double Lot19 = 1.46;
input int    step19 = 20;
input int    TP19 = 75;

input double Lot20 = 1.54;
input int    step20 = 20;
input int    TP20 = 80;

input double Lot21 = 6.8;
input int    step21 = 500;
input int    TP21 = 40;

input double Lot22 = 6.8;
input int    step22 = 30;
input int    TP22 = 40;

input double Lot23 = 6.8;
input int    step23 = 30;
input int    TP23 = 40;

input double Lot24 = 6.8;
input int    step24 = 30;
input int    TP24 = 40;

input double Lot25 = 6.8;
input int    step25 = 30;
input int    TP25 = 40;

input double Lot26 = 6.8;
input int    step26 = 30;
input int    TP26 = 40;

input double Lot27 = 6.8;
input int    step27 = 30;
input int    TP27 = 40;

input double Lot28 = 6.8;
input int    step28 = 30;
input int    TP28 = 40;

input double Lot29 = 6.8;
input int    step29 = 30;
input int    TP29 = 40;

input double Lot30 = 6.8;
input int    step30 = 30;
input int    TP30 = 40;

input double Lot31 = 6.8;
input int    step31 = 30;
input int    TP31 = 40;

input double Lot32 = 6.8;
input int    step32 = 30;
input int    TP32 = 40;

input double Lot33 = 6.8;
input int    step33 = 30;
input int    TP33 = 40;

input double Lot34 = 6.8;
input int    step34 = 30;
input int    TP34 = 40;

input double Lot35 = 6.8;
input int    step35 = 30;
input int    TP35 = 40;

input double Lot36 = 6.8;
input int    step36 = 30;
input int    TP36 = 40;

input double Lot37 = 6.8;
input int    step37 = 30;
input int    TP37 = 40;

input double Lot38 = 6.8;
input int    step38 = 30;
input int    TP38 = 40;

input double Lot39 = 6.8;
input int    step39 = 30;
input int    TP39 = 40;

input double Lot40 = 6.8;
input int    step40 = 30;
input int    TP40 = 40;


double g_price_812;
double g_price_828;
double g_price_836;
double g_price_844;
double g_price_852;
int g_ticket_860 = 0;
int g_ticket_864 = 0;
int gi_unused_868 = 0;
int gi_unused_872 = 0;
int g_ticket_876 = 0;
int g_ticket_880 = 0;
double g_ord_takeprofit_884 = 0.0;
double g_ord_takeprofit_892 = 0.0;
double g_ord_lots_900 = 0.0;
double g_ord_lots_908 = 0.0;
double g_ord_lots_916 = 0.0;
double g_ord_open_price_924 = 0.0;
double g_ord_open_price_932 = 0.0;
double gd_940 = 0.0;
double gd_948 = 0.0;
double gd_unused_956 = 0.0;
int gi_972 = 16711680;
int gi_1036 = 10;

void objectCreate(
   string name,
   int x,
   int y,
   string text = "-",
   int fontsize = 40,
   string fontname = "Arial",
   color col = clrWhite,
   int corner = CORNER_LEFT_UPPER
)
{
long chart_id = ChartID();
int  window   = 0; // main window in EA

// For indicators, you can keep:
 // int window = WindowOnDropped();

   // Delete old object if exists (avoid "already exists" errors)
   if(ObjectFind(chart_id, name) >= 0)
      ObjectDelete(chart_id, name);

   // Create label
   if(!ObjectCreate(chart_id, name, OBJ_LABEL, window, 0, 0))
   {
      Print("❌ Failed to create label: ", name);
      return;
   }

   // Set label properties
   ObjectSetInteger(chart_id, name, OBJPROP_CORNER, corner);
   ObjectSetInteger(chart_id, name, OBJPROP_XDISTANCE, x);
   ObjectSetInteger(chart_id, name, OBJPROP_YDISTANCE, y);
   ObjectSetInteger(chart_id, name, OBJPROP_COLOR, col);
   ObjectSetInteger(chart_id, name, OBJPROP_FONTSIZE, fontsize);
   ObjectSetString(chart_id, name, OBJPROP_FONT, fontname);
   ObjectSetString(chart_id, name, OBJPROP_TEXT, text);
}
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
   gd_unused_956 = Lot1;
   return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
   ObjectDelete(ChartID(), "Info");
   ObjectDelete(ChartID(), "Info1");
   ObjectDelete(ChartID(), "Mode");
   ObjectDelete(ChartID(), "Risk");
   Comment("");
}

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
   // Account information
   Comment(
      "\n SolMoon",
      "\n H$H ",
      "\n------------------------------------------------",
      "\n  BROKER INFORMATION:",
      "\n    Broker Company:           ", AccountInfoString(ACCOUNT_COMPANY),
      "\n------------------------------------------------",
      "\n  ACCOUNT INFORMATION:",
      "\n    Account Type:              ", AccountInfoString(ACCOUNT_SERVER),
      "\n    Account Name:              ", AccountInfoString(ACCOUNT_NAME),
      "\n    Account Number:            ", (long)AccountInfoInteger(ACCOUNT_LOGIN),
      "\n    Account Leverage:          ", (string)AccountInfoInteger(ACCOUNT_LEVERAGE),
      "\n    Account Balance:           ", DoubleToString(AccountInfoDouble(ACCOUNT_BALANCE), 2),
      "\n    Account Currency:          ", AccountInfoString(ACCOUNT_CURRENCY),
      "\n    Account Equity:            ", DoubleToString(AccountInfoDouble(ACCOUNT_EQUITY), 2),
      "\n------------------------------------------------",
      "\n  ORDERS INFORMATION:",
      "\n    Working & Pending Order:   ", (string)OrdersTotal(),
      "\n    Orders History Total:      ", (string)HistoryDealsTotal(),
      "\n------------------------------------------------",
      "\n  MARGIN INFORMATION:",
      "\n    Free Margin:                ", DoubleToString(AccountInfoDouble(ACCOUNT_FREEMARGIN), 2),
      "\n    Used Margin:                ", DoubleToString(AccountInfoDouble(ACCOUNT_MARGIN), 2),
      "\n------------------------------------------------",
      "\n    PAIRS:                      ", _Symbol,
      "\n    SPREAD:                     ", (string)(SymbolInfoInteger(_Symbol, SYMBOL_SPREAD)), " points",
      "\n    Min Lot:                    ", DoubleToString(SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MIN), 2),
      "\n    Max Lot:                    ", DoubleToString(SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MAX), 2),
      "\n------------------------------------------------",
      "\n  Actual Server Time:           ", TimeToString(TimeCurrent(), TIME_DATE | TIME_SECONDS),
      "\n------------------------------------------------"
   );

   // Get Moving Averages (example using built-in iMA)
// Calculate Moving Averages
double MA1 = iMA(_Symbol, PERIOD_CURRENT, Period1, MA_SHIFT1, MA_METHOD1, PRICE_CLOSE, 0);
double MA2 = iMA(_Symbol, PERIOD_CURRENT, Period2, MA_SHIFT2, MA_METHOD2, PRICE_CLOSE, 0);

// Adjusted values with Dalta
double ld_16 = MA2 + Dalta * _Point;
double ld_24 = MA1 + Dalta * _Point;

// Count open positions for this magic number
int li_32 = OrdersTotals(magic);   // <-- This needs to be adapted for MT5
double ld_36 = Profit(magic);      // <-- You already have MT5 version

// Close BUY positions if condition met
if (MA1 < MA2 && ld_36 > AmountmoneyLose && li_32 != 0)
{
   closebuy(magic);                  // MT5 version already written
   DeletePendingOrdersbuy(magic);    // MT5 version already written
   return;
}

// Close SELL positions if condition met
if (MA1 > MA2 && ld_36 > AmountmoneyLose && li_32 != 0)
{
   closesell(magic);                 // MT5 version already written
   DeletePendingOrderssell(magic);   // MT5 version already written
   return;
}

// No trade if MA conditions not met
if (MA1 < ld_16 && li_32 == 0 && Tradebuy)   return;
if (MA2 < ld_24 && li_32 == 0 && Tradesell)  return;

// Prevent both buy and sell from running on same chart
if (Tradesell && Tradebuy)
{
   Alert("Tradebuy=true and Tradesell=true - Cannot execute both directions on same chart");
   return;
}

////

void ExecuteOrders()
{
   Ticket();
   double l_lots_44 = getlot();
   int li_52 = TP();
   int li_56 = Step();

   double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
   double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);

   if (g_ticket_860 == 0)
   {
      if (g_ticket_876 != 0) trade.OrderDelete(g_ticket_876);
      g_price_828 = ask - gi_80 * _Point;
      if (gi_80 <= 0) g_price_828 = 0;
      g_price_844 = ask + li_52 * _Point;
      if (Tradebuy)
         trade.Buy(Lot1, _Symbol, ask, g_price_828, g_price_844, "magic = " + IntegerToString(magic));
   }

   if (g_ticket_864 == 0)
   {
      if (g_ticket_880 != 0) trade.OrderDelete(g_ticket_880);
      g_price_836 = bid + gi_80 * _Point;
      if (gi_80 <= 0) g_price_836 = 0;
      g_price_852 = bid - li_52 * _Point;
      if (Tradesell)
         trade.Sell(Lot1, _Symbol, bid, g_price_836, g_price_852, "magic = " + IntegerToString(magic));
   }

   if (g_ticket_860 != 0 && g_ticket_876 == 0)
   {
      g_price_812 = g_ord_open_price_924 - li_56 * _Point;
      g_price_828 = g_price_812 - gi_80 * _Point;
      if (gi_80 <= 0) g_price_828 = 0;
      g_price_844 = g_price_812 + li_52 * _Point;
      trade.BuyLimit(l_lots_44, g_price_812, _Symbol, g_price_828, g_price_844, ORDER_TIME_GTC, 0, "magic = " + IntegerToString(magic));
   }

   if (g_ticket_864 != 0 && g_ticket_880 == 0)
   {
      g_price_812 = g_ord_open_price_932 + li_56 * _Point;
      g_price_836 = g_price_812 + gi_80 * _Point;
      if (gi_80 <= 0) gi_80 = 0;
      g_price_852 = g_price_812 - li_52 * _Point;
      trade.SellLimit(l_lots_44, g_price_812, _Symbol, g_price_836, g_price_852, ORDER_TIME_GTC, 0, "magic = " + IntegerToString(magic));
   }

   TrailingStopTp(g_ord_open_price_924, g_ord_takeprofit_884, g_ord_open_price_932, g_ord_takeprofit_892, g_ticket_860, g_ticket_864);

   if (!MQLInfoInteger(MQL_TESTER))
   {
      objectCreate("Info", 240, 10, "-", gi_1036, "Arial", gi_972);
      objectCreate("Info1", 240, 10, "-", gi_1036, "Arial", gi_972);
      objectCreate("Mode", 840, 30, "-", gi_1036, "Arial", gi_972);
      objectCreate("Risk", 50, 70, "-", gi_1036, "Arial", gi_972);

      long chart_id = ChartID();

      if (MA1 > MA2)
         ObjectSetString(chart_id, "Info", OBJPROP_TEXT, "The Two MA Indicator Confirm The Buy Mode");
      else if (MA2 < MA1)
         ObjectSetString(chart_id, "Info1", OBJPROP_TEXT, "The Two MA Indicator Confirm The Sell Mode");

      if (Tradesell)
         ObjectSetString(chart_id, "Mode", OBJPROP_TEXT, "Sell Mode ");
      else if (Tradebuy)
         ObjectSetString(chart_id, "Mode", OBJPROP_TEXT, "Buy Mode");

      if ((MA1 > MA2 && g_ticket_864 != 0) || (g_ticket_860 != 0 && MA1 < MA2))
         ObjectSetString(chart_id, "Risk", OBJPROP_TEXT, "Risk!!!! waiting for Closeorders Mode");
   }
}
////////////////
//////////////

int OrdersTotals(int a_magic_0)
{
   int count = 0;
   int total = PositionsTotal();
  
   for(int i = 0; i < total; i++)
   {
      if(PositionSelectByIndex(i))
      {
         long magic;
         string sym;
         long type;
        
         PositionGetInteger(POSITION_MAGIC, magic);
         PositionGetString(POSITION_SYMBOL, sym);
         PositionGetInteger(POSITION_TYPE, type);
        
         if(magic == a_magic_0 && sym == _Symbol &&
            (type == POSITION_TYPE_BUY || type == POSITION_TYPE_SELL))
         {
            count++;
         }
      }
   }
   return count;
}
////////
// Example arrays (fill with your Lot1..Lot40 values)
double LotsArray[40] = { Lot1, Lot2, Lot3, /* ... */ Lot40 };
double TPArray[40]   = { TP1, TP2, TP3, /* ... */ TP40 };
double StepArray[40] = { step1, step2, step3, /* ... */ step40 };

double getlot()
{
   int idx = OrdersTotals(magic);
   if(idx >= 0 && idx < 40)
      return LotsArray[idx];
   return LotsArray[0]; // default fallback
}

double TP()
{
   int idx = OrdersTotals(magic);
   if(idx >= 0 && idx < 40)
      return TPArray[idx];
   return TPArray[0];
}

double Step()
{
   int idx = OrdersTotals(magic);
   if(idx >= 0 && idx < 40)
      return StepArray[idx];
   return StepArray[0];
}

////////

///
int DeletePendingOrdersSell(int a_magic_0)
{
   int total = OrdersTotal();

   for(int i = total - 1; i >= 0; i--)
   {
      if(OrderSelect(i, SELECT_BY_POS))
      {
         long magic;
         string sym;
         long type;
         ulong ticket;

         OrderGetInteger(ORDER_MAGIC, magic);
         OrderGetString(ORDER_SYMBOL, sym);
         OrderGetInteger(ORDER_TYPE, type);
         ticket = OrderGetInteger(ORDER_TICKET);

         if(magic == a_magic_0 && sym == _Symbol && type == ORDER_TYPE_SELL_LIMIT)
         {
            if(!OrderDelete(ticket))
               Print("Failed to delete order ", ticket, " Error: ", GetLastError());
         }
      }
   }
   return 0;
}
///
///
int DeletePendingOrdersBuy(int a_magic_0)
{
   int total = OrdersTotal();

   for(int i = total - 1; i >= 0; i--)
   {
      if(OrderSelect(i, SELECT_BY_POS))
      {
         long magic;
         string sym;
         long type;
         ulong ticket;

         OrderGetInteger(ORDER_MAGIC, magic);
         OrderGetString(ORDER_SYMBOL, sym);
         OrderGetInteger(ORDER_TYPE, type);
         ticket = OrderGetInteger(ORDER_TICKET);

         if(magic == a_magic_0 && sym == _Symbol && type == ORDER_TYPE_BUY_LIMIT)
         {
            if(!OrderDelete(ticket))
               Print("Failed to delete order ", ticket, " Error: ", GetLastError());
         }
      }
   }
   return 0;
}

/////

void CloseBuy(int a_magic_0)
{
   int total = PositionsTotal();

   for(int i = total - 1; i >= 0; i--)
   {
      string sym;
      long magic;
      long type;

      // Select the position
      if(PositionSelectByIndex(i))
      {
         PositionGetString(POSITION_SYMBOL, sym);
         PositionGetInteger(POSITION_MAGIC, magic);
         PositionGetInteger(POSITION_TYPE, type);

         // Check symbol, magic number, and position type (buy)
         if(sym == _Symbol && magic == a_magic_0 && type == POSITION_TYPE_BUY)
         {
            double volume = PositionGetDouble(POSITION_VOLUME);

            // Close the position
            if(!trade.PositionClose(sym))
               Print("Failed to close BUY position on ", sym,
                     " Error: ", GetLastError());
         }
      }
   }
}

///

void CloseSell(int a_magic_0)
{
   int total = PositionsTotal();

   for(int i = total - 1; i >= 0; i--)
   {
      string sym;
      long magic;
      long type;

      // Select position
      if(PositionSelectByIndex(i))
      {
         PositionGetString(POSITION_SYMBOL, sym);
         PositionGetInteger(POSITION_MAGIC, magic);
         PositionGetInteger(POSITION_TYPE, type);

         // Check symbol, magic number, and SELL type
         if(sym == _Symbol && magic == a_magic_0 && type == POSITION_TYPE_SELL)
         {
            // Close position
            if(!trade.PositionClose(sym))
               Print("Failed to close SELL position on ", sym,
                     " Error: ", GetLastError());
         }
      }
   }
}



///



double Profit(int a_magic_0)
{
   double total_profit = 0;
   int total_positions = PositionsTotal();

   for(int i = 0; i < total_positions; i++)
   {
      string sym;
      long magic;
      long type;
      double profit;

      if(PositionSelectByIndex(i))
      {
         PositionGetString(POSITION_SYMBOL, sym);
         PositionGetInteger(POSITION_MAGIC, magic);
         PositionGetInteger(POSITION_TYPE, type);
         PositionGetDouble(POSITION_PROFIT, profit);

         // Ensure magic number and symbol match
         if(sym == _Symbol && magic == a_magic_0 &&
            (type == POSITION_TYPE_BUY || type == POSITION_TYPE_SELL))
         {
            total_profit += profit;
         }
      }
   }

   return total_profit;
}
/////

double TrailingStopTp(double ad_0, double ad_8, double ad_16, double ad_24, int ai_32, int ai_36)
{
   double l_ord_takeprofit_40;
   double l_price_48;
   double l_ord_takeprofit_56;
   double l_price_64;

   for(int i = 0; i < PositionsTotal(); i++)
   {
      string sym;
      long magic_number, type;
      double open_price, stop_loss, take_profit;

      if(PositionSelectByIndex(i))
      {
         PositionGetString(POSITION_SYMBOL, sym);
         PositionGetInteger(POSITION_MAGIC, magic_number);
         PositionGetInteger(POSITION_TYPE, type);
         PositionGetDouble(POSITION_PRICE_OPEN, open_price);
         PositionGetDouble(POSITION_SL, stop_loss);
         PositionGetDouble(POSITION_TP, take_profit);

         // BUY trailing logic
         if(sym == _Symbol && type == POSITION_TYPE_BUY && ai_32 != 0 && magic_number == magic)
         {
            l_price_48 = ad_0 - gi_80 * _Point;
            if(gi_80 <= 0) gi_80 = 0;

            if(ai_32 != (int)PositionGetInteger(POSITION_TICKET))
               l_ord_takeprofit_40 = ad_8;
            else
               l_ord_takeprofit_40 = take_profit;

            if(l_ord_takeprofit_40 != take_profit || l_price_48 != stop_loss)
               trade.PositionModify(sym, l_price_48, l_ord_takeprofit_40);
         }

         // SELL trailing logic
         if(sym == _Symbol && type == POSITION_TYPE_SELL && ai_36 != 0 && magic_number == magic)
         {
            l_price_64 = ad_16 + gi_80 * _Point;
            if(gi_80 <= 0) l_price_64 = 0;

            if(ai_36 != (int)PositionGetInteger(POSITION_TICKET))
               l_ord_takeprofit_56 = ad_24;
            else
               l_ord_takeprofit_56 = take_profit;

            if(l_ord_takeprofit_56 != take_profit || l_price_64 != stop_loss)
               trade.PositionModify(sym, l_price_64, l_ord_takeprofit_56);
         }
      }
   }

   return 0.0;
}



////

void Ticket()
{
   g_ticket_860 = 0;
   g_ticket_864 = 0;
   gi_unused_868 = 0;
   gi_unused_872 = 0;
   g_ticket_876 = 0;
   g_ticket_880 = 0;
   g_ord_takeprofit_884 = 0;
   g_ord_takeprofit_892 = 0;
   g_ord_lots_900 = 0;
   g_ord_lots_908 = 0;
   g_ord_lots_916 = 0;
   g_ord_open_price_924 = 0;
   g_ord_open_price_932 = 0;
   gd_940 = 0;
   gd_948 = 0;

   // === Open positions loop ===
   for(int i = 0; i < PositionsTotal(); i++)
   {
      if(PositionSelectByIndex(i))
      {
         string sym;
         long magic_number, type;
         double lots, open_price, tp;

         PositionGetString(POSITION_SYMBOL, sym);
         PositionGetInteger(POSITION_MAGIC, magic_number);
         PositionGetInteger(POSITION_TYPE, type);
         PositionGetDouble(POSITION_VOLUME, lots);
         PositionGetDouble(POSITION_PRICE_OPEN, open_price);
         PositionGetDouble(POSITION_TP, tp);

         ulong ticket = (ulong)PositionGetInteger(POSITION_TICKET);

         if(sym == _Symbol && magic_number == magic)
         {
            // BUY
            if(type == POSITION_TYPE_BUY && g_ticket_860 < (int)ticket)
            {
               g_ord_lots_900 = lots;
               g_ord_open_price_924 = open_price;
               g_ticket_860 = (int)ticket;
               g_ord_takeprofit_884 = tp;
               if(lots == Lot1) gd_940 = open_price - gi_80 * _Point;
            }
            // SELL
            if(type == POSITION_TYPE_SELL && g_ticket_864 < (int)ticket)
            {
               g_ord_lots_908 = lots;
               g_ord_open_price_932 = open_price;
               g_ticket_864 = (int)ticket;
               g_ord_takeprofit_892 = tp;
               if(lots == Lot1) gd_948 = open_price + gi_80 * _Point;
            }
         }
      }
   }

   // === Pending orders loop ===
   for(int i = 0; i < OrdersTotal(); i++)
   {
      if(OrderSelect(i, SELECT_BY_INDEX))
      {
         string sym;
         long magic_number, type;
         double lots;

         OrderGetString(ORDER_SYMBOL, sym);
         OrderGetInteger(ORDER_MAGIC, magic_number);
         OrderGetInteger(ORDER_TYPE, type);
         OrderGetDouble(ORDER_VOLUME_CURRENT, lots);

         ulong ticket = (ulong)OrderGetInteger(ORDER_TICKET);

         if(sym == _Symbol && magic_number == magic)
         {
            if(type == ORDER_TYPE_BUY_LIMIT)
            {
               g_ticket_876 = (int)ticket;
               g_ord_lots_916 = lots;
            }
            if(type == ORDER_TYPE_SELL_LIMIT)
            {
               g_ticket_880 = (int)ticket;
               g_ord_lots_916 = lots;
            }
         }
      }
   }
}
 

Latest Posts

Live Forex Chart

Currency
Rates
EUR / USD
1.15325
USD / JPY
155.424
GBP / USD
1.34795
USD / CHF
0.81961
USD / CAD
1.39347
EUR / JPY
179.243
AUD / USD
0.71273
Back
Top
Log in Register