Features of the mql5 language, subtleties and tricks - page 24

 
Alexey Viktorov:
And what will change from this?
The statement about Trade-events is fully consistent with the topic of the branch.
 

A simple short-term network failure nullifies the trading logic based ONLY on listening to Trade events.

That's why OnTradeTransaction adepts go a little overboard in their reasoning.

This is the mechanism of trading logic that will work properly on any platform

Forum on trading, automated trading systems and trading strategies testing

Good example of working with limit orders in an EA

fxsaber, 2017.01.02 23:12

I only trade through pending orders a bunch of the time. Not doing any processing at all. OrderSend returned -1 (MT4 or MT5+MT4Orders) - it didn't work and ok, because the next step is still a full view of the trading environment. And if there is no pending/position, but there should be, then there is a synchronization with the state that should be - the corresponding OrderSend is sent.

With this approach, all the nuances of regresses, partial executions, etc. are taken into account. The implementation is very simple and efficient. It has never failed.

I haven't tried asynchronous stuff and it does not seem to be much more complicated, but I can't claim for sure.

 
fxsaber:

A simple short-term network failure nullifies the trading logic based ONLY on listening to Trade events.

That's why OnTradeTransaction adepts go a little overboard in their reasoning.

This is the mechanism of trade logic that will serve faithfully on any platform

Yes, the only reliable way is to check the trading account status. All OnTrade* events cannot provide a reliable mechanism for managing trade orders.

As for asynchronous operations - their only advantage is that you can send trade orders in a row, without waiting for the results of previous orders. But the control of their execution also can't rely on events, in this respect there is no difference with the verification of the results of synchronous orders.

The state of the trading account is what we have at the time of the request (we make the request ourselves), if there are problems with the network - no problem, we can make requests until the network is restored. But relying on events we become completely dependent on external factors.

 

fxsaber:
This situation with Trade-events is fully consistent with the topic of this branch.

I`m not objecting, I`m just saying that it`s not necessary to catch such subtleties.

fxsaber:

A simple short-term network failure nullifies the trading logic based ONLY on listening to Trade events.

That's why OnTradeTransaction adepts go a little overboard in their reasoning.

This is the mechanism of trade logic that will work correctly on any platform

And I'm not going to discourage anyone from it. Moreover, I believe that it is very necessary to control the return from the server. Only there are different approaches. What you suggest is correct, but not a panacea.

Maybe this is my life principle: "I'll make it worse, but in my own way. If something happens, there will be no one to blame.

 

I'm used to using the MarketInfo(_Symbol, MODE_TICKVALUE) function for the point value of a symbol in 4. I did not encounter any problems yet.

It is not so uniform at different brokers in MT5. I ran a small script on EURUSD and USDJPY on two different accounts. I would like to draw your attention to the point value and contract size.

This is a demo account from MQ.

This is a demoaccount from Just2Trade:

Does anyone have a universal function that would make point value look the same?
I understand the size of a tick and the contract size should be taken into account, maybe something else?

I.e., if it is EURUSD and the deposit is dollar, then 1 five-digit pip would be equal to $1.

And in what cases should I use SYMBOL_TRADE_TICK_VALUE_PROFIT or SYMBOL_TRADE_TICK_VALUE_LOSS?
 
Vasiliy Pushkaryov:

I'm used to using the MarketInfo(_Symbol, MODE_TICKVALUE) function for the point value of a symbol in 4. I did not encounter any problems yet.

It is not so uniform at different brokers in MT5. I ran a small script on EURUSD and USDJPY on two different accounts. I would like to draw your attention to the point value and contract size.

This is a demo account from MQ.

This is a demoaccount from Just2Trade:

Does anyone have a universal function that would result in a uniform point value?
I understand the size of a tick and the contract size should be taken into account, maybe something else?

I.e., if it is EURUSD and the deposit is dollar, then 1 five-digit point is equal to 1 dollar.

When should I use SYMBOL_TRADE_TICK_VALUE_PROFIT or SYMBOL_TRADE_TICK_VALUE_LOSS?
That's when the "Nikonor's Office" will have the contract size like in normal, HUNDREDS of thousands, then the point value will be like in normal. In the meantime, you can multiply what you've got by 100,000 and get what you want.
 
Alexey Viktorov:
When the "Nikonor's office" will have a contract size like the normal ones, HUNDREDS of thousands, then the point value will be like the normal ones. In the meantime, you can multiply what you've got by 100,000 and get what you want.
I also once struggled with this. For MetaQuotes-Demo, the contract size is one; for Just2Trade, it is different. For forex - one, for stocks, etc. - for Forex, one for stocks, etc. It is different. The help helps helps me calculate these figures, they do not add up. And the customer is waiting... So we agreed that he will not automatically calculate it, but will just multiply it by 100. And only on his Just2Trade. I still don't understand this trick... :((
 
Artyom Trishkin:
I also once struggled with this. For MetaQuotes-Demo the contract size is one, for Just2Trade it is another. For forex ones it is the same, but for shares etc. it is different. - for Forex, one for stocks, etc. It is different. The help helps helps me calculate these figures, they do not add up. And the customer is waiting... So we agreed that he will not automatically calculate it, but will just multiply it by 100. And only on his Just2Trade. I still don't understand this trick... :((

What can be unclear here?

Example: I bought 1000 lots, i received 0.00001*1000/1 = 0.01

Another option, the contract size = 100000 bought 0.01 lot (100000*0.01=1000) got 1 point 1*1000/100000 = 0.01

This is for 5/3 digits.

ps; And in Insta the size of the standard contract was 10000.
 
Alexey Viktorov:

What can be unclear here?

Standard contract size = 1, bought 1000 lot, received 0.00001*1000/1 = 0.01 for 1 pip

Another option, the contract size = 100000 bought 0.01 lot (100000*0.01=1000) got 1 point 1*1000/100000 = 0.01

This is for 5/3 digits.

Alexey Viktorov: ps; And in Insta it was 10000 standard contract size.
I see, I'm just not used to deal with 3000 or 5000 lots. I should get used to it.
 
Vasiliy Pushkaryov:
I see, I'm just not used to using 3000 or 5000 lots. I'll have to get used to it.

If you're not used to it, you can write it this way

input double               lot         =  0.1;
input int                  take        =  100;   // TakeProfit

double takePips, contract;

/*******************Expert initialization function*******************/
int OnInit()
{
   contract = 100000/SymbolInfoDouble(_Symbol, SYMBOL_TRADE_CONTRACT_SIZE)*lot;
    takePips = take*_Point;
   return(INIT_SUCCEEDED);
}/*******************************************************************/

And in the OrderSend() function send a contract variable, regardless of the dealer's whim.
Reason: