Cycle Operator 'for' questions - page 8

 
WhooDoo22:

The above snapshot error is the current issue needing to be addressed. What advice do you recommend to solve this issue?

Thank you.

I've covered the reason for that in a previous post  (last post on page 4) . . .  ignoring that I suggest you formulate a loop (for or while,  they are the same) that will loop through ALL open orders and find the correct ones to modify and close . . .  but really what you should do is forget mql4 for  few months and learn the basics first . . .  
 
 

Simon,

What basics in particular would you believe best to study?


Also, I am analyzing this currently:

Now  i  is 2 ,  the OrderSelect() tries to select the Order at position 2 but fails . . .  there are only 2 Orders open, at positions 0 & 1, so the OrderSelect() returns false,  what does the OrderSymbol() do ?  there is no valid Order selected  . . .  but even if it returns true for some weird reason,  the OrderSelect() has already returned false,  false and true = false . . .  the while loop has ended and  i   is set at 2 

Now work through the rest of the code bearing in mind that  i  has a value of 2 . . .


The way in which the post was written was a bit tricky to read yet I found this section above of interest.


If 'i''s current value is now two (2) then the OrderSelect() function holds 2 as the Order position number. Obviously there is no order in order position 2 assuming the order has already been closed so an error "invalid ticket" is produced.

Currently working on this.

I am thinking along the lines of resetting the value 2 currently contained within the OrderSelect() function to zero as well as adding a condition before execution of the lines of code below the 'while' cycle body.

Thank you.

 
WhooDoo22:

Simon,

What basics in particular would you believe best to study?

All of them  . . .  search using Google you will find many resources,  don't just rely on one source for any subject,  ALWAYS find more than one so you can test your understanding . . . you should cover the following at least and much more besides:

  • binary
  • hexadecimal
  • basic boolean algebra 
  • what is an algorithm
  • flowcharts 
  • variables and types of variables
  • conditions
  • loops
  • arrays and sorting arrays
  • basics of handling strings 

 this assumes your Maths skills are good,  if not you need to brush up on your algebra.

 
WhooDoo22:

If 'i''s current value is now two (2) then the OrderSelect() function holds 2 as the Order position number. Obviously there is no order in order position 2 assuming the order has already been closed so an error "invalid ticket" is produced.

Currently working on this.

I am thinking along the lines of resetting the value 2 currently contained within the OrderSelect() function to zero as well as adding a condition before execution of the lines of code below the 'while' cycle body.

Thank you.

Fix the root cause of the issue, don't try and address the symptoms . . . your loop was supposed to find the USDJPY order,  but what is it supposed to do if there isn't one ?  what is it supposed to do if there is more than one ? 

Your code must handle no
t only what you think should happen but also what can happen . . .  
 

Simon,

I will dedicate part of my time to the study of these basics but ;) Volume II MUST be completed. I even came up with more effective usage of moving averages for the MF code blocks. Very proud of myself for considering and developing a more profitable use for these moving averages. Instead of designing my exit/entry signals based on moving averages, I decided to consider these signals to execute within  these moving average periods and use proper moving averages for exits within moving average periods. Basically moving averages within moving averages. Also Volume II will adapt better because it will not always open 0.5 lot orders every time Only when five moving averages are able to be properly fit within two moving averages (a piece of the market). Example: moving average one and moving average two hundred create a section to play within if enough support/resistance is created. It is very pleasing to have thought of this before today. :)

Thank you.

 

Simon,

but what is it supposed to do if there isn't one ?

This is why I wish to add a condition below the 'while' cycle which will be checked before execution of the OrderClose() function is executed.

what is it supposed to do if there is more than one ?

I did not consider this but am considering this now.

Your code must handle not only what you think should happen but also what can happen . . .  

Yes agreed in full.

Thank you.

 
WhooDoo22:

Simon,

I will dedicate part of my time to the study of these basics but ;) Volume II MUST be completed. I even came up with more effective usage of moving averages for the MF code blocks. Very proud of myself for considering and developing a more profitable use for these moving averages. Instead of designing my exit/entry signals based on moving averages, I decided to consider these signals to execute within  these moving average periods and use proper moving averages for exits within moving average periods. Basically moving averages within moving averages. Also Volume II will adapt better because it will not always open 0.5 lot orders every time Only when five moving averages are able to be properly fit within two moving averages (a piece of the market). Example: moving average one and moving average two hundred create a section to play within if enough support/resistance is created. It is very pleasing to have thought of this before today. :)

Thank you.

I don't believe you can complete a working EA without understanding the basics . . .  and you are wasting valuable time trying to do it.  There is only one fastest way to do something,  do it correctly the first time. 
 

Simon,

I don't believe you can complete a working EA without understanding the basics

I do understand some basics but not all. Do you truly believe understanding all coding basics is the only path towards completion of an expert advisor?

Personally, I strongly believe I need only a MetaEditor dictionary in concert with MetaEditor to complete the coding of an expert advisor.

There is only one fastest way to do something,  do it correctly the first time.

Yes, of course. Agreed.

Thank you

 
WhooDoo22:

Simon,

I don't believe you can complete a working EA without understanding the basics

I do understand some basics but not all. Do you truly believe understanding all coding basics is the only path towards completion of an expert advisor?

Personally, I strongly believe I need only a MetaEditor dictionary in concert with MetaEditor to complete the coding of an expert advisor.

I think the code you have produced so far amply proves my point. One can't use OrdersTotal() as part of a loop if one does't know that the first position in the pool is 0, this is but one example,  there are many, many more situations where you must know the basics;  loops,  bitwise operators, etc, etc  
 

Simon,

I did write I would designate part of my time to studying coding basics and this is what I will do. Volume II must be completed. I will begin studying basics witch will strengthen my weaknesses first, then touch-up on more familiar basics to ensure acceptable understanding of a majority of coding basics.

Thank you.