Forex



Go Back   Forex Trading > Downloads > Indicators - Metatrader 4
Forex Forum Register More recent Blogs Calendar Advertising Others Help






Register
Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.

From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.

Exclusive Forum
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
  • Elite Section
    Get access to private discussions, specialized support, indicators and trading systems reported every week.
  • Advanced Elite Section
    For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
See more

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 01-15-2007, 06:43 PM
leeb's Avatar
Senior Member
 
Join Date: Dec 2005
Posts: 368
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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #2 (permalink)  
Old 01-15-2007, 06:52 PM
mqldev's Avatar
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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #3 (permalink)  
Old 01-15-2007, 06:55 PM
leeb's Avatar
Senior Member
 
Join Date: Dec 2005
Posts: 368
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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #4 (permalink)  
Old 01-15-2007, 07:55 PM
Member
 
Join Date: Nov 2005
Posts: 56
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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #5 (permalink)  
Old 01-15-2007, 09:51 PM
Nicholishen's Avatar
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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #6 (permalink)  
Old 01-15-2007, 11:03 PM
mqldev's Avatar
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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #7 (permalink)  
Old 01-15-2007, 11:53 PM
ralph.ronnquist's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 297
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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #8 (permalink)  
Old 01-16-2007, 12:26 AM
Nicholishen's Avatar
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-16-2007 at 12:38 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #9 (permalink)  
Old 01-16-2007, 02:24 PM
leeb's Avatar
Senior Member
 
Join Date: Dec 2005
Posts: 368
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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #10 (permalink)  
Old 09-06-2007, 02:09 PM
Bongo's Avatar
Senior Member
 
Join Date: Oct 2005
Posts: 496
Bongo is an unknown quantity at this point
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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
AMA SLOPE - New Stuff Kalenzo Indicators - Metatrader 4 32 11-01-2009 07:13 PM
Chaikin Volatility - New Stuff :) Kalenzo Indicators - Metatrader 4 21 06-03-2009 06:25 PM


All times are GMT. The time now is 09:01 PM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.