Cualquier pregunta de los recién llegados sobre MQL4 y MQL5, ayuda y discusión sobre algoritmos y códigos - página 1664

 
Taras Slobodyanik #:

Todavía tiene que comprobar las condiciones en cada nuevo tick, y si no funcionó en el tick anterior, cambiará en el nuevo.

Y hay que gestionar los errores.

Si lo haces a través de un array, entonces comprueba sólo los ticks de las órdenes modificadas escritas en él frente a todas las demás.

MakarFX #:
Así es, sí, gracias. En ese caso, si guardas en objetos, será mejor que tengas majicies únicas en lugar de entradas, de lo contrario habrá docenas de objetos con el mismo nombre.

StringToInteger(ObjectName(0,i,0)
¿Un error tipográfico? Creo que ambas funciones sólo pueden tomar un parámetro.
 
Документация по MQL5: Графические объекты / ObjectName
Документация по MQL5: Графические объекты / ObjectName
  • www.mql5.com
ObjectName - Графические объекты - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
Nerd Trader #:
Si lo haces a través de un array, entonces comprueba sólo los ticks de las órdenes modificadas escritas en él frente a todas las demás.

Más o menos, sí, gracias. En ese caso, si estamos guardando en objetos, será mejor que tengamos majicks únicos en lugar de entradas, de lo contrario habrá docenas de objetos con el mismo nombre.

¿Un error tipográfico? Creo que ambas funciones sólo pueden tomar un parámetro.

No lo harán.

if(ObjectName(i)!=OrderTicket()) ObjectDelete(0,ObjectName(i));

Lo siento

StringToInteger(ObjectName( i));
 
MakarFX #:

No lo harán.

Lo siento

Por cierto, ¿sabes por qué se produce periódicamente el siguiente error? Por cada 100 órdenes abiertas con éxito, hay unas 10.

2021.10.10 16:18:09.853	2021.01.05 21:15:00  test EURUSD,M5: 4051 | order.sl_price: 2.813499706815862e-262
2021.10.10 16:18:09.853	2021.01.05 21:15:00  test EURUSD,M5: OrderSend error 4051
2021.10.10 16:18:09.853	2021.01.05 21:15:00  test EURUSD,M5: unknown trade cmd 406958564 for OrderSend function

order.sl_price: 2.813499706815862e-262 - precio del bucle de parada, claramente este número no debería ser.
4051 - "Valor no válido del parámetro de la función"
- ¿es el tipo de orden? Tampoco debería haber problema con eso.

class Order{
  public:
    double open_price;
    double sl_price;
    double tp_price;
    color  arrow_color;
    string error_text;
    int cmd;

    Order(){};

    void InitForSell(string type = ""){
      if(type == ""){
        Print("Ошибка: 'type' должен иметь значение");
        return;
      }

      sl_price = NormalizeDouble(db_last.hight + (sl_indent*Point), Digits); // (цена + (кол-во пипсов*Point)


      arrow_color = clrRed;

      if(type == "sellstop"){
        open_price = NormalizeDouble(db_last.low - (order_indent*Point), Digits);

        if(tp_size != 0)
          tp_price = NormalizeDouble(db_last.low - (order_indent+tp_size)*Point, Digits);
        else
          tp_price = 0;

        cmd = OP_SELLSTOP;
        error_text = "Ошибка открытия селстопа ";
      }

      if(type == "sell"){
        open_price = Bid;

        if(tp_size != 0)
          tp_price = NormalizeDouble(Bid - tp_size*Point, Digits);
        else
          tp_price = 0;

        cmd = OP_SELL;
        error_text = "Ошибка открытия села ";
      }
    };

    void InitForBuy(string type = ""){
      if(type == ""){
        Print("Ошибка: 'type' должен иметь значение");
        return;
      }

      sl_price = NormalizeDouble(db_last.low - (sl_indent*Point), Digits); // (цена + (кол-во пипсов*Point)


      arrow_color = clrGreen;

      if(type == "buystop"){
        open_price = NormalizeDouble(db_last.hight + (order_indent*Point), Digits);

        if(tp_size != 0)
          tp_price = NormalizeDouble(db_last.hight + (order_indent+tp_size)*Point, Digits);
        else
          tp_price = 0;

        cmd = OP_BUYSTOP;
        error_text = "Ошибка открытия байстопа ";
      }

      if(type == "buy"){
        open_price = Ask;

        if(tp_size != 0)
          tp_price = NormalizeDouble(Bid + tp_size*Point, Digits);
        else
          tp_price = 0;

        cmd = OP_BUY;
        error_text = "Ошибка открытия бая ";
      }
    };

    ~Order(){};
};

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

if(...)
  {
    ResetLastError();
    int order_send = OrderSend(Symbol(), order.cmd, 0.01, order.open_price, 1, 
    order.sl_price, order.tp_price, "", 0, 0, order.arrow_color);

    if(order_send == -1) return;
  }
 
MakarFX #:
¿Se refiere a "mínimo y máximo" por billete o por precio?

Por billete

 
Nerd Trader #:

Por cierto, ¿sabes por qué se produce periódicamente el siguiente error? Por cada 100 órdenes abiertas con éxito, hay unas 10.

order.sl_price: 2.813499706815862e-262 - precio de parada, claramente este número no debería ser.
4051 - "Valor no válido del parámetro de la función"
- ¿es el tipo de orden? Tampoco debería haber problemas con él.

Intenta mover "NormalizeDouble"

if(...)
  {
    ResetLastError();
    int order_send = OrderSend(Symbol(), order.cmd, 0.01, NormalizeDouble(order.open_price, Digits), 1, 
    NormalizeDouble(order.sl_price, Digits), NormalizeDouble(order.tp_price, Digits), "", 0, 0, order.arrow_color);

    if(order_send == -1) return;
  }

 
EVGENII SHELIPOV #:

Por billete

//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 19.02.2008                                                     |
//|  Описание : Возвращает суммарный профит открытых позиций в пунктах         |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   (""   - любой символ,                   |
//|                                     NULL - текущий символ)                 |
//|    op - операция                   (-1   - любая позиция)                  |
//|    mn - MagicNumber                (-1   - любой магик)                    |
//+----------------------------------------------------------------------------+
int GetProfitOpenPosInPoint(string sy="", int op=-1, int mn=-1) {
  double p;
  int    i, k=OrdersTotal(), pr=0;

  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if ((OrderSymbol()==sy || sy=="") && (op<0 || OrderType()==op)) {
        if (mn<0 || OrderMagicNumber()==mn) {
          if (OrderTicket()== GetTicketMaxMinOrder(0) || OrderTicket()== GetTicketMaxMinOrder(1) ) {
             p=MarketInfo(OrderSymbol(), MODE_POINT);
             if (p==0) if (StringFind(OrderSymbol(), "JPY")<0) p=0.0001; else p=0.01;
             if (OrderType()==OP_BUY) {
               pr+=(MarketInfo(OrderSymbol(), MODE_BID)-OrderOpenPrice())/p;
             }
             if (OrderType()==OP_SELL) {
               pr+=(OrderOpenPrice()-MarketInfo(OrderSymbol(), MODE_ASK))/p;
            }
          }
        }
      }
    }
  }
  return(pr);
}
 
MakarFX #:

Intenta mover "NormalizeDouble"

sin cambios.

 
MakarFX #:

Makar ha insertado código en el EA hasta ahora sólo para comparar el beneficio en moneda y el beneficio en pips por lo que entiendo que se puede entender cuando estas funciones tienen valores cero


Razón de la queja: