Take Profit by Using Target Balance

To add comments, please log in or register
yohtrianto
11
yohtrianto  
Hi everyone, this is my first thread.

I have an idea of Closing all Open Orders when my Account Equity reach (>=) the Target Balance. 
For example:
My Initial Balance = 1000
My target balance is 105% of initial balance
So when the first order opened and my balance at 1050 (1000*1.05) or bigger... -> Close all open orders.
Then my second order opened, and when my balance reach 1102.5 (1050*1.05) -> Close all open orders.
And this is keep going until I reached my Monthly Goal Balance.


Do you know how to make the EA ???

Because I tried it but it didn't work. Only if I changed my target to a constant number (ex 10) then it worked but not as I hoped for.
Example:
Initial balance = 1000
First order opened and my balance reached 1010 (1000+10) -> Close all open order
Sencond order opened and my balance reached 1020 (1010+10) -> Close all open order
...


Marco vd Heijden
Moderator
9535
Marco vd Heijden  

For you to use balance like that the orders have to be already closed so you have to use a different function.

Please see these:

For the function AccountInfoDouble()

ENUM_ACCOUNT_INFO_DOUBLE

Identifier

Description

Type

ACCOUNT_BALANCE

Account balance in the deposit currency

double

ACCOUNT_CREDIT

Account credit in the deposit currency

double

ACCOUNT_PROFIT

Current profit of an account in the deposit currency

double

ACCOUNT_EQUITY

Account equity in the deposit currency

double

ACCOUNT_MARGIN

Account margin used in the deposit currency

double

ACCOUNT_MARGIN_FREE

Free margin of an account in the deposit currency

double

ACCOUNT_MARGIN_LEVEL

Account margin level in percents

double

ACCOUNT_MARGIN_SO_CALL

Margin call level. Depending on the set ACCOUNT_MARGIN_SO_MODE is expressed in percents or in the deposit currency

double

ACCOUNT_MARGIN_SO_SO

Margin stop out level. Depending on the set ACCOUNT_MARGIN_SO_MODE is expressed in percents or in the deposit currency

double

ACCOUNT_MARGIN_INITIAL

Initial margin. The amount reserved on an account to cover the margin of all pending orders

double

ACCOUNT_MARGIN_MAINTENANCE

Maintenance margin. The minimum equity reserved on an account to cover the minimum amount of all open positions

double

ACCOUNT_ASSETS

The current assets of an account

double

ACCOUNT_LIABILITIES

The current liabilities on an account

double

ACCOUNT_COMMISSION_BLOCKED

The current blocked commission amount on an account

double

Code2219 or probably 2319
477
Code2219 or probably 2319  

record the account balance on EA start.
each time your equity reaches your 5% gain (your smaller goal), close all positions, then set the current account balance as a new starting point.

double STARTING_BALANCE;    // a global variable of course

OnInit() :

STARTING_BALANCE = AccountInfoDouble.....(ACCOUNT_BALANCE....)  



Ontick() :

if there's open positions right now....         // check by PositionsTotal()...
current_EQUITY  = AccountInfoDouble....(ACCOUNT_EQUITY....)             // current floating equity
if(current_EQUITY >= STARTING_BALANCE * 105 * 0.01)
{
        // here close all open positions....
        STARTING_BALANCE = current_EQUITY;
}

azmirhajali89
5
azmirhajali89  
can someone make a code to view data like this?? put in EA...111
Siti Latifah
15832
Siti Latifah  
Code2219 or probably 2319:

record the account balance on EA start.
each time your equity reaches your 5% gain (your smaller goal), close all positions, then set the current account balance as a new starting point.

yes .. agree with you

William Roeder
18315
William Roeder  
azmirhajali89: can someone make a code to view data like this?? put in EA...
You have only four choices:
  1. Search for it,
  2. Beg at
  3. learn to code it. If you don't learn MQL4/5, there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into yours.
  4. or pay (Freelance) someone to code it.
We're not going to code it for you (although it could happen if you are lucky or the problem is interesting.) We are willing to help you when you post your attempt (using CODE button) and state the nature of your problem.
          No free help
          urgent help.
To add comments, please log in or register