Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1820

 
Alexander Avksentyev #:

Hi

Got a profit order on a ticket, I want to close when it reaches -x.

But I get all orders closed in a row.

Can you tell me how to do this correctly?

How do you get all orders to close if I only see one OrderClose call?

It's not very clear where this code is even called... The robot's algorithm is also unclear...
 
Mihail Matkovskij #:

How do you close all orders if I only see one OrderClose call?

Closes an order as soon as it is opened

 
Tretyakov Rostyslav #:
That's not what you wanted - it's an example. I was making an EA for semi-automated trading.


What you want you have to write yourself).

If anything, I will help.

So, I will describe more specifically what I need for this Fast Pending Orders Panel EA, I have partially found pieces of code from this list (20%), but the rest I will need to ask you, colleagues.


1) Shell: display as such a board with buttons on the chart: BUY_lp(lower ASK in___pips), SELL_hp (higher BID in___pips) - number in pips entered manually on the board, BUY_lt (lower ASK up to____seconds),SELL_ht (higher BID up to____seconds) - number in seconds entered manually on the board, CLOSE_buys, CLOSE_sells - close all orders.

a) code to create a button on the chart; the scoreboard as a background object;

b) code for entering values into this scoreboard (pips, seconds) special fields for this

c) saving the value of pips to a certain memory file where the price is fixed after the button is pressed and the number of pips for the price at which you want to enter the market is added or subtracted;

d) saving the value of seconds in a certain memory file, where the minimum/maximum value of the price for the selected "in seconds" period is continuously counted;

2) inside: execution.

a) read value in pips and fixed price from file, after pressing BUY_lp or SELL_hp button, in order to compare it with current price;

b) when the BUY_lt or SELL_ht button is pressed, the value in seconds and the changed maximum/minimum price is read from the file so that it is compared with the current price;

c) when the current price reaches the required value - enter the market (open order);

d) button to close the order or all orders. This button should function differently depending on the execution mode; if the price was entered by "pips", then, after closing by an equal number of pips, the closing price should be different in the "better" direction (waiting for that price after you press "close"), if the button is "by seconds", then the best price should be calculated for a certain period (waiting for that price, but not lower/higher at the moment you pressed the button).

 
Alexander Avksentyev #:

Closes the order as soon as it opens

Well, yes. The profit always has a negative value the moment it is entered because of the spread... Try to decrease the value of x.

And it is better to make your own profit calculation function in pips (of course, if you do not want to set it in the deposit currency).
 
Mihail Matkovskij #:

Well, yes. Profit always has a negative value at the time of entry because of the spread... Try reducing the value of x.

-x less than spread, output to Print

if(OrderProfit()<=-x);

will be true if the conditions match. adding a close command. closes immediately

 
Mihail Matkovskij #:

Well, yes. Profit always has a negative value the moment after entry due to the presence of spread... Try reducing the value of x.

And it would be better to make your own function for calculating profit in pips (of course, if you don't want to set it in the deposit currency).

You can do it with points, it doesn't make much difference. I just wanted to make it simpler

 
Alexander Avksentyev #:

-x less than spread, output to Print

will be true if the conditions match. add a close command. closes immediately

Then the condition should be false according to you...?

Spread is measured in pips and OrderProfit returns a profit in the currency of the deposit depending on entry volume.

Do you see where you got the misunderstanding?

 
Mihail Matkovskij #:

Then the condition should be false...

Spread is measured in pips and OrderProfit returns a profit in the currency of the deposit, depending on the entry volume.

Do you see where you have a problem?

Set x, increase volume. And now the condition has always triggered. This approach does not work.

 
Mihail Matkovskij #:

Set x, increase the volume. And then the condition started to work all the time. This approach is no good at all.

You can do it this way and virtual sl. But I have not done it yet.

The main thing is to get a signal to close the order when it reaches -x

 
Alexander Avksentyev #:

You could do it that way, and you could do a virtual sl. But I haven't done that yet.

The main thing is to get a signal to close the order when it reaches -x

You really don't understand anything, do you? I tried to explain why your condition is always true and the order closes.

Reason: