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.
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
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(conststring id,// Строковый идентификаторconstdatetime t1, // Время первой точки линииconstdatetime t2, // Время второй точки линииconstdouble price,// Цена обеих точек линииconstcolor clr // Цвет линии
)
{
//--- Формируем имя линииconststring 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( conststring id, // Строковый идентификаторconstdatetime time // Время
)
{
//--- Формируем имя линииconststring 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));
}
Il manque un paramètre de commentaire à la fonctionmytrade.PositionClose(conststring symbol,ulong deviation=ULONG_MAX) de la bibliothèque standard:conststring comment="".
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;
//+------------------------------------------------------------------+//| Переменные вводимые при запуске параметры |//+------------------------------------------------------------------+inputdouble StartLot = 0.1;
inputint Indent = 30;
inputint Step = 10;
inputdouble ProfitClose = 20;
inputint MagicNumber = 12345;
inputint Slippage = 30;
//+------------------------------------------------------------------+//| Изменяемые параметры в программе |//+------------------------------------------------------------------+int dStep;
int dIndent;
//+------------------------------------------------------------------+//| Expert initialization function |//+------------------------------------------------------------------+intOnInit()
{
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);
}
elseif (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 |//+------------------------------------------------------------------+voidOnDeinit(constint reason)
{
}
//+------------------------------------------------------------------+//| Expert tick function |//+------------------------------------------------------------------+voidOnTick()
{
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();
}
//Функция проверки котировокboolRefreshRates()
{
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());
}
}
La logique qui existe déjà est cassé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
La logique qui existe déjà est violée.
Personne n'utilise cette logique. D'autant plus que c'est un faux.
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
il fait 10 ( !!!) tentatives pour fermer une position:( J'ai eu de telles situations lors du débogage (Netting, Real, Opening) :
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 :
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
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.
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 :
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
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.