Author: Copyright 2025, MetaQuotes Ltd.
Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reached
0 Views
0 Downloads
0 Favorites
CLaunch
ÿþ//+------------------------------------------------------------------+

//|                                                      CLaunch.mq4 |

//|                                  Copyright 2025, MetaQuotes Ltd. |

//|                                             https://www.mql5.com |

//+------------------------------------------------------------------+

#property library

#property copyright "Copyright 2025, MetaQuotes Ltd."

#property link      "https://www.mql5.com"

#property version   "1.00"

//#property strict



//--------------------------------------------------------------

//

// Launch - 0?CA:

//

// -B>B :;0AA 70?CA:05B >@45@0 =0 8A?>;=5=85

//

//--------------------------------------------------------------



//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

class CLaunch

  {

public:



                     CLaunch(void) {};



   int               MainBuy(string symb, int mag);

   int               MainBuyLimit(string symb, int mag);

   int               MainBuyStop(string symb, int mag);

   int               MainSell(string symb, int mag);

   int               MainSellLimit(string symb, int mag);

   int               MainSellStop(string symb, int mag);



   int               Main(string symb, int typ, int mag);



   int               Buy(string symb, double lot, int slip, double sl, double tp, int mag);

   int               BuyStop(string symb, double lot, int plus, int slip, double sl, double tp, int mag);

   int               BuyLimit(string symb, double lot, int plus, int slip, double sl, double tp, int mag);

   int               Sell(string symb, double lot, int slip, double sl, double tp, int mag);

   int               SellStop(string symb, double lot, int minus, int slip, double sl, double tp, int mag);

   int               SellLimit(string symb, double lot, int minus, int slip, double sl, double tp, int mag);



                    ~CLaunch(void) {};

  };

//+-------------------------------------------------------------

// 1. >4AG5B >B:@KB89 >@45@0 BUY

//+-------------------------------------------------------------

int CLaunch::MainBuy(string symb, int mag)

  {

   int cout=0;

   for(int i=OrdersTotal()-1; i>=0; i--)

     {

      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

        {

         if(OrderType()==OP_BUY &&

            OrderSymbol()==symb &&

            OrderMagicNumber()==mag)

           {

            cout++;

           }

        }

     }

   return cout;

  }

//+-------------------------------------------------------------

// 2. >4AG5B >B:@KB89 >@45@0 SELL

//+-------------------------------------------------------------

int CLaunch::MainSell(string symb, int mag)

  {

   int cout=0;

   for(int i=OrdersTotal()-1; i>=0; i--)

     {

      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

        {

         if(OrderType()==OP_SELL &&

            OrderSymbol()==symb &&

            OrderMagicNumber()==mag)

           {

            cout++;

           }

        }

     }

   return cout;

  }

//+-------------------------------------------------------------

// 3. >4AG5B >B:@KB89 >@45@0 BUYLIMIT

//+-------------------------------------------------------------

int CLaunch::MainBuyLimit(string symb, int mag)

  {

   int cout=0;

   for(int i=OrdersTotal()-1; i>=0; i--)

     {

      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

        {

         if(OrderType()==OP_BUYLIMIT &&

            OrderSymbol()==symb &&

            OrderMagicNumber()==mag)

           {

            cout++;

           }

        }

     }

   return cout;

  }

//+-------------------------------------------------------------

// 4. >4AG5B >B:@KB89 >@45@0 SELLLIMIT

//+-------------------------------------------------------------

int CLaunch::MainSellLimit(string symb, int mag)

  {

   int cout=0;

   for(int i=OrdersTotal()-1; i>=0; i--)

     {

      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

        {

         if(OrderType()==OP_SELLLIMIT &&

            OrderSymbol()==symb &&

            OrderMagicNumber()==mag)

           {

            cout++;

           }

        }

     }

   return cout;

  }

//+-------------------------------------------------------------

// 5. >4AG5B >B:@KB89 >@45@0 BUYSTOP

//+-------------------------------------------------------------

int CLaunch::MainBuyStop(string symb, int mag)

  {

   int cout=0;

   for(int i=OrdersTotal()-1; i>=0; i--)

     {

      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

        {

         if(OrderType()==OP_BUYSTOP &&

            OrderSymbol()==symb &&

            OrderMagicNumber()==mag)

           {

            cout++;

           }

        }

     }

   return cout;

  }

//+-------------------------------------------------------------

// 6. >4AG5B >B:@KB89 >@45@0 SELLSTOP

//+-------------------------------------------------------------

int CLaunch::MainSellStop(string symb, int mag)

  {

   int cout=0;

   for(int i=OrdersTotal()-1; i>=0; i--)

     {

      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

        {

         if(OrderType()==OP_SELLSTOP &&

            OrderSymbol()==symb &&

            OrderMagicNumber()==mag)

           {

            cout++;

           }

        }

     }

   return cout;

  }

//+-------------------------------------------------------------

//

//  -B> >1I89 4;O 2A5E (<>6=> ?>;L7>20BLAO B>;L:> MB8< >4=8<)...

//

//+-------------------------------------------------------------

int CLaunch::Main(string symb, int typ, int mag)

  {

   int cout=0;

   for(int i=OrdersTotal()-1; i>=0; i--)

     {

      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

        {

         if(OrderType()==typ &&

            OrderSymbol()==symb &&

            OrderMagicNumber()==mag)

           {

            cout++;

           }

        }

     }

   return cout;

  }

//+-------------------------------------------------------------

// 7. 5B>4K @01>BK A DC=:F859 | OrderSend =0 70?CA:

//+-------------------------------------------------------------

int CLaunch::Buy(string symb, double lot, int slip, double sl, double tp, int mag)

  {

   if(tp==0)

      tp=0;

   else

      tp=NormalizeDouble(Bid+tp*Point, Digits);



   if(sl==0)

      sl=0;

   else

      sl=NormalizeDouble(Bid-sl*Point, Digits);



   int ticket=OrderSend(

                 symb, OP_BUY, lot,

                 Ask, slip, sl, tp, "", mag, 0);



   return ticket;

  }

//--------------------------------------------------------------

//

//--------------------------------------------------------------

int CLaunch::BuyStop(string symb, double lot, int plus, int slip, double sl, double tp, int mag)

  {

   double pl=NormalizeDouble(Ask+plus*Point, Digits);



   if(tp==0)

      tp=0;

   else

      tp=NormalizeDouble(pl+tp*Point, Digits);



   if(sl==0)

      sl=0;

   else

      sl=NormalizeDouble(pl-sl*Point, Digits);



   int ticket=OrderSend(

                 symb, OP_BUYSTOP, lot,

                 pl, slip, sl, tp, "", mag, 0);



   return ticket;

  }

//--------------------------------------------------------------

//

//--------------------------------------------------------------

int CLaunch::BuyLimit(string symb, double lot, int plus, int slip, double sl, double tp, int mag)

  {

   double pl=NormalizeDouble(Ask-plus*Point, Digits);



   if(tp==0)

      tp=0;

   else

      tp=NormalizeDouble(pl+tp*Point, Digits);



   if(sl==0)

      sl=0;

   else

      sl=NormalizeDouble(pl-sl*Point, Digits);



   int ticket=OrderSend(

                 symb, OP_BUYLIMIT, lot,

                 pl, slip, sl, tp, "", mag, 0);



   return ticket;

  }

//--------------------------------------------------------------

//

//--------------------------------------------------------------

int CLaunch::Sell(string symb, double lot, int slip, double sl, double tp, int mag)

  {

   if(tp==0)

      tp=0.0;

   else

      tp=NormalizeDouble(Bid-tp*Point, Digits);



   if(sl==0)

      sl=0.0;

   else

      sl=NormalizeDouble(Bid+sl*Point, Digits);



   int ticket=OrderSend(

                 symb, OP_SELL, lot,

                 Bid, slip, sl, tp, NULL, mag, 0);

   if(ticket<0)

     {

      Print("OrderSend 7025@H8;0AL A >H81:>9 #", GetLastError());

     }

   else

      //Print("$C=:F8O OrderSend CA?5H=> 2K?>;=5=0");

      return ticket;



   return ticket;

  }

//--------------------------------------------------------------

//

//--------------------------------------------------------------

int CLaunch::SellStop(string symb, double lot, int minus, int slip, double sl, double tp, int mag)

  {

   double min=NormalizeDouble(Bid-minus*Point, Digits);



   if(tp==0)

      tp=0;

   else

      tp=NormalizeDouble(min-tp*Point, Digits);



   if(sl==0)

      sl=0;

   else

      sl=NormalizeDouble(min+sl*Point, Digits);



   int ticket=OrderSend(

                 symb, OP_SELLSTOP, lot,

                 min, slip, sl, tp, "", mag, 0);



   return ticket;

  }

//--------------------------------------------------------------

//

//--------------------------------------------------------------

int CLaunch::SellLimit(string symb, double lot, int minus, int slip, double sl, double tp, int mag)

  {

   double min=NormalizeDouble(Bid+minus*Point, Digits);



   if(tp==0)

      tp=0;

   else

      tp=NormalizeDouble(min-tp*Point, Digits);



   if(sl==0)

      sl=0;

   else

      sl=NormalizeDouble(min+sl*Point, Digits);



   int ticket=OrderSend(

                 symb, OP_SELLLIMIT, lot,

                 min, slip, sl, tp, "", mag, 0);



   return ticket;

  }

//--------------------------------------------------------------

//  close  $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

//--------------------------------------------------------------

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---