[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 581

 
lottamer:


And may I ask what they're trying to do with this?

for(int i=0; i<OrdersTotal(); i++)

it feels like they're trying to count open positions...

...But don't give in to your feelings, but refer to the rules. In this case, the loop is trying parameters (in the "list" of orders) involving an integer variable i, and its value is incremented by 1 with every iteration. The order number is being tried out. :)))
 
BeerGod:

Well this way it selects orders according to given parameters.

e.g. https://www. mql5.com/ru/forum/131859/page3#434221

Function NumberOfPositions().

This function returns the number of open positions at the moment. A more accurate selection of positions to be counted is specified by external parameters:

  • sy - Name of market instrument. If this parameter is set, the function will consider only positions of the specified instrument. The default value "" means any market instrument. NULL means the current instrument.
  • op - Trade operation, position type. Valid values: OP_BUY, OP_SELL or -1. The default value -1 means any position.
  • mn - Position identifier, MagicNumber. Default value -1 means any identifier.


thanks...i'll add that forum thread to my bookmarks. :))
 
Desead:


So deinit is called when I delete the robot from the chart - I can't track this condition any other way..... , it's probably easier to write a separate script that deletes all the remaining pending.

By the way, another thought on this subject:

I seem to have solved the problem of deleting orders. I calculated the number of "necessary" (to be removed) orders in a separate function, called this function and then while with a condition (Total>0), then the cycle of removing for(int i=Total-1;i<=0l; i--), again calculating"necessary", counter of removing attempts with an exit fromwhile when the given level is reached. This way everything is deleted.

An infinite loop may occur here in case one of the orders disappears after the moment of counting for any reason.


Order counting is done every time after the for loop for deleting an order, the counter iterates while with exit from the loop bybreak, when the counter reaches the value you set in the external variable, you can add error handling before the exit and output the result with
Alert(...)
or
Print( ...)
And as someone advised me to add a check for trade resolution. So there is no way to loop here.


 
Dimka-novitsek:

Good day!!! Can't find a pretty solution to the situation. Here is a typical order setting. But if I give zero to my robot in parameters, i.e. no stops and takeprofits, nothing will work.

We can also set an if and enter an order with zeros for the second time, but it is a bit cumbersome.

Everything is mature - at the level of art!!! ;)

And seriously - learn to think about what you have just written. At zero values of STOPPs according to your formula stoploss and take profit are equal to the opening price of an order, which is IMPOSSIBLE. Do you have any other solutions (can you use your brain??? :))?

 
Dimka-novitsek:

Good day!!! Can't find a pretty solution to the situation. Here is a typical order setting. But if I give zero to my robot in parameters, i.e. no stops and takeprofits, nothing will work.

We can also set an if and enter an order with zeros for the second time, but it is a bit cumbersome.



if (takeprofit!=0) TP = NormalizeDouble(Ask + takeprofit*Point,Digits); else TP=0;
if (stoploss!=0) SL = NormalizeDouble(Ask - stoploss*Point,Digits); else SL=0; 
 
rigonich:


...you're wrong (you haven't given the man a chance): if a man doesn't stimulate his grey matter, he'll spend his whole life "on the porch" - "Give me a hint, for Christ's sake!" :)))
 
BeerGod:

Well this way it selects orders according to given parameters.

e.g. https://www. mql5.com/ru/forum/131859/page3#434221

Function NumberOfPositions().

This function returns the number of open positions at the moment. A more accurate selection of positions to be counted is specified by external parameters:

  • sy - Name of market instrument. If this parameter is set, the function will consider only positions of the specified instrument. The default value "" means any market instrument. NULL means the current instrument.
  • op - Trade operation, position type. Valid values: OP_BUY, OP_SELL or -1. The default value of -1 means any position.
  • mn - Position identifier, MagicNumber. The default value of -1 means any identifier.


looked at

ModifyOrder() function. https://forum.mql4.com/ru/38949#434195

there are 3 parameters that need to be entered. Two I guessed, the third one I didn't.

What is UseSound on the next line?

----------------------------------------------------

if (UseSound) PlaySound("alert.wav"); break;

 
lottamer:


I would have let it work - I have one position and one tool.

But it doesn't work!

It says there's an error in the code

to this.

---------------------------

int start()

{

//----

if OrdersTotal()>0

PlaySound ("alert.wav");

//----

return(0);

}

-----------------------------

gives up 8 errors!!!


Put the condition (the one after if) in parentheses
 
TarasBY:

You've got it all mature - at an art level!!! ;)

And seriously - learn to think about what you have just written. If we set zero STOPPs according to your formula, stop loss and take profit are equal to the opening price of an order, which is UNACCEPTABLE. Do you have any other solutions (can you use your brain??? :))?


:))) oops, may I also clarify the following point in "pan-European"?

What is the difference between start and void functions?

 
TarasBY:

...you're wrong: if a person doesn't stimulate his grey matter, he will spend his whole life "on the porch" - "Give me a hint, for Christ's sake!" :)))


You're probably right but it's my philosophy in life - if it's not too much trouble, help others and they will help you when you need it. At 55, it's hard to change habits.

P.S. This is also how I learn.