Forex Forum - EarnForex
Serving Traders Since 2005
 

Go Back   Forex Forum - EarnForex > MetaTrader > MetaTrader Expert Advisors

MetaTrader Expert Advisors Post and discuss the MetaTrader expert advisors here.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 14th June 2011, 09:35
Default Avatar
Junior Member
 
Join Date: Mar 2011
Location: china
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default money management and lotoptimize

I try to use these code to manage my money,but an problem is I don't know how to descirbe my initital money(priniciple) .my method is cotrol lot :use priniciple 's maximumrisk+3 times about of profit(or loss)'s maximunrisk as lot,it profit>0,it will enlarge,otherwise,the vise.
MQL5 Code:
double LotsOptimized()
  {
   double b,lot;//=Lots;
   int    orders=HistoryTotal();    
   int    losses=0,wins=0;  
   int    c,e,f,d;
   b=iATR(NULL,0,60,0);
   c=AccountLeverage();
   
   d=AccountFreeMargin();//I wanna use it describe account's principal,but couldn't how to
   if(orders>=1)
   {e=AccountFreeMargin(); }            
   Print(MarketInfo(Symbol(), MODE_LOTSIZE));
   Print(MarketInfo(Symbol(), MODE_LOTSTEP));
   Print(MarketInfo(Symbol(), MODE_MAXLOT));
   Print("this accountleverage is",c);
   if(d!=0)  
   lot=NormalizeDouble((e*MaximumRisk/2000)*(1+3*(e/d-1)),2);//if profitiable,increase position,otherwise,the vice
   if(lot<0.01) lot=0.01;
   return(lot);
  }
but the first order's position still be 0.01(the mini lot of my MM terminal), these follow will be normal,don't know why. And I know the d==e in my code,so e/d always=1, but I wanna use d stands principal,but how do?TKS!
And have another method of lotoptimize,if solve this,I will list that one here!
Reply With Quote
  #2 (permalink)  
Old 15th June 2011, 08:43
Enivid's Avatar
Administrator
 
Join Date: Nov 2008
Posts: 1,542
Thanks: 18
Thanked 20 Times in 16 Posts
Default

If by principal you mean the initial balance on an account, then you can't code it with some MQL function. You should create an input parameter and the user will have to fill it with the principal value.
__________________
Please, read the Forum Rules and the Signature Rules to avoid termination of your account.
Reply With Quote
  #3 (permalink)  
Old 15th June 2011, 09:05
Default Avatar
Junior Member
 
Join Date: Mar 2011
Location: china
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Enivid View Post
If by principal you mean the initial balance on an account, then you can't code it with some MQL function. You should create an input parameter and the user will have to fill it with the principal value.
yes,I mean the initial balance,but problem now is I don't know how to describe the initial balace(also means:how to get this value?)
Reply With Quote
  #4 (permalink)  
Old 15th June 2011, 17:20
Enivid's Avatar
Administrator
 
Join Date: Nov 2008
Posts: 1,542
Thanks: 18
Thanked 20 Times in 16 Posts
Default

You can't. You can only use some input parameter and set it manually before running your EA.
__________________
Please, read the Forum Rules and the Signature Rules to avoid termination of your account.
Reply With Quote
  #5 (permalink)  
Old 16th June 2011, 09:24
Default Avatar
Junior Member
 
Join Date: Mar 2011
Location: china
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Fixed fractional risk method is my target,but if couldn't get the initial balance value,this is impossible to achieve.Are you sure only" set it manually "this way?
TKS!
Reply With Quote
  #6 (permalink)  
Old 16th June 2011, 19:18
Enivid's Avatar
Administrator
 
Join Date: Nov 2008
Posts: 1,542
Thanks: 18
Thanked 20 Times in 16 Posts
Default

As far as I know, yes. There is no MQL4 variable for initial balance.
But wait. If by initial balance you mean the balance at the start of the EA running (immediately before attaching it to a chart), then it can be done by reading the current account balance only once in the init() function.
__________________
Please, read the Forum Rules and the Signature Rules to avoid termination of your account.
Reply With Quote
  #7 (permalink)  
Old 17th June 2011, 14:55
Default Avatar
Junior Member
 
Join Date: Mar 2011
Location: china
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

TKS! Initial balance I mean is the deposit money of account.Whether array could be used for it or not?e.g. array[0] stands the lastest balance,array[n-1] stands the initial balance, or array[1] stands balance before the lastest trade happend.This is only a hypothesis,actually,I hardly know array clearly.
Any suggestion would be appreciation!

Last edited by univetsity; 18th June 2011 at 04:43. Reason: refresh
Reply With Quote
  #8 (permalink)  
Old 18th June 2011, 07:10
Enivid's Avatar
Administrator
 
Join Date: Nov 2008
Posts: 1,542
Thanks: 18
Thanked 20 Times in 16 Posts
Default

Quote:
Originally Posted by univetsity View Post
TKS! Initial balance I mean is the deposit money of account.Whether array could be used for it or not?e.g. array[0] stands the lastest balance,array[n-1] stands the initial balance, or array[1] stands balance before the lastest trade happend.This is only a hypothesis,actually,I hardly know array clearly.
Any suggestion would be appreciation!
No, there's no such array in MQL.
__________________
Please, read the Forum Rules and the Signature Rules to avoid termination of your account.
Reply With Quote
  #9 (permalink)  
Old 18th June 2011, 07:51
Default Avatar
Junior Member
 
Join Date: Mar 2011
Location: china
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

How to get the balance or accountfreemargin before the lastest trade happend.I wanna compare the lastest accountfreemargin with the previous one's value,that could help me confirm lot.
Reply With Quote
  #10 (permalink)  
Old 18th June 2011, 09:54
Enivid's Avatar
Administrator
 
Join Date: Nov 2008
Posts: 1,542
Thanks: 18
Thanked 20 Times in 16 Posts
Default

If your EA trades with OrderSend() without pending orders, then it can get AccountFreeMargin just before sending its next order.
__________________
Please, read the Forum Rules and the Signature Rules to avoid termination of your account.
Reply With Quote
Reply

Bookmarks

Tags
money;lot;position


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 On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Money Management fdiwata General Forex Discussion 11 20th May 2012 19:09
Stealth Forex Signals and Tom Strignano Money Management Bonus Points ForexTradingChoice Advertisements 0 3rd January 2011 14:27
Money & Risk Management in xls file peterngkl@gmail.com General Forex Discussion 1 26th August 2009 05:55
Money management is crucial in Forex Trading andy003 General Forex Discussion 27 21st July 2009 05:44
Techniques for Global Money management fun_calls Advertisements 0 20th February 2009 16:11


All times are GMT. The time now is 03:11.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Inactive Reminders By Icora Web Design

SEO by vBSEO 3.3.2