Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1294

 
Vladimir Pastushak:
How do I understand the account type programmatically? Hedge or netting?
   if(m_account.MarginMode()!=ACCOUNT_MARGIN_MODE_RETAIL_HEDGING)
     {
      Alert("Only Hedging!");
      return(INIT_FAILED);
     }
 

Or like this

AccountInfoSample

   m_label_info[3].Description(m_account.MarginModeDescription());

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

//+------------------------------------------------------------------+
//|                                        MarginModeDescription.mq5 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#include <Trade\AccountInfo.mqh>
CAccountInfo      m_account;     // account info wrapper
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   string Pr= m_account.MarginModeDescription();
   Alert(Pr);
  }
//+------------------------------------------------------------------+
 
Please help me find an EA (script) which either puts a grid of virtual pending orders with specified parameters, or opens orders (one by one) in a specified direction with a specified take.
 

Please tell me where the error lies:

      for(int s=OrdersTotal()-1; s>=0; s--)          
         {
           if(o_orderInfo.SelectByIndex(s)) 
           if(o_orderInfo.OrderType()==ORDER_TYPE_SELL_STOP)
             {                 
               count_sell_stop++;
             }
         }  

      for(int s1=PositionsTotal()-1; s1>=0; s1--)          
         {
           if(o_orderInfo.SelectByIndex(s1)) 
           if(o_orderInfo.OrderType()==ORDER_TYPE_SELL)
             {                 
               count_sell++;
             }
         }  
         
      if(count_sell == 0 && count_sell_stop == 0)
         {
            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) - 100*_Point;
            sellstop_req3.sl           = sellstop_req3.price + 110*_Point;
            sellstop_req3.type         = ORDER_TYPE_SELL_STOP;
            sellstop_req3.type_filling = ORDER_FILLING_RETURN;
            sellstop_req3.expiration   = ORDER_TIME_GTC;
            
            OrderSend(sellstop_req3, sellstop_res3);
         }
SELL_STOP - the orders are calculated, but SELL doesn't want it. According to the algorithm, if there are none, the SELL_STOP order is placed, and if there is at least one of them, the order is not placed.
 
Fergert Фергерт:

Please tell me where the error lies:

SELL_STOP - orders are counted, but SELL does not want. According to the algorithm, if there are none, the SELL_STOP order is placed, and if at least one of them is present, no order is placed.

Don't confuse the LOCAL ORDER with the POSITION.

//+------------------------------------------------------------------+
//|                                                     Script 1.mq5 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
//---
#include <Trade\PositionInfo.mqh>
#include <Trade\OrderInfo.mqh>
//---
CPositionInfo  m_position;                   // object of CPositionInfo class
COrderInfo     m_order;                      // object of COrderInfo class
//---
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   int count_buys          = 0.0;
   int count_sells         = 0.0;
   int count_buy_limits    = 0.0;
   int count_sell_limits   = 0.0;
   int count_buy_stops     = 0.0;
   int count_sell_stops    = 0.0;
//---
   for(int i=PositionsTotal()-1; i>=0; i--)
      if(m_position.SelectByIndex(i)) // selects the position by index for further access to its properties
        {
         if(m_position.PositionType()==POSITION_TYPE_BUY)
            count_buys++;
         else
            if(m_position.PositionType()==POSITION_TYPE_SELL)
               count_sells++;
        }
//---
   for(int i=OrdersTotal()-1; i>=0; i--) // returns the number of current orders
      if(m_order.SelectByIndex(i)) // selects the pending order by index for further access to its properties
        {
         if(m_order.OrderType()==ORDER_TYPE_BUY_LIMIT)
            count_buy_limits++;
         else
            if(m_order.OrderType()==ORDER_TYPE_SELL_LIMIT)
               count_sell_limits++;
            else
               if(m_order.OrderType()==ORDER_TYPE_BUY_STOP)
                  count_buy_stops++;
               else
                  if(m_order.OrderType()==ORDER_TYPE_SELL_STOP)
                     count_sell_stops++;
        }
//--- you code
  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
Files:
Script_1.mq5  5 kb
 
Vladimir Karputov:

Don't confuse the REMOTE ORDER with the POSITION.

THANK YOU)) Got it...
 
I don't understand what the parameter begin in the second version of onCalculate function is responsible for.
Every time onCalculate function is called, it equals 0.
I was outputting the value of begin via print function.
The reference book says that begin is "where the meaningful data starts from". This doesn't tell me anything.
 
MisterRight:
I don't understand what parameter begin in second variant of onCalculate function is responsible for.
Every time onCalculate function is called, it equals 0.
I made the output of begin value via print function.
The reference book says that begin is "where meaningful data starts from". This doesn't tell me anything.

Look at the open indicator codes from Example.

 
Mikhail Mishanin:

Look at the open indicator codes from Example.

I looked. Always begin = 0.

Here, I pulled a piece of code from AMA indicator

if(begin!=0)

PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtPeriodAMA+begin);


And what should this code tell me if the condition begin!=0 is never true?

 
Can you tell me what to use to count closed orders in the history. I tried it like this:

HistorySelect(0,TimeCurrent());

Alert("Количество ордеров в истории:  ",HistoryOrdersTotal());
It gives out some nonsense in the end, much more than closed orders.
Reason: