Trailing Bar Entry EA - page 2

 
WHRoeder 2013.08.17 15:17 #
BenLinus: I replaced all global variables by static variables inside start() and I removed init(). Is this good --or at least better -- practice?

Depends on use and intent. ...

I agree. For example, using static variables in start() rather than global variables also changes the scope of the those variables. See Types of Variables.

 
RaptorUK:

The point is . . . in the event that it does fail how will the code that follows perform ?

would it be a good idea to replace all occurrences of OrderSelect() with this code (or a function that has this code):

        if (!OrderSelect(argTicket,SELECT_BY_TICKET,MODE_TRADES)){    //order is now selected as a side effect

                if(!Closing_Alert_Made){              //This is a global variable in customs.mqh initialized to 0
                        Alert("Ticket was not found.");
                        Closing_Alert_Made = 1;
                }
                else return(0);
        }

Please forgive my ignorance. My background is one c++ course in college.


Thanks for all the comments that I got from everyone. I will think about them.



 
BenLinus:

would it be a good idea to replace all occurrences of OrderSelect() with this code (or a function that has this code):

Please forgive my ignorance. My background is one c++ course in college.

If you are using a bool your code will read clearer if you use true and false . . . you can report the error and exit the function or report the error and continue to the next value in the loop.
 
BenLinus:

would it be a good idea to replace all occurrences of OrderSelect() with this code (or a function that has this code):

Please forgive my ignorance. My background is one c++ course in college.


Thanks for all the comments that I got. I will think about them.




Is it possible to exit start() from within a function? I didn't find the exit() function in the help. How to exit a calling function?

 
BenLinus:


Is it possible to exit start() from within a function? I didn't find the exit() function in the help. How to exit a calling function?

start() is a function just like any other, to exit use return, if you want to return from a function you have called from within start and as a result of the function exit start then . . .

int start()
   {
   
   if(AFunction) return(0);
   
   
   }


bool AFunction()
   {
   
   
   return(true)
   }



 
RaptorUK:

start() is a function just like any other, to exit use return, if you want to return from a function you have called from within start and as a result of the function exit start then . . .




I understand. But, this doesn't exit start from within the function. I guess there is no easy way to accomplish this.
 
BenLinus:

I understand. But, this doesn't exit start from within the function. I guess there is no easy way to accomplish this.
In what way doesn't it achieve what you have described ? the only way of exiting a function before the end of the function is using return, for a return to take effect it has to be called form the function you want to return from.
 
RaptorUK:
In what way doesn't it achieve what you have described ? the only way of exiting a function before the end of the function is using return, for a return to take effect it has to be called form the function you want to return from.

Return() will exit the function from which it is called and "return" some value to the caller -- start() for example. What I asked for is a way to exit the caller from inside a function. In C languages, there is an aptly named exit() function that does the job. It will exit the program all together -- even if it is inside a function other that main().

Btw, I am aware this is a divergence from the initial topic. Apologies for that.

 
BenLinus:

Is it possible to exit start() from within a function? I didn't find the exit() function in the help. How to exit a calling function?

BenLinus:
I understand. But, this doesn't exit start from within the function. I guess there is no easy way to accomplish this.

BenLinus:

Return() will exit the function from which it is called and "return" some value to the caller -- start() for example. What I asked for is a way to exit the called from inside a function. In C languages, there is an aptly named exit() function that does the job. It will exit the program all together -- even if it is inside a function other that main().

The answer to your question is: No. You must pass control back to start() and then decide whether to exit by issuing a "return" from within start(). See RaptorUK's example above.
 
BenLinus:

Return() will exit the function from which it is called and "return" some value to the caller -- start() for example. What I asked for is a way to exit the called from inside a function. In C languages, there is an aptly named exit() function that does the job. It will exit the program all together -- even if it is inside a function other that main().

Btw, I am aware this is a divergence from the initial topic. Apologies for that.

It's not possible in standard mql4 to exit an EA or Indicator totally so there is no need for an equivalent of exit() . . . you could crash with a divide by zero I guess, but why would you want to ?
Reason: