For loop refusing to loop through ALL orders in the ledger.

 

Right, I just do not get the logic behind why MQL4 is outright refusing to display the correct order position information on the correct chart, as in the chart with which the order was placed upon.

I just do not get why - despite the fact that I have specifically told it to loop through ALL of the orders using the `for` loop - it will only show the information on last order on all the charts with which an order has been placed. 

Is there any particular valid reason as to why it's just refusing to do what I ask of it. With one position in the ledger, it works a dream. With more than one order, it just goes crazy, because on each chart with which an order has been placed upon, it only displays the information pertaining to the bottom order in the ledger. It does not loop through all the orders. 

I have looked and rechecked my code over and over and over again & I just cannot see why it's refusing to loop through all the orders on each iteration.

Here is my setup:

void OnTick()
  {

int TotalOpenOrders = OrdersTotal();
   
   if(TotalOpenOrders > 0){
   
      for(int i = TotalOpenOrders - 1; i >=0; i--){
      
         if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)){
               
            if(OrderSymbol() == Symbol()){
            
               if(OrderMagicNumber() == Period()){
               
                  ChartButtonStaticAttributes(); //No issues here
                  
                  ChartButtonFluidAttributes(clrGreen,clrCrimson,clrGray);
                                 
               } else {
               
                  continue;
               
               }
            
            } else {
            
               continue;
            
            }
            
         } else {
         
            continue;
         
         }
      
      }
   
   }
}

The following pertains to the chart objects which are to be drawn on the chart.

ChartButtonStaticAttributes();
                  
ChartButtonFluidAttributes(clrGreen,clrCrimson,clrGray);

I have tried `

for(int i = 0 - 1; i < TotalOpenOrders; i++)

but it makes absolutely no difference whatsoever.

There are no error 4105 logs either, which means that it does not have any issues with selecting the order itself, so its just not bothering to select the next order in the sequence - on the following iteration - in the first place. 

I have also ran all the tiket numbers of all the orders in the ledger:

2024.07.19 14:30:52.480 2024.16.1.0 EURAUD,H1: Order 0 Ticket Number: 152743361
2024.07.19 14:30:52.324 2024.16.1.0 EURCAD,H1: Order 1 Ticket Number: 152744231


So we can see that is actually has no issues looping through all the order - so it's just down to it just refusing to display the correct information on the correct chart. I just do not understand this.

It just loops and it loops and it loops and it loops and it loops when it prints the above ticket number, why is it constantly looping? Its not a `while` loop, it's a `for` loop, a for loop performs a function for a pre-specified number of iterations - in this case - the number of open order.

Rally sorry but have MQLQ4 changed all the rulls with all of the function since I deep-dived into this? Its just that everything id doing the exact opposite of what the manual days: 

  • it does not seem to like looping through all the orders:
  • yet it continuously loops until infinity when printing out logging information
  • am I literally going to scream.

As you can see in the following logs, everything matches up:

2024.07.19 13:46:17.719 2024.16.1.0 EURAUD,H1: Symbol() = EURAUD
2024.07.19 13:46:17.719 2024.16.1.0 EURAUD,H1: OrderSymbol() = EURAUD
2024.07.19 13:46:17.719 2024.16.1.0 EURAUD,H1: OrderMagicNumber() = 60
2024.07.19 13:46:17.719 2024.16.1.0 EURAUD,H1: Period() = 60
2024.07.19 13:46:17.719 2024.16.1.0 EURAUD,H1: TotalOpenOrders -1 = 
0 
2024.07.19 13:46:17.719 2024.16.1.0 EURAUD,H1: OrdersTotal() = 1 
Why is it refusing to continue through ALL the open orders on the next iteration? Why does it only stop at the bottom order in the ledger despite the fact that it's a for loop, and therefore for loops are supposed to loop through all the open order (based in my setup)?
Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Types
Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Types
  • www.mql5.com
When a graphical object is created using the ObjectCreate() function, it's necessary to specify the type of object being created, which can be one...
 
TheFlyingPrussian:


So we can see that is actually has no issues looping through all the order - so it's just down to it just refusing to display the correct information on the correct chart. I just do not understand this.


the code you posted does not display anything on the chart.... the function it calls might do, but you say there is nothing wrong with it, so unless you post all the relevant code not a lot to be said.

 
TheFlyingPrussian:
it will only show the information on last order on all the charts with which an order has been placed

You have only one order:

TheFlyingPrussian:
2024.07.19 13:46:17.719 2024.16.1.0 EURAUD,H1: Symbol() = EURAUD
2024.07.19 13:46:17.719 2024.16.1.0 EURAUD,H1: OrderSymbol() = EURAUD
2024.07.19 13:46:17.719 2024.16.1.0 EURAUD,H1: OrderMagicNumber() = 60
2024.07.19 13:46:17.719 2024.16.1.0 EURAUD,H1: Period() = 60
2024.07.19 13:46:17.719 2024.16.1.0 EURAUD,H1: TotalOpenOrders -1 = 
0 
2024.07.19 13:46:17.719 2024.16.1.0 EURAUD,H1: OrdersTotal() = 1 
 
Paul Anscombe #:

the code you posted does not display anything on the chart.... the function it calls might do, but you say there is nothing wrong with it, so unless you post all the relevant code not a lot to be said.

They do display objects on the chart.

Because its contradicting itself, it works when looping through printing out the ticket numbers but it not when it displays the correct information on the correct chart. its like it chooses when it wants to work. This is really trying my patience. I am going to go absolutely crazy in a second.

This is so unfair, I work so bloody had and every time I get to thrown back in my face by software that just doesn't want to know. I am getting so tired of everything I try not working, I'm literally on my knees with this thing, I have to spent all day troubleshooting this but I just cannot get it to work. I am going to start scream. 

To answer your question, these display the fluid attributes,

#Included in header of MQL file.
#include <ChartButtonStaticAttrs.mqh>
#include <ChartButtonFluidAttrs.mqh>



#include/
void ChartButtonFluidAttributes(color ProfitColor, color LossColor, color ButtonUnavailable){

	ObjectSetString(0,ChartID_CloseButton, OBJPROP_TEXT,"Close Ticket #"+string(OrderTicket())+" with a "+(OrderProfit()> 0.01 ? "profit" : "loss")+" of "+AccountCurrency()+DoubleToString(OrderProfit(),2));    

      //ChartID_CloseButton - This object is drawn on the chart
    
}

Now, instead of displaying the correct ticket number on the correct chart, its displays the ticket number for the last order on both chart.  That says to me that it stops looping when ti selects the bottom order and for no apparent reason either.

Why does it do thing when I have specifically told it to loop through ALL the sodding orders!

Why is it so difficult for this thing to understand that it's a for loop, it begins with the total number or order - 1...

i = TotalOpenOrders - 1

), and it ends with 0 (meaning there is one order left)...

i >=0

and it decrements it....

i--

Why is it so difficult for the terminal to comprehended that? If i, a human, can understand this, why can't a computer understand that? 

Why is it that everything simple time I tell a piece of software to do something and it just does not listen to me.

I'm sorry, but I have every single right to be absolutely furious over this. I will not tolerate spending all day on a problems with a piece of software that just will not do as its told. When you read manuals and then it just does the complete opposite of what you are telling to, then I will get furious.

There is absolutely no logic as to why this software is behaving like this whatever. 

 
Vladislav Boyko #:

You have only one order:

Yup, works with only one order. Multiple orders, nope, it just refused to display the correct information on the correct chart. 

 
TheFlyingPrussian #:
ObjectSetString ( 0 ,ChartID_CloseButton, OBJPROP_TEXT , "Close Ticket #" + string (OrderTicket())+ " with a " +(OrderProfit()> 0.01 ? "profit" : "loss" )+ " of " +AccountCurrency()+ DoubleToString (OrderProfit(), 2 ));

Are you sure you need current orders? Maybe you want to draw order history rather than current orders?

 
Vladislav Boyko #:

Are you sure you need current orders? Maybe you want to draw order history rather than current orders?Yes @v

No @Vladislav I need the current, open orders. 

I am so tired of this. I'm tired of screaming, I'm so tired of struggling, I'm so tired of getting to end of my tether with everything, I'm so tired of not feeling like I'm good enough. I am so tired of it all. You have no idea how much effort and time and stress and aggro I have to put in,just because this stupid platform doesn't clearly know what a for loop is. I have absolutely had it with thing. I am literally about to pick this computer up and throw it against the wall because right now, that might kick MQL4 into gear and actually start doing as it's told for one. 

Sick to death. I am so angry right now, I could scream. 

IT
IS
A
FOR
LOOP

I have told it to go through EVERY SINGLE ORDER IN THE LEDGER. That is all I've told it to do, I haven't told it to perform open heart surgery, I haven't told it to fly a jumbo jet half way around the sodding world. I have told it to go through EVERY SINGLE ORDER IN THE LEDGER and display the correct information on the correct chart. No rocket science, not difficult, but clearly MQL4 find this a terrible hardship.

So, why is it refusing to obtain each positions information and display it on their correct, corresponding chart? 

Why?

Why is it, when I have an open position on the EURUSD and a position on the EURAUD (for instance) do both charts only display the position information on the EURAUD? Thats not what I havd told it do to, hence for fop loop. 

I HAVE TRIED EVERYTING! NOTHING BLODDY WORKS, ITS JUST THE SAME RESULT OVER AND OVER AGAIN.


 
TheFlyingPrussian #:
ObjectSetString ( 0 ,ChartID_CloseButton, OBJPROP_TEXT

Each such call replaces the button text with a new one, rather than adding new text to the current text.

Inside the loop, you set new text to the button multiple times. As a result, the text that you set last is displayed for the button.
 
Amazing, so how would I get it up so that each button reads from the corresponding position? 
 
TheFlyingPrussian #:
Amazing, so how would I get it up so that each button reads from the corresponding position? 

I don't know how many buttons you have, I don't know what you're trying to do. You haven't provided complete code that can be compiled.

Judging by this code, the advisor always changes the text of only one button.
 
Vladislav Boyko #:

I don't know how many buttons you have, I don't know what you're trying to do. You haven't provided complete code that can be compiled.

Judging by this code, the advisor always changes the text of only one button.
That is correct