FORTS SL and TP

 

Hi!

Never used SL and TP

Please clarify.

Stop Loss and Take Profit are set on an existing position

Or can we set these parameters in an order being set, i.e. when the position is not yet open?

If we can specify parameters in an order, how should we calculate SL and TP in a market order(the position price is not fixed)?

 
prostotrader:

Hi!

Never used ST and TP

Please clarify.

Stop Loss and Take Profit are set on an existing position

Or can we set these parameters in an order being set, i.e. when the position is not yet open?

If we can specify parameters in an order, how should we calculate SL and TP in a market order(the position price is not fixed)?


You can specify any parameters, the levels are stored on the server. The same server can refuse to execute your stops.
 
Sergey Chalyshev:

You can set as you like, the levels are stored on the server. The same server may refuse to execute your stops.


That's why I don't want to get server's refusals.

I.e. is it better to set to an existing position (to be sure)?

 
prostotrader:


That's why I don't want to get server rejections.

I.e. is it better to install on an existing position (to be sure)?


Stops should not be set at all, put limiters.
 
prostotrader:


That's why I don't want to get server rejections.

I.e. is it better to install on an existing position (to be sure)?

I am illiterate in stock execution, but nevertheless. If slippage occurs, then the levels will be exactly equal to the size you set. I did not check it personally, but I read that without SL and TP, the order is executed faster. If it is really so, then it would be better to wait until the position is opened, and then work with it.
 
Sergey Chalyshev:

Stops are better not to be set at all, put limits.


That's why I've never used them before.

But, now I'm writing a CFORTSOrder class and it should have a function to set SL and TP

Added

POSITION_SL


POSITION_TP

Are these the minimum levels?

 
Vitaly Muzichenko:
I am illiterate in stock execution, but still. If there is slippage, the levels will be exactly equal to the size you set. I did not check it personally, but I read that without SL and TP, the order is executed faster. If it is really so, then it would be better to wait for the opening of the position, and then work with it.

Thanks
 
prostotrader:

Thank you
If you don't mind, you can personally check the speed of execution with and without preset orders, thereby proving or disproving the fact"without SL and TP the order is executed faster". I think it will be useful for some people.
 
Vitaly Muzichenko:
I am illiterate in exchange execution, but nevertheless. The order as a whole is better to place on an existing position, if there is slippage, the levels will be exactly the size that you set. I did not check it personally, but I read that without SL and TP, the order is executed faster. If it is really so, then it would be better to wait until the position is opened, and then work with it.


The stop orders themselves are triggered very quickly because they are stored on the server, and the server itself sends out the orders under the conditions. This saves ping to the server, compared to if you were to close at the market.

But limiters are more reliable and the speed is incomparable (latency = 0).

I have not measured speed physically, but I can see it by eye - price has not reached stop and deal has been executed and displayed in history, and then the chart starts to show price and deal.

 
prostotrader:


That's why I've never used it before.

But, now I'm writing a CFORTSOrder class and it should have a function to set SL and TP

Added

POSITION_SL


POSITION_TP

Are these the minimum levels?



Why not write a function without crutches that are stored on the server?

Write directly with the limits. Or at least TR with limits, and SL as you get it.

 
Sergey Chalyshev:


Why not write function without crutches which are stored on server?

Write at once with limits. Or at least TR with limits, and SL as you can.


And because I'll probably publish the class code.

I don't need it, but beginners may need it.

void CFORTSOrder::SetSlTp(const string a_symbol, const double a_sl=0, const double a_tp=0)
{
  if(PositionSelect(a_symbol))
  {
    ulong pos_ticket = ulong(PositionGetInteger(POSITION_TICKET));
    ENUM_POSITION_TYPE pos_type = ENUM_POSITION_TYPE(PositionGetInteger(POSITION_TYPE));
    double sl_level = PositionGetDouble(POSITION_SL);
    double tp_level = PositionGetDouble(POSITION_TP);
    MqlTradeRequest request = {0};
    MqlTradeResult  result  = {0};
    mem_magic = magic_storage + 1;
    if(magic_storage >= (magic_number + 65530)) mem_magic = magic_number;
    request.symbol = a_symbol;
    request.action = TRADE_ACTION_SLTP;
    request.comment = "Установка SL/TP";
    request.magic = mem_magic;
    request.position = pos_ticket;
    switch(pos_type)
    {
      case POSITION_TYPE_BUY:
        if (a_sl == 0)
        {
          request.sl = sl_level;
        }
        else
        if(a_sl <= sl_level)
        {
          request.sl = a_sl;
        }
        else request.sl = sl_level;
        if (a_tp == 0)
        {
          request.tp = tp_level;
        }
        else
        if(a_tp >= tp_level)
        {
          request.tp = a_tp;
        }
        else request.tp = tp_level;
      break;
      case POSITION_TYPE_SELL:
        if (a_sl == 0)
        {
          request.sl = sl_level;
        }
        else
        if(a_sl >= sl_level)
        {
          request.sl = a_sl;
        }
        else request.sl = sl_level;
        if (a_tp == 0)
        {
          request.tp = tp_level;
        }
        else
        if(a_tp <= tp_level)
        {
          request.tp = a_tp;
        }
        else request.tp = tp_level;
      break;
    }
    if(OrderSend(request, result))
    {
      if(result.retcode == TRADE_RETCODE_DONE)
      {
        magic_storage = mem_magic;
        Print(__FUNCTION__, ": SL и/или TP установлен.");
      }
    }
    else Print(__FUNCTION__, ": SL и/или TP не установлен.");
  }
}
Reason: