View Single Post
 
Old 01-15-2007, 11:26 PM
Nicholishen's Avatar
Nicholishen Nicholishen is offline
Senior Member
 
Join Date: Dec 2005
Posts: 531
Nicholishen is on a distinguished road
Quote:
Originally Posted by ralph.ronnquist
Perhaps it's too unikely to happen, but there is a small worry in picking up AccountBalance() two times, beacuse it is possible that the balance changes in between them. The point is that the balance can be affected by other execution threads than the one processing the EA. The following would be a variation to avoid the worry:

PHP Code:
bool drawdown(double maxdrawdownpercent)
{
   if ( 
AccountEquity AccountBalance * ( maxdrawdownpercent ) )
   {
      return( 
true );
   }
   return( 
false );

Then there is a similar thread race between reading off the balance and reading off the equity, but that race cannot be avoided. At best you could define which order to read them off in, but I'm not sure the one order is any better than the other in respect of possibly return "wrong result".
Nice catch Ralph! I didn't think about the possibilities of that. You are correct in the fact that your method is a "Best Practice".

EDIT::

I had assumed that AccountBalance() was appart of the predefined variables, but apparently it is not. Thanks for the enlightenment!

However one is able to call functions in the manner that I did with out worry because every launch of an attached expert or a custom indicator is assigned its own predefined variables; "is supported that reflect the state of the current price chart at the launching of a program".

So in the instance that script A is running and script B refreshes rates, only the predifined variables are updated in script B, not effecting the status of the predefined variables for script A.
__________________
"Anyone who has never made a mistake has never tried anything new." -Albert Einstein

Last edited by Nicholishen; 01-15-2007 at 11:38 PM.