Which design is correct? - page 7

 
Vladon:
I used to publish my own set on closing different types in codebase at one time.
In this case you are giving compiled files, which is of no use in this branch.
Vladon:
https://www.mql5.com/ru/code/mt4

And here, sorry, wrong forum.

No offence.

 

Oh, that's not it :-), now.


https://www.mql5.com/ru/code/9052

 
int Close_This_Symbol_All()
{
//----
  string a = "Всего ордеров = " + DoubleToStr(OrdersTotal(),0)+ "\n";
  for (int Cnt = OrdersTotal(); Cnt >= 0; Cnt--) 
  {
    if(!OrderSelect(Cnt, SELECT_BY_POS, MODE_TRADES)) break;

        while (!IsTradeAllowed()) Sleep(1000);
        RefreshRates();
        if(OrderType() == OP_BUY ) OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(Bid,Digits), slip, CLR_NONE);
        if(OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(Ask,Digits), slip, CLR_NONE);
       Comment(a+ GetLastError());  
  }
//----
   return(0);
}
Then such a design should, in theory, close all orders at all, but it closes only a pair of the current window, what is the error?
 
Vladon:

Oh, that's not it :-), now.


https://www.mql5.com/ru/code/9052


Yes, your kit is good, however I can't figure out where the bug is in my code.
 
valenok2003:

Yes, your kit is good, however I can't figure out where the bug is in my code.

int Close_This_Symbol_All()
{
//----
  string a = "Всего ордеров = " + DoubleToStr(OrdersTotal(),0)+ "\n";
  for (int Cnt = OrdersTotal(); Cnt >= 0; Cnt--) 
  {
    if(!OrderSelect(Cnt, SELECT_BY_POS, MODE_TRADES)) break;

        while (!IsTradeAllowed()) Sleep(1000);
        RefreshRates();
        if(OrderType() == OP_BUY ) OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(Bid,Digits), slip, CLR_NONE);
        if(OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(Ask,Digits), slip, CLR_NONE);
       Comment(a+ GetLastError());  
  }
//----
   return(0);
}


for (int  Cnt = OrdersTotal(); Cnt >= 0; Cnt--) 
Sometimes the stubbornness is astonishing. On page 3 of this thread and further down the thread you were shown a proper example of overriding orders. RTFM at the end of the day. How many times do I have to tell you: Exit outside an array. Orders with number
OrdersTotal()

does not exist ! Then it will work :

if(!OrderSelect(Cnt, SELECT_BY_POS, MODE_TRADES)) break;
 
VladislavVG:
Sometimes the stubbornness is just astounding. On page 3 of this thread and further down the thread you were shown the correct example of order overruns. RTFM at the end of the day. How many times do I have to tell you : Exit outside the array. Orders with number

does not exist ! Then it will work :


Vladislav, I apologise, it's not stubbornness, but rather inattention. I was experimenting and didn't correct the code.

Of course it is:

for (int  Cnt = OrdersTotal()-1; Cnt >= 0; Cnt--) 

However, this does not seem to be the reason, because the corrected design

int Close_This_Symbol_All()
{
//----
  string a = "Всего ордеров = " + DoubleToStr(OrdersTotal(),0)+ "\n";
  for (int Cnt = OrdersTotal()-1; Cnt >= 0; Cnt--) 
  {
    if(!OrderSelect(Cnt, SELECT_BY_POS, MODE_TRADES)) break;

        while (!IsTradeAllowed()) Sleep(1000);
        RefreshRates();
        if(OrderType() == OP_BUY ) OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(Bid,Digits), slip, CLR_NONE);
        if(OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(Ask,Digits), slip, CLR_NONE);
       Comment(a+ GetLastError());  
  }
//----
   return(0);
}

still closes orders only on the pair of the window on which you throw the script, but not all pairs.

 

From the starter's profile "I write in MQL4, including bespoke." - a typical example of over-zealousness.

I understand programmers can be average. You get used to it. And I myself sometimes write bad code, though I try. But what would be...

I confirm someone's old assumption, the starter has wool in his head.

 
valenok2003:


Vladislav, I apologize, it's not stubbornness, but rather inattention. I was experimenting and didn't correct the code.

Of course it is:

However, that does not seem to be the reason, because the corrected design

still closes orders only for a pair of the window on which the script is thrown, but not all pairs.

If all pairs, then you are not using Ask correctly, Bid - you are taking from the current chart. If you process errors when closing orders - you would see the messages.

instead of Ask - MarketInfo(OrderSymbol(),MODE_ASK); instead of Bid - MarketInfo(OrderSymbol(),MODE_BID);

Good luck.

ZS and change the name of the script, because according to the name it works correctly ;).

 
gip:

From the starter's profile "I write in MQL4, including bespoke." - a typical example of over-zealousness.

I understand programmers can be average. You get used to it. And I myself sometimes write bad code, though I try. But what would be...

I confirm someone's old assumption, the topic-starter has wool in his head.


It's a shame to hear that, of course. However, I never take orders that I cannot fulfil. And you, I hope, understand that order levels can also vary. And, as someone said - There's no shame in not knowing. It's a shame not to ask.... And as I understand it, this forum exists precisely to provide an opportunity for learning. And so your, snobbishness is not clear to me, and your criticism, I do not accept. Although I admit that you are the smartest on this forum.

P.S. The art of programming is not in the ability to write code, but in the ability to make a correct algorithm. It's like if you have been driving a Lada all your life and then you moved to Mercedes and don't know where all the knobs and buttons are, you haven't become a bad driver because of that.

 
VladislavVG:

If all pairs, you are not using Ask correctly, Bid - you are taking from the current chart. If you processed errors when closing orders, you would see the message.

instead of Ask - MarketInfo(OrderSymbol(),MODE_ASK); instead of Bid - MarketInfo(OrderSymbol(),MODE_BID);

Good luck.


Thank you very much, I'm processing the errors, the message comes back - wrong price, but I can't figure out what's wrong.
Reason: