Preguntas de los principiantes MQL5 MT5 MetaTrader 5 - página 1294

 
Vladimir Pastushak:
¿Cómo puedo entender el tipo de cuenta de forma programada? ¿Cobertura o red?
   if(m_account.MarginMode()!=ACCOUNT_MARGIN_MODE_RETAIL_HEDGING)
     {
      Alert("Only Hedging!");
      return(INIT_FAILED);
     }
 

O así

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);
  }
//+------------------------------------------------------------------+
 
Por favor, ayúdenme a encontrar un EA (script) que ponga una parrilla de órdenes pendientes virtuales con parámetros especificados, o que abra órdenes (una por una) en una dirección especificada con una toma especificada.
 

Por favor, dígame dónde está el error:

      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 - las órdenes se calculan, pero SELL no lo quiere. Según el algoritmo, si no hay ninguno, se coloca la orden SELL_STOP, y si hay al menos uno, no se coloca la orden.
 
Fergert Фергерт:

Por favor, dígame dónde está el error:

SELL_STOP - las órdenes se cuentan, pero SELL no quiere. Según el algoritmo, si no hay ninguno, se coloca la orden SELL_STOP, y si hay al menos uno, no se coloca ninguna orden.

No confundas el ORDEN LOCAL con la POSICIÓN.

//+------------------------------------------------------------------+
//|                                                     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
  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
Archivos adjuntos:
Script_1.mq5  5 kb
 
Vladimir Karputov:

No confundas el ORDEN REMOTO con la POSICIÓN.

GRACIAS)) Lo tengo...
 
No entiendo de qué es responsable el parámetro begin en la segunda variante de la función onCalculate.
Cada vez que se llama a la función onCalculate, ésta es igual a 0.
Estaba emitiendo el valor de begin a través de la función print.
El libro de referencia dice que el inicio es "el punto de partida de los datos significativos". Esto no me dice nada.
 
MisterRight:
No entiendo de qué es responsable el parámetro begin en la segunda variante de la función onCalculate.
Cada vez que se llama a la función onCalculate, es igual a 0.
Hice la salida del valor de inicio a través de la función print.
El libro de referencia dice que el inicio es "el punto de partida de los datos significativos". Esto no me dice nada.

Comprueba los códigos de los indicadores abiertos de Example.

 
Mikhail Mishanin:

Mira los códigos de los indicadores abiertos del Ejemplo.

He mirado. Siempre comienza = 0.

Aquí, he sacado un trozo de código del indicador AMA

si(¡inicio!=0)

PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtPeriodAMA+begin);


¿Y qué debería decirme este código si la condición ¡comienza!=0 nunca es verdadera?

 
Me podéis decir qué hay que utilizar para contar las órdenes cerradas en el historial. Lo he probado así:

HistorySelect(0,TimeCurrent());

Alert("Количество ордеров в истории:  ",HistoryOrdersTotal());
Al final da algunas tonterías, mucho más que las órdenes cerradas.
Razón de la queja: