How do I open a market order correctly? - page 8

 
Dmitry Fedoseev:
You're not the one who needs a pause.
That's just it.
 
Anyway, the bottom line, imho, is this.

Globally, there are 2 ways:

1) analysis of the environment (sucking in the history of transactions, checking the open position or the volume of the position);

2) analysis of transactions.

The first works slower. But it is more reliable. We need a compromise. Perhaps, we need to look at the strategy and depend on it.

Yes, FORTS has a full-fledged ticker, so one should not work with ticks but with the BookEvent event.

It's strange that Vasily Sokolov has not commented on this subject. His point of view is interesting...
 
Dennis Kirichenko:
Anyway, the bottom line, imho, is this.

Globally, there are 2 ways:

1) analysis of the environment (sucking in the history of transactions, checking the open position or the volume of the position);

2) analysis of transactions.

The first works slower. But it is more reliable. We need a compromise. Perhaps, we need to look at the strategy and depend on it.

Yes, FORTS has a full-fledged ticker, so one should not work with ticks but with the BookEvent event.

It's strange that Vasily Sokolov has not commented on this subject. His point of view is interesting...
Maybe soon I'll switch to glass, but for now .... in the old way.
 
Dennis Kirichenko:
Anyway, the bottom line, imho, is this.

Globally, there are two ways:

1) analysis of the environment (sucking in the history of transactions, checking the open position or the volume of the position);

2) analysis of transactions.

The first works slower. But it is more reliable. We need a compromise. Perhaps, we need to look at the strategy and depend on it.

Yes, FORTS has a full-fledged ticker, so one should not work with ticks but with the BookEvent event.

It's strange that Vasily Sokolov has not commented on this subject. His point of view is interesting...
By the way, I have a question: can we use theBookEvent event the same way we use Tick or Timer?
i.e. can I transfer my strategy there completely?
 
I remembered on the subject...

I once worked on this order and wrote the CiOnTrade class:
class CiOnTrade : public CTrade
It was an interesting task. I and my client got on each other's nerves and broke our hearts. As far as I remember, the main task was to buy/sell the guaranteed volume. And if part of the volume was not filled, we had to delete these orders and sell the rest at a different price...

So, the optimal solution I found was in processing the states. And there were so many of them:
enum ENUM_TRADE_STATE
  {
   TRADE_STATE_NONE=0,      // "ничего"
   TRADE_STATE_ORDERS=1,    // "только ордера"
   TRADE_STATE_POSITION=2,  // "только позиция"
   TRADE_STATE_ALL=3,       // "все"
  };
1) "Nothing" - this is the initial state, when nothing was done.

2) "Orders only" - this is the state when the orders are placed.

3) "Position only" is the state when orders are fully executed.

4) "All" is the state when the orders have not been executed completely and there is already a position in the market.

So each state had to be processed. Yes, by the way, I admit that there are intermediate states as well. So my class could be improved.
 
Gennady Mazur:
By the way, a question has arisen: can theBookEvent event be used in the same way as the Tick or the Timer?
i.e. can your strategy be fully transferred there?
Yes, but note that BookEvent generates events more often. That's why we need some filter to sift out the unnecessary ones. For example, the prices have not changed, but only the volumes of some bids...
 
Dennis Kirichenko:
Yes! But consider that the glass is more likely to generate events. Therefore, you need some filter to sift out unnecessary events. For example, prices have not changed, but only volumes of some bids...
I understand thanks...and in some cases volume change is more important than price change, especially near strong levels.
 
Dennis Kirichenko:
The bottom line, imho, is this.

Globally, there are two ways:

1) environment analysis (sucking up the history of trades, checking open position or position volume);

2) transaction analysis.

The first works slower. But it is more reliable. There must be a compromise. Perhaps we must look at the strategy and depend on it.
The OrderSend+Sleep(0) variant doesn't work slower than OrderSend+OnTradeTransaction. I measured it. That's why I don't use the second variant not for asynchronous transactions.
 
Dennis Kirichenko:
I assume that the info about the deal has not come yet. Here (marked in red), you rely on luck. And she is a capricious lady :-))

bool OpenSellPosition(string symbol, double volume, string comment="", ulong deviation=10, ENUM_ORDER_TYPE_FILLING filling=ORDER_FILLING_FOK)
{
  MqlTradeRequest Request;
  MqlTradeResult Results;
  ZeroMemory(Request);
  ZeroMemory(Results);
  Request.price=SymbolInfoDouble(_Symbol,SYMBOL_BID);
  Request.action=TRADE_ACTION_DEAL;
  Request.type=ORDER_TYPE_SELL;
  Request.symbol=symbol;
  Request.volume=volume;      
  Request.deviation=deviation;
  Request.comment=comment;  
  Request.type_filling=filling;
  bool res=false;
  res=OrderSend(Request,Results);
  if(res)
  {
    if(Results.deal>0) return(true);
    else return(false);

  }
  return(false);
}

Even withORDER_STATE_FILLED, Results.order can have a problem - Results.deal is zero. 100% reproduction of this situation is achieved on FXOpen-MT5 server.

I recommend to open many demos on different servers and achieve full functionality of the code. I did so for MT4 biblical. That's why there is no problem with the subgame.

 
fxsaber:
OrderSend+Sleep(0) is not slower than OrderSend+OnTradeTransaction. I measured it. Therefore, I don't use the second variant not for asynchronous transactions.

The OrderSend+Sleep(0) variant is temporary, because it's a shortcoming of developers (don't use it as an example :) ).

When it is corrected, only OrderSend will remain

Reason: