Questions from a "dummy" - page 140

 

Can you tell me, I am trying to set take profit and stop loss, the order is opened and SL and TP are not set, what is the problem and how to fix it?

 

CheckSYMBOL_TRADE_EXEMODE property for the tool, which can be one of the values ofENUM_SYMBOL_TRADE_EXECUTION enumeration :

ENUM_SYMBOL_TRADE_EXECUTION

Identifier

Description

SYMBOL_TRADE_EXECUTION_REQUEST

Trade on request

SYMBOL_TRADE_EXECUTION_INSTANT

Trade at streaming prices

SYMBOL_TRADE_EXECUTION_MARKET

Execution_execution_market

SYMBOL_TRADE_EXECUTION_EXCHANGE

Exchange execution

SL and TP are not requiredfor trading in SYMBOL_TRADE_EXECUTION_MARKETmode .

ENUM_SYMBOL_TRADE_EXECUTION trade_execution=(ENUM_SYMBOL_TRADE_EXECUTION)SymbolInfoInteger(_Symbol,SYMBOL_TRADE_EXEMODE);
 
T-G:

Can you tell me, I am trying to set take profit and stop loss, the order is opened and SL and TP are not set, what is the problem and how to fix it?

What is the Market Execution mode supported by the broker? If the Market Execution mode is supported , then SL and TP are not set for it.
 

Returns 3 - i.e. SYMBOL_TRADE_EXECUTION_MARKET

What do you mean by not providing SL and TP and if you need levels, what do you do? Or you mean to modify it after opening? If you modify it, can you give me an example function, thanks.

 
T-G:

Returns 3 - i.e. SYMBOL_TRADE_EXECUTION_MARKET

What do you mean by not providing SL and TP and if you need levels, what do you do? Or you mean to modify it after opening? If you modify it, can you give me an example function, thanks.

If you will use limit orders, you can set both stop and take. How close to the market can a limit order be set? Depends on the broker, from zero pips (i.e. at market price).
 
What if I need to follow the market? I opened an order and what should I do if I cannot set a TP and a SL?
 
Документация по MQL5: Стандартные константы, перечисления и структуры / Структуры данных / Структура торгового запроса
Документация по MQL5: Стандартные константы, перечисления и структуры / Структуры данных / Структура торгового запроса
  • www.mql5.com
Стандартные константы, перечисления и структуры / Структуры данных / Структура торгового запроса - Документация по MQL5
 
T-G:

What if I need to follow the market? I opened an order and what should I do if I cannot set the TP and SL?
After opening/modifying a position , you can use a separate request to set SL and TP levels.
 
T-G: Or do you mean to modify it after opening? If modified, can you give an example function, thanks.

This is where the MQL5 Reference / Standard constants, enumerations and structures / Data structures / Structure of a trade request says:

SL & TP Modification

Торговый приказ на модификацию уровней StopLoss и/или TakeProfit. Требуется указание 4 полей:

action 
symbol 
sl 
tp 

So the code is roughly like this (after checking for position):

bool PositionModify(const string symbol,double sl,double tp)
  { 
   m_request={0};
   m_result ={0};
//--- setting request
   m_request.action=TRADE_ACTION_SLTP;
   m_request.symbol=symbol;
   m_request.sl    =sl;
   m_request.tp    =tp;
//--- order send
   if(!OrderSend(m_request,m_result))
     {
      Print("Неудача с отправкой ордера при TRADE_ACTION_SLTP");
      return(false);
     }
//--- ok
   return(true);
  }
 
T-G:

Returns 3 - so you get SYMBOL_TRADE_EXECUTION_MARKET

The problem seems to be elsewhere.

void OnStart()
  {
   Print("SYMBOL_TRADE_EXECUTION_MARKET=",SYMBOL_TRADE_EXECUTION_MARKET);
  }
The value "3" is not returned in any way :) After all, the enumerations are numbered from zero.