Erreurs, bugs, questions - page 2380

 
fxsaber:

La logique qui existe déjà est cassée.

C'est plus intéressant.

bool CTrade::PositionClosePartial(const ulong ticket,const double volume,const ulong deviation,const string comment = "")
{
...
  m_request.comment = (comment == NULL) ? ::PositionGetString(POSITION_COMMENT) : comment;
...

Si nous ne changeons pas les appels, le commentaire sera écrasé comme avant.

Si nous passons explicitement NULL, nous copions le commentaire existant

 
Slava:

La logique qui existe déjà est violée.

Personne n'utilise cette logique. D'autant plus que c'est un faux.

 
Slava:

La logique qui existe déjà est cassée.

C'est plus intéressant.

Si vous ne modifiez pas les défis, le commentaire sera écrasé comme avant.

Si vous passez explicitement NULL, alors vous copiez le commentaire existant.

Jetez un coup d'œil et

bool CTrade::PositionClose(const string symbol,const ulong deviation)

il fait 10 ( !!!) tentatives pour fermer une position:( J'ai eu de telles situations lors du débogage (Netting, Real, Opening) :

2019.01.28 16:58:11.764 57384742        Si-3.19 buy     in      1.00    66492   98591318        -1.03   0.00    0.00            Price=66493
2019.01.28 17:01:14.586 57384818        Si-3.19 sell    out     1.00    66503   98591566        0.00    0.00    11.00           
2019.01.28 17:01:14.598 57384819        Si-3.19 sell    in      1.00    66502   98591567        -1.03   0.00    0.00            
2019.01.28 17:04:16.067 57385000        Si-3.19 buy     out     1.00    66514   98591891        0.00    0.00    -12.00          

la ligne en surbrillance correspond à la deuxième tentative de fermeture d'une position :) Comme vous pouvez le voir dans les journaux, cela n'a pas été un franc succès.

Pour l'instant, je l'utilise :

bool CTrade::PositionClose(const ulong ticket,const ulong deviation)

Il y a déjà une tentative de fermeture de la position par code. Il semble correct de laisser l'utilisateur contrôler le fait de fermer la position. 10 tentatives ne sont pas une panacée

 
Slava:

La logique qui existe déjà est brisée.

C'est plus intéressant.

Si nous ne changeons pas les appels, le commentaire sera écrasé comme avant.

Si nous passons explicitement NULL, nous copions le commentaire existant

Ou peut-être que ce sera plus pratique.

bool CTrade::PositionClosePartial(const ulong ticket,const double volume,const ulong deviation,const string comment = NULL)
{
...
  m_request.comment = (comment == NULL) ? ::PositionGetString(POSITION_COMMENT) : comment;
...

Ensuite, celui qui en a besoin l'écrasera avec une valeur vide. La valeur par défaut sera copiée.

 

Chers développeurs !

Le terminal a été mis à jour en 1983. Il y a quelques erreurs étranges dans le testeur lors de la création d'objets graphiques (je crée des lignes verticales et des lignes de tendance). En 1981, tout était normal.

Maintenant, je reçois des erreurs 4001.

Code de création :

//+------------------------------------------------------------------+
//| Создаем трендовую линию на чарте                                                                                    |
//+------------------------------------------------------------------+
void DrawTrendLine(const string id,// Строковый идентификатор
                   const datetime t1,         // Время первой точки линии
                   const datetime t2,         // Время второй точки линии
                   const double price,// Цена обеих точек линии
                   const color clr            // Цвет линии
                   )
  {
//--- Формируем имя линии
   const string name=_prefix+id+TimeToString(t1)+"_"+TimeToString(t2);
//--- Сбрасываем код последней ошибки
   ResetLastError();
//---
//Print( __FUNCTION__,": Создаем тренд-линию "+name+": t1 = "+TimeToString( t1 )+", t2 = "+TimeToString( t2 )+", price = "+DoubleToString( price ) );
//--- Создаем объект, проверяем создание
   if(ObjectCreate(0,name,OBJ_TREND,0,t1,price,t2,price))   // Если объект создан
     {
      //--- Меняем свойства линий
      ObjectSetInteger(0,name,OBJPROP_COLOR,clr);
      ObjectSetInteger(0,name,OBJPROP_BACK,true);
      ObjectSetInteger(0,name,OBJPROP_SELECTABLE,false);
      ObjectSetInteger(0,name,OBJPROP_SELECTED,false);
      ObjectSetInteger(0,name,OBJPROP_STYLE,STYLE_DOT);
      ObjectSetInteger(0,name,OBJPROP_RAY_LEFT,false);
      ObjectSetInteger(0,name,OBJPROP_RAY_RIGHT,false);
     }
   else                                                 // Если объект не создан
   Print(__FUNCTION__,": ОШИБКА #",GetLastError(),": Объект '"+name+"' не построен! t1 = "+TimeToString(t1)+", t2 = "+TimeToString(t2)+", price = "+DoubleToString(price));
  }
//+------------------------------------------------------------------+
//| Создаем вертикальную линию на чарте                              |
//+------------------------------------------------------------------+
void DrawVLine( const string id,         // Строковый идентификатор
               const datetime time      // Время
               )
  {
//--- Формируем имя линии
   const string name=_prefix+id+TimeToString(time);
//--- Сбрасываем код последней ошибки
   ResetLastError();
//--- Создаем объект, проверяем создание
   if(ObjectCreate(0,name,OBJ_VLINE,0,time,0))   // Если объект создан
     {
      //--- Меняем свойства линий
      ObjectSetInteger(0,name,OBJPROP_COLOR,_vLineClr);
      ObjectSetInteger(0,name,OBJPROP_BACK,true);
      ObjectSetInteger(0,name,OBJPROP_SELECTABLE,false);
      ObjectSetInteger(0,name,OBJPROP_SELECTED,false);
      ObjectSetInteger(0,name,OBJPROP_STYLE,STYLE_DOT);
     }
   else                                                 // Если объект не создан
   Print(__FUNCTION__,": ОШИБКА #",GetLastError(),": Объект '"+name+"' не построен! t1 = "+TimeToString(time));
  }
 
De plus, les commentaires dans le testeur ne sont plus affichés.
 

Question pour les développeurs.

Il manque un paramètre de commentaire à la fonctionmytrade.PositionClose(conststring symbol,ulong deviation=ULONG_MAX) de la bibliothèque standard:conststring comment="".

Est-ce un oubli ?

 

Il semble plus approprié d'écrire ici :

https://www.mql5.com/ru/forum/302709#comment_10570043

Вопросы по проектам / папки Projects и Shared Projects
Вопросы по проектам / папки Projects и Shared Projects
  • 2019.02.08
  • www.mql5.com
Попытался начать работать с проектами, но что-то не ладится. Допустим, уже есть исходный файл с инклудами...
 
Supprimez STATUS_TERMINAL_PATH de la documentation.
 

Erreur de NormalPrice ! Bon après-midi à tous. J'ai modifié c mql4 en mql5 et maintenant j'ai l'erreur NormalPrice. Veuillez m'aider à en comprendre la raison.

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

CPositionInfo  o_position;    //класс для управления открытыми позициями
CTrade         o_trade;     
CSymbolInfo    o_symbol;
COrderInfo     o_order;
//+------------------------------------------------------------------+
//| Переменные вводимые при запуске параметры                        |
//+------------------------------------------------------------------+
input double  StartLot    = 0.1;
input int     Indent      = 30;
input int     Step        = 10;
input double  ProfitClose = 20;
input int     MagicNumber = 12345;
input int     Slippage    = 30;
//+------------------------------------------------------------------+
//| Изменяемые параметры в программе                                 |
//+------------------------------------------------------------------+
int dStep;
int dIndent;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
   dStep = Step;
   dIndent = Indent;
   
   if (!o_symbol.Name(Symbol()))
      return(INIT_FAILED);
   
   RefreshRates();
   
   o_trade.SetExpertMagicNumber(MagicNumber);
   //Проверка режимов открытия ордеров через функцию
   if (IsFillingTypeAllowed (o_symbol.Name(), SYMBOL_FILLING_FOK))
   {
      o_trade.SetTypeFilling(ORDER_FILLING_FOK);
   }
   else if (IsFillingTypeAllowed (o_symbol.Name(), SYMBOL_FILLING_IOC))
   {
      o_trade.SetTypeFilling(ORDER_FILLING_IOC);
   }
   else 
   {
      o_trade.SetTypeFilling(ORDER_FILLING_RETURN);
   }

   o_trade.SetDeviationInPoints(Slippage);
   
   if (o_symbol.Digits() == 3 || o_symbol.Digits() == 5)
   {
      dStep    *= 10;
      dIndent  *= 10;
   }

   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
   datetime             lpos_time         = 0;
   double               lpos_price_open   = 0.0;
   double               lpos_volume       = 0.0;
   ENUM_POSITION_TYPE   lpos_type         = -1;
   int                  pos_count         = 0;
   double               sum_profit        = 0;
   //счечик открытых позиций
   for (int i = PositionsTotal() - 1; i>=0; i--)
   {
      if (o_position.SelectByIndex(i))
      {
         if (o_position.Symbol() == o_symbol.Name() && o_position.Magic() == MagicNumber)
         {
            if (o_position.Time() > lpos_time)//если время позиции больше чем время последней позиции
            {
               lpos_time         = o_position.Time();
               lpos_price_open   = o_position.PriceOpen();
               lpos_volume       = o_position.Volume();
               lpos_type         = o_position.PositionType();
            }
            pos_count++;
            sum_profit = sum_profit + o_position.Commission() + o_position.Swap() + o_position.Profit();
         }
      }
   
   }
   //счетчик количества отложенных ордеров
   int stop_count = 0;
   for (int i = OrdersTotal()-1; i>=0; i--) //OrderTotal считает только отложенные ордера
   {
      if (o_order.SelectByIndex(i))
      {
         if (o_order.Symbol() == o_symbol.Name() && o_order.Magic() == MagicNumber)
         stop_count++;
      }
   
   }
//Функция проверки котировок
   if (!RefreshRates())
      return;
   //
   if (sum_profit > ProfitClose)
   {
      CloseAll();
      return;
   }
   //
   if (pos_count>0)
   {
      if (lpos_type == POSITION_TYPE_BUY && o_symbol.Bid() < lpos_price_open - dStep * o_symbol.Point())
      {
         o_trade.Sell(lpos_volume * 2, o_symbol.Name());
      }   
      if (lpos_type == POSITION_TYPE_SELL && o_symbol.Ask() < lpos_price_open + dStep * o_symbol.Point())
      {
         o_trade.Buy(lpos_volume * 2, o_symbol.Name());
      }   
      o_trade.SellStop(StartLot, o_symbol.Bid() - dIndent * o_symbol.Point());
      o_trade.BuyStop(StartLot, o_symbol.Ask() + dIndent * o_symbol.Point());
      return;
   }
   if (pos_count > 0 && stop_count > 0)
      DeleteStopOrders(); 
}
//Функция проверки котировок
bool RefreshRates()
{
   if (!o_symbol.RefreshRates())
      return (false);
   if (o_symbol.Ask() == 0 || o_symbol.Bid() == 0)
      return (false);
   return(true);
}   

//+------------------------------------------------------------------+
bool IsFillingTypeAllowed (string symbol, int fill_type)
{
   int filling = (int) SymbolInfoInteger(symbol, SYMBOL_FILLING_MODE);//запрашиваем режим открытия
   return(filling && fill_type);
}   
//+------------------------------------------------------------------+
void  CloseAll()
{
   for (int index = PositionsTotal()-1; index >=0; index--)
   {
      if (o_position.SelectByIndex(index))
      {
         if (o_position.Symbol() == o_symbol.Name() && o_position.Magic() == MagicNumber)
         {
            o_trade.PositionClose(o_position.Ticket());
         }
      }
   }
}
//+Функция удаления стоп ордеров
void  DeleteStopOrders()
{
   for (int i = OrdersTotal()-1; i>-0; i--)
   {
      if (o_order.SelectByIndex(i))
         if (o_order.Symbol() == o_symbol.Name() && o_order.Magic() == MagicNumber)
            o_trade.OrderDelete(o_order.Ticket());
   }
}