Typical mistakes and how to deal with them when dealing with the trading environment - page 4

 
Artyom Trishkin:

And if the order is cancelled by the server?

Then on the next tick the EA will see that there are no positions, and everything will be fine. But there will be no doubling.


Artyom Trishkin:

I think that when accounting for market orders, we should return WRONG_VALUE, for example - positions cannot be less than zero. This will be a signal that there is an unrecorded market order. But do not add the number of positions.

This depends on the logic of specific TS.

In the most basic case where one trade in the market is allowed, any value other than 0 should be returned. 1 will also do.

 
Andrey Khatimlianskii:

Then on the next tick the advisor will see that there are no positions and everything will be fine. But there will be no duplication.


It depends on the logic of the particular TS.

In the most basic case, when one trade in the market is allowed, it is enough to return any value other than 0, 1 will do.

It (the Expert Advisor) will already receive, on this tick, a value greater than the amount of market orders. I.e., there are actually two of them, but the function will result in 3.

I think this is not normal behavior. We should always rest a valid number, without virtual positions, which may not end up being there.

After all, there are strategies that require precise calculations for a precise and defined number of positions, volumes, aggregate stop/stop levels, etc...

 
Andrey Khatimlianskii:

It depends on the logic of the particular TS.

In the most primitive case, when one trade in the market is allowed, it is enough to return any value other than 0, 1 will also do.

Andrew, a function that is asked for quantity or volume or any other quantitative data is obliged to give their exact value.

It's not like we're playing with toys :)

 
Artyom Trishkin:

Andrew, a function that is asked for quantity or volume or any other quantitative data is obliged to give its exact value.

You are looking at a specific example of an EA with one trade in the market, and it is written incorrectly 99% of the time. You still need to get to the complex ones.

If you really want, rename the function to IsPosition and make it boolean: return(Res>0);

 
Andrey Khatimlianskii:

A specific example of an EA with one trade in the market is considered and it is written wrong 99% of the time. You still need to get to the complex ones.

If you really want, rename the function to IsPosition and make it a boolean: return(Res>0);

Well, no... it's an example of some common library function "for all occasions"...

By the way, interesting proposal to make it a Boolean function - following the example of many standard mql5-functions - with return of execution result as bool value, and number of positions by passing value to a variable by reference.

 
Artyom Trishkin:

Well no..., an example of some kind of general library function "for all occasions" is being considered...

Yes, universal.

 
fxsaber:

Yes, universal.

The solution you proposed contains an inaccuracy in the cancellation of the order by the server. I would like to discuss options for handling this inaccuracy. Without them, the proposal is raw.
 
Artyom Trishkin:
The solution suggested by you contains an inaccuracy of order cancellation by the server. I would like to discuss how to deal with this inaccuracy. Without them the offer is raw.

Let's move away from MT5 towards MT4. An EA is trading. Suddenly, the broker makes a technical mistake (not you) and places a position on your account, which successfully passes the filter of the Expert Advisor friend-or-foe - Magic, Symbol, etc. Seconds later, the broker corrects his mistake - deletes (doesn't even close) his position from your account.

Will your TS break?


I remember a situation when a big broker who loves Expert Advisors did a great job. By "mistake" he deposited a very large amount to the account. Accordingly, the Expert Advisor opened a position with a very large lot. Then the broker corrected the "mistake" - withdrew the incorrectly credited money. The account was closed using a stop loss.

 
fxsaber:

Let's move away from MT5 towards MT4. An EA is trading. Suddenly, the broker makes a technical mistake (not you) and places a position on your account, which successfully passes the filter of the Expert Advisor friend-or-foe - Magic, Symbol, etc. Seconds later, the broker corrects his mistake - deletes (doesn't even close) his position from your account.

Will your TS break?


I remember a situation when a big broker who loves Expert Advisors did a great job. By "mistake" he deposited a very large amount to the account. Accordingly, the Expert Advisor opened a position with a very large lot. Then the broker corrected the "mistake" - withdrew the incorrectly credited money. The account was closed using a stopout.

We are not talking about the TS.
A function that MUST return what is physically in the account.
All the rest "imagine" - must be on the balance of the TS developer. But he should have a simple function in his arsenal which does not lie, and yet gives the ability to know about the uncertain state of the environment.
 

Artyom Trishkin:
Мы говорим не о ТС.

In the example we are talking about the specific TC situation described. And there the question is left unanswered.

A function that MUST return what is physically in the account.
All other "imagine" should be on the balance of the TC developer. But he should have a simple function in his arsenal, which does not lie, and at the same time gives a possibility to know about undefined state of the environment.

The function returns what is physically in the account. And it lies exactly as much as it would lie in MT4. I.e. everything is normal.