Forex
Google

Go Back   Forex Trading > Downloads > Indicators - Metatrader 4
Forex Forum Register FAQ Members List Calendar Search Today's Posts Mark Forums Read


Register in Forex TSD!
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time).
Click here to register and get more information

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-15-2007, 05:43 PM
leeb's Avatar
leeb leeb is offline
Senior Member
 
Join Date: Dec 2005
Posts: 341
leeb is on a distinguished road
Coding Help Please - easy stuff

Hi - could anyone tell me if there is code which calculates drawdown which could be put into an EA ? Thanks :-)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-15-2007, 05:52 PM
mqldev's Avatar
mqldev mqldev is offline
Member
 
Join Date: Dec 2006
Posts: 59
mqldev is on a distinguished road
Quote:
Originally Posted by leeb
Hi - could anyone tell me if there is code which calculates drawdown which could be put into an EA ? Thanks :-)
What do you mean by "drawdown"? Do you mean to stop trading when you make % loss?
__________________
Online Expert Advisor Builder
http://www.mqldev.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-15-2007, 05:55 PM
leeb's Avatar
leeb leeb is offline
Senior Member
 
Join Date: Dec 2005
Posts: 341
leeb is on a distinguished road
hi mqlDev - yes that is right I would like expert to take action after % loss of account balance
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-15-2007, 06:55 PM
4xCoder 4xCoder is offline
Member
 
Join Date: Nov 2005
Posts: 49
4xCoder is on a distinguished road
Take a look at AccountEquity() and AccountBalance()
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 01-15-2007, 08:51 PM
Nicholishen's Avatar
Nicholishen Nicholishen is offline
Senior Member
 
Join Date: Dec 2005
Posts: 531
Nicholishen is on a distinguished road
You could try something like this:

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

__________________
"Anyone who has never made a mistake has never tried anything new." -Albert Einstein
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 01-15-2007, 10:03 PM
mqldev's Avatar
mqldev mqldev is offline
Member
 
Join Date: Dec 2006
Posts: 59
mqldev is on a distinguished road
Thumbs up

Quote:
Originally Posted by Nicholishen
You could try something like this:

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

Very good function!
__________________
Online Expert Advisor Builder
http://www.mqldev.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 01-15-2007, 10:53 PM
ralph.ronnquist's Avatar
ralph.ronnquist ralph.ronnquist is offline
Senior Member
 
Join Date: Oct 2006
Posts: 280
ralph.ronnquist is on a distinguished road
dreaded multithreading

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".
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 01-16-2007, 01:24 PM
leeb's Avatar
leeb leeb is offline
Senior Member
 
Join Date: Dec 2005
Posts: 341
leeb is on a distinguished road
Thanks for your input guys
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 09-06-2007, 01:09 PM
Bongo Bongo is offline
Senior Member
 
Join Date: Oct 2005
Posts: 278
Bongo is on a distinguished road
Will these codes work?
-max 5% drawdown.
-stop open new trade.
Thanks B.

extern double maxdrawdownpercent = 0.05;

if ( AccountBalance() - AccountEquity() > AccountBalance() * maxdrawdownpercent )
{
return(0);
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


Similar Threads
Thread Thread Starter Forum Replies Last Post
AMA SLOPE - New Stuff Kalenzo Indicators - Metatrader 4 24 05-25-2008 12:38 AM
Chaikin Volatility - New Stuff :) Kalenzo Indicators - Metatrader 4 8 09-12-2006 04:59 PM


All times are GMT. The time now is 02:50 AM.