Errors, bugs, questions - page 2410

 
Vladimir Karputov:

Nuh-uh :)

OK. Enlighten us. What error in the code, or what code, can close a position in the tester at the price of another instrument. I'm really, really interested.

Совершение сделок - Торговые операции - MetaTrader 5
Совершение сделок - Торговые операции - MetaTrader 5
  • www.metatrader5.com
Торговая деятельность в платформе связана с формированием и отсылкой рыночных и отложенных ордеров для исполнения брокером, а также с управлением текущими позициями путем их модификации или закрытия. Платформа позволяет удобно просматривать торговую историю на счете, настраивать оповещения о событиях на рынке и многое другое. Открытие позиций...
 
Aleksey Sergan:

The code is several thousand lines. There is no point in appending it. there are no static variables. There are classes. In any case it is the tester's error.

There is your error.

In debug mode, run a check before sending the trade order. Look at the symbol and prices. And test at least in "All ticks" mode.

 
Andrey Barinov:

OK. Enlighten us. What error in the code, or what code, could close a position in the tester at the price of another instrument. I am really, really curious.

Easily. It depends directly on the slavishness of the code. I did it myself :). Poorly thought-out system of character class initialization control. And plus there are static variables.

Anyway, it's meaningless to speak further without the code written by the person you are asking about.

 
Vladimir Karputov:

Easily. It's a direct correlation to the curvature of the code. I have done it myself :). Insufficiently elaborate system of character class initialization control. And moreover there are static variables.

So it's meaningless to speak further without asking you about the code.

Can you show us an example of code? How do I close a position in EURUSD at GPBUSD price?

If so, it will not be a problem for you. I would be very grateful.

 
Andrey Barinov:

Can you show me an example code? How do I close a EURUSD position at GPBUSD price?

If so, it would be no problem for you. I will be very grateful.

Forum on trading, automated trading systems & strategy testing

Bugs, bugs, questions

Vladimir Karputov, 2019.03.24 05:58

It's easy. The dependence of the code curvature. I made such mistakes myself :). Insufficiently well-thought-out system of character class initialization control. And plus static variables.

Anyway, it's meaningless to speak further without the code written by the person you are asking about.


 
That's how cool the tester graals can be, no more trailing pips, cool)
 

There is no error in debugging, visualisation mode. The position is closed not by trade order, but by stop loss:



Quite possibly a logical error in the code, most likely here, I will look into it, of course, don't know how yet - no error in debug mode:



it manages to set a stop for an order at 1.60704, 3000 pips above the current price of the position.

The tester should have prohibited the stop setting in this case.

 

Here I am looking at the log:

the order to change the stop is sent for gpbusd, the highlighted line, but is actually executed for eurusd- next.


here's the code to set the stop


bool MyOrderSend( MqlTradeRequest &req, MqlTradeResult &res ){

  
  //Print("Попытка выполнения OrderSend ... ");
  Print("Try to execute OrderSend ... for ", req.symbol );
  ResetLastError();
  if (OrderSend( req, res  )){
    if( res.retcode != TRADE_RETCODE_DONE ){
      //Print("Ошибка обработки торгового запроса,код ответа сервера: ", res.retcode, "Описание:", TradeServerReturnCodeDescription(res.retcode) );
      Print("Error of trade requaest: ", res.retcode, "Description:", TradeServerReturnCodeDescription(res.retcode) );
      Print(STradeRequest(req) );
      return(false);
    }else{
      //Print("Успех, код ответа сервера: ", IntegerToString(res.retcode), " Описание:",  TradeServerReturnCodeDescription(res.retcode)  );
      Print("Success, return code is : ", IntegerToString(res.retcode), " Description:",  TradeServerReturnCodeDescription(res.retcode)  );
      Print(STradeRequest(req) );
    }
    return(true);
  }else{
    //Print("Ошибка выполнения OrderSend в ", __FUNCTION__, " _LastError=", _LastError, " ",  ErrorDescription(_LastError) );
    Print("Error of execution OrderSend in ", __FUNCTION__, " _LastError=", _LastError, " ",  ErrorDescription(_LastError) );
    //Print("Код ответа сервера: ", IntegerToString(res.retcode), " Описание:",  TradeServerReturnCodeDescription(res.retcode)  );
    Print("Server return code : ", IntegerToString(res.retcode), " Description:",  TradeServerReturnCodeDescription(res.retcode)  );
    Print(STradeRequest(req) ); 
    return(false);
  }
  return(true);
}


where


OrderSend( req, res  )

native mql function, not overloaded.

i.e. here

 Print("Try to execute OrderSend ... for ", req.symbol );


it says that it sets a stop for gbpusd and should be so, but in fact


OrderSend( req, res  )


sets it for eurusd

 
Aleksey Sergan:

Here I am looking at the log:

the order to change the stop is sent for gpbusd, the highlighted line, but is actually executed for eurusd- the next one.

there are 2 mistakes.

№1. Your mistake. Somewhere in the code. You set a SL for a EURUSD position using GBPUSD price. The terminal should have nothing against it.

№2. Bug in the terminal. If this SL is triggered at a price that does not exist at the time in the EURUSD flow, using the GBPUSD price.

 
Aleksey Sergan:

Here I am looking at the log:

the order to change the stop is sent for gpbusd, the highlighted line, but is actually executed for eurusd- next.


here's the code to set the stop



where


native mql function, not overloaded.

https://www.mql5.com/ru/docs/constants/structures/mqltraderequest

Apparently when sending a modification request, the position field takes precedence over the symbol. Printreq.position

Документация по MQL5: Константы, перечисления и структуры / Структуры данных / Структура торгового запроса
Документация по MQL5: Константы, перечисления и структуры / Структуры данных / Структура торгового запроса
  • www.mql5.com
Взаимодействие клиентского терминала и торгового сервера для проведения операций постановки ордеров производится посредством торговых запросов. Запрос представлен специальной предопределенной структурой MqlTradeRequest, которая содержит все поля, необходимые для заключения торговых сделок. Результат обработки запроса представлен структурой...