Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1281

 
Vladimir Karputov:

Example of counting four types of pending orders in code Min Max for N Bars Martingal

Vladimir Karputov:

Example of counting four types of pending orders in code Min Max for N Bars Martingale 2

Vladimir Karputov:

An example of counting four types of pending orders in the code Min Max for N Bars Martingale 2




Vladimir, for some reason it does not count bylimit orders????

int count_buy_limits = 0;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(o_orderInfo.OrderType()==ORDER_TYPE_BUY_LIMIT)
{
count_buy_limits++;
}
}

 
Fergert Фергерт:


Vladimir, for some reason does not count bylimit orders????

int count_buy_limits = 0;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(o_orderInfo.OrderType()==ORDER_TYPE_BUY_LIMIT)
{
count_buy_limits++;
}
}

1. Insert the code correctly
2. Show all the code.
4. Screenshot of window with positions and pending orders
 
Vladimir Karputov:
1. Insert code correctly
2. Show all the code
3. Are there any compilation errors?
4. Screenshot of window with positions and pending orders

There are no compilation errors.

HERE IS THE CODE:

#include <Trade\Trade.mqh>
#include <Trade\OrderInfo.mqh>
#include <Trade\SymbolInfo.mqh>

CTrade      o_trade;
COrderInfo  o_orderInfo;
CSymbolInfo o_symbolInfo;

MqlTradeRequest   order_req={0}, buylimit_req1={0}, buylimit_req2={0}, sellstop_req3={0};
MqlTradeResult    order_res={0}, buylimit_res1={0}, buylimit_res2={0}, sellstop_res3={0};

//double   lot_r    = GlobalVariableGet("glot"); // Глобальная переменная
//double   lot_r    = 0.33;
double   lot_r    = NormalizeDouble(AccountInfoDouble(ACCOUNT_BALANCE)/15000,2);

int      tp_r     = 125;

double   lot_bl1  = 2.5;
double   lot_bl2  = 3;

double   lot_v    = NormalizeDouble(lot_r + (lot_r * lot_bl1) + (lot_r * lot_bl2), 2);

int      set_bl1  = 500;   
int      set_bl2  = 1000;
int      set_v    = 1100;

int      tp_bl1   = 70;
int      tp_bl2   = 480;

int OnInit()
  {
      order_req.action           = TRADE_ACTION_DEAL;
      order_req.symbol           = _Symbol;
      order_req.price            = SymbolInfoDouble(order_req.symbol, SYMBOL_ASK);
      order_req.volume           = lot_r;
      order_req.tp               = order_req.price+tp_r*_Point;
      order_req.type             = ORDER_TYPE_BUY;
      order_req.type_filling     = ORDER_FILLING_FOK;
      
      buylimit_req1.action       = TRADE_ACTION_PENDING;
      buylimit_req1.symbol       = _Symbol;
      buylimit_req1.volume       = NormalizeDouble(lot_r*lot_bl1, 2);
      buylimit_req1.price        = SymbolInfoDouble(buylimit_req1.symbol, SYMBOL_ASK)-set_bl1*_Point;
      buylimit_req1.tp           = order_req.price-tp_bl1*_Point;
      buylimit_req1.type         = ORDER_TYPE_BUY_LIMIT;
      buylimit_req1.type_filling = ORDER_FILLING_RETURN;
      buylimit_req1.expiration   = ORDER_TIME_GTC;
      buylimit_req1.magic        = 01;
      
      buylimit_req2.action       = TRADE_ACTION_PENDING;
      buylimit_req2.symbol       = _Symbol;
      buylimit_req2.volume       = NormalizeDouble(lot_r*lot_bl2, 2);
      buylimit_req2.price        = SymbolInfoDouble(buylimit_req2.symbol, SYMBOL_ASK)-set_bl2*_Point;
      buylimit_req2.tp           = order_req.price-tp_bl2*_Point;
      buylimit_req2.type         = ORDER_TYPE_BUY_LIMIT;
      buylimit_req2.type_filling = ORDER_FILLING_RETURN;
      buylimit_req2.expiration   = ORDER_TIME_GTC;
      buylimit_req1.magic        = 02;
      
      sellstop_req3.action       = TRADE_ACTION_PENDING;
      sellstop_req3.symbol       = _Symbol;
      sellstop_req3.volume       = NormalizeDouble(lot_v, 2);
      sellstop_req3.price        = SymbolInfoDouble(sellstop_req3.symbol, SYMBOL_ASK)-set_v*_Point;
      sellstop_req3.sl           = buylimit_req2.price + 10*_Point;
      sellstop_req3.type         = ORDER_TYPE_SELL_STOP;
      sellstop_req3.type_filling = ORDER_FILLING_RETURN;
      sellstop_req3.expiration   = ORDER_TIME_GTC;
      
   
   if(OrdersTotal()==0 && PositionsTotal() == 0)
      {
         OrderSend(order_req, order_res);
         OrderSend(buylimit_req1, buylimit_res1);
         OrderSend(buylimit_req2, buylimit_res2);
         OrderSend(sellstop_req3, sellstop_res3);
      }
   return(INIT_SUCCEEDED);
  }
void OnDeinit(const int reason)
  {

  
  }
 
 void OnTick()
  {
       int count_buy_limits = 0;
       for(int i=OrdersTotal()-1; i>=0; i--)
        {
          if(o_orderInfo.OrderType()==ORDER_TYPE_BUY_LIMIT)
               {
                  count_buy_limits++;
               }
        }   
      if(count_buy_limits < 2 || PositionsTotal() == 0)
         {
            for(int r=PositionsTotal()-1; r>=0; r--)
               {
                  ulong ticket=PositionGetTicket(r);
                  o_trade.PositionClose(ticket);   
               }  
      
            for(int o=OrdersTotal()-1; o>=0; o--)
               {
                  ulong ticket1=OrderGetTicket(o);
                  o_trade.OrderDelete(ticket1);
               }
      ExpertRemove();
         }
  }
//+------------------------------------------------------------------+
Files:
001.jpg  173 kb
 
Fergert Фергерт:

There are no compilation errors...

HERE'S THE CODE:

Carefully review my example and your example. You cannot copy mindlessly. You have to think a little. Look for an error in your code.

Insert the code correctly (using the Code button - I corrected your message the first time)

 
Vladimir Karputov:

Look carefully at my example and your example. You can't copy mindlessly. You have to think a little. Look for an error in your code.

Insert the code correctly (using the button - I corrected your message for the first time)

Yep, got it...
 
Fergert Фергерт:
Yep, got it all...

Yes, you forgot that if you bypass the loop, you have to BREAK at each iteration:

      if(m_order.SelectByIndex(i))     // selects the pending order by index for further access to its properties

Reference:

SelectByIndex

Selects an order for further access by the specified index

Документация по MQL5: Стандартная библиотека / Торговые классы / COrderInfo / SelectByIndex
Документация по MQL5: Стандартная библиотека / Торговые классы / COrderInfo / SelectByIndex
  • www.mql5.com
SelectByIndex(int) - COrderInfo - Торговые классы - Стандартная библиотека - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
Vladimir Karputov:

Yes, you forgot that if you bypass the loop, you have to BREAK at each iteration:

Reference:

SelectByIndex

Selects an order for further access by the specified index

Yeah. My bad..... THANKS VLADIMIR SO MUCH!!!!)))) Good luck to you......
 
Good afternoon to all forum members. I can't figure out how to use sliders. I have read the help, but still can't figure it out. I have read the help, but still do not understand it. I want to take readings of fast MA on 10 and 15 bars. I want to get slow MA on 10 and 15 bars, but my head is getting confused. I am confused. I used standard code and help. Help who knows how to implement this code. Thanks in advance.
 

Good afternoon.

No migration to"shared hosting" when transactions are open?

Or another reason?


I have closed the trades, it is not migrating anyway.

Expert works and loads everywhere, what could be the problem?

Виртуальный хостинг для MetaTrader 5
Виртуальный хостинг для MetaTrader 5
  • www.mql5.com
Самый быстрый виртуальный выделенный сервер (VPS) для трейдинга на форексе от производителей терминала MetaTrader 4/5
 
Aleksandr Prishenko:

Good afternoon.

No migration to"shared hosting" when transactions are open?

Or another reason?


I have closed the trades, it is not migrating anyway.

Expert Advisor works and is loaded everywhere, what could be the problem?

The problem is in the EA. By the way, the rules on shared hosting prohibit dlls.