Closing of positions. On indicator signal. - page 4

 
Thank you. I'll give it a try...
 
granit77:
If komposter and Vinin are to be believed, then instead:
for (int v=0; v<OrdersTotal(); v++)

write:
for (int v=OrdersTotal()-1; v>0; v--)

It works for me.
Mistake ;) This will close all orders except for the first.
This is the correct variant:
for ( int z = OrdersTotal() - 1; z >= 0; z -- )
{
 
}
 

I'll go and have a look.

granit77 and Vinin ! Is it working for you and closing all open positions? I have this piece for some reason.

то вместо:
for (int v=0; v<OrdersTotal(); v++) 
 
написать:
for (int v=OrdersTotal()-1; v>0; v--)
Started closing the last open position instead of the earliest open position. But all the others keep moving...
 
komposter:
granit77:
If komposter and Vinin are to be believed, instead:
for (int v=0; v<OrdersTotal(); v++)

write:
for (int v=OrdersTotal()-1; v>0; v--)

It works for me.
Mistake ;) This will close all orders except for the first.
This is the correct variant:
for ( int z = OrdersTotal() - 1; z >= 0; z -- )
{
 
}


Thank you! I will now try your recommendation !
 

The result is still the same! With the last option only the last open position is closed!

Let's try to figure it out!

int z = OrdersTotal() - 1

-Here, "z" equals the total number of open orders minus one! At the same time, we set z >=0.

Apparently, z-- probably means that we further (OrderSelect) search through the open orders starting from the most recent one ?

And it is clear that the last order will be closed . Since it was the first to "get into the distribution". But at this point, the execution of closing of other orders stops! And this algorithm waits for the next indicator signal to close. I think something should be added here. I do not know what to add....

And why - z = OrdersTotal() - 1; ?

 
rid:

The result is still the same! With the last option, only the last open position is closed!

Now remove return after OrderClose, and observe the result ;)
 
rid:

Why, in fact - z = OrdersTotal() - 1; ?

Because the number of orders is OrdersTotal(), the 1st order has index 0, and the last one, accordingly, OrdersTotal()-1.
Learn the basics ;)
 
rid:

The result is still the same! With the last option only the last open position is closed!

Let's try to figure it out!

It is even good for the brain and for the experience.

All bikes and motorbikes have already been (strikethrough) invented before us - put all orders into your own array (perhaps more than one) and do whatever manipulations you like with it. sort it by any criteria, or delete it (the ticket is your friend), or modify it (it's easy to make modifications of stoplosses/takeprofits, or create new orders.

ps (one more thing). if you decide to take your creation seriously, remember that at any second (millisecond) the connection with your brokerage company may disconnect. The ideal solution is to enable the Expert Advisor to see the necessity of closing certain orders (in this case) after an emergency stop/shutdown and close them.

However, most of publicly sold "grails" in the form of P.C. - are similarly toy-like...

 
Shu:

However, if you want to implement more complicated algorithms and get rid of migraines, keep it simple.
...
Put all orders into your array (maybe more than one) and make any manipulations on this array that your heart desires.

May I ask why? ;)
Of course, if there is some complicated logic or several algorithms in one, you can bother, but for a simple reverse Expert Advisor, why?
 
komposter:
Shu:

However, if you want to implement more complicated algorithms and get rid of migraines, keep it simple.
...
Put all orders into your array (may be, not only one) and use it to make any manipulations you like.

May I ask why? ;)
I see, if there's some complicated logic or several algorithms in one, you can bother, but for a simple flipping expert, why?


That's right - for complex logic. however, once he had tasted honey, Winnie couldn't forget it. :-)

If there is more than one order - I almost always use it. :-)