Target Revenue in Percentage using Account Balance and Equity - page 2

 
anuj71 #:

This is not what i want. you misunderstood my question.


Regarding the percentage calculation and if condition, it already short out. My current error is while writing the values in the file. So even when it Deinit and OnInit, it will remember it values instead of replacing to new one without fulfilling existing value/Profits.

What do you need the file for? My example determines the fact of achieving a given percentage of profit without using files and global variables

Vladislav Boyko #:
string text = profitPercent < inpTargetPercent ? "Target profit not yet reached" : "Target profit reached";
 
Vladislav Boyko #:
What do you need the file for? My example determines the fact of achieving a given percentage of profit without using files and global variables


This is what i want :

Account Balance = $1000

Target Percentage = 10% (10% of 1000$ = $100)

When Account balance is above $1100, close all the running trade whether it in positive or negative. Than it start again but now the Account balance is $1100 and 10% targeted percentage is $110. and it keep repeating.

---x---


I am not comparing Account Balance and Equity because value change on each Tick. I want, complete the target and close all running trade if any, rewrite the value, repeat again every time. And i have already made the code which working as i want but the only error is if any how my EA got Deinit and when it reinit it value redefined without fulfillment of existing value. 

 
anuj71 #:


This is what i want :

Account Balance = $1000

Target Percentage = 10% (10% of 1000$ = $100)

When Account balance is above $1100, close all the running trade whether it in positive or negative. Than it start again but now the Account balance is $1100 and 10% targeted percentage is $110. and it keep repeating.

---x---


I am not comparing Account Balance and Equity because value change on each Tick. I want, complete the target and close all running trade if any, rewrite the value, repeat again every time. And i have already made the code which working as i want but the only error is if any how my EA got Deinit and when it reinit it value redefined without fulfillment of existing value. 

Forum on trading, automated trading systems and testing trading strategies

Target Revenue in Percentage using Account Balance and Equity

anuj71, 2024.02.29 07:22

To do this, i am trying like :

extern double Target_Percentage = 10;

double target_profits = AccountBalance() * (Target_Percentage * 0.01); //Calculating in Percentage

static double target_Capital = AccountBalance() + target_profits;  //Setting the value in static so it will not change on every tick. 

if(AccountEquity() >= target_Capital) { //Comparing Account Equity with total targeted revenue i need. 

CloseAllTrade(); 
Print("All the trade has been successfully closed as it reached Targeted Capital requirement and targeted capital redjusted automatically to new value based on new capital");
}

#property strict

input double inpTargetPercent = 10.0;

void OnTick()
  {
   double balance = AccountBalance();
   double equity = AccountEquity();
   double profitCurrency = equity - balance; // Can be replaced by the total profit of all orders of this EA
   double profitPercent = profitCurrency / balance * 100.0;
   if(profitPercent >= inpTargetPercent)
      CloseAllTrade();
   //string text = profitPercent < inpTargetPercent ? "Target profit not yet reached" : "Target profit reached";
   //Comment(text + StringFormat(": (%.2f%%/%.2f%%)", profitPercent, inpTargetPercent));
  }

void CloseAllTrade()
  {
  
  }
 
Vladislav Boyko #:
#property strict

input double inpTargetPercent = 10.0;

void OnTick()
  {
   double balance = AccountBalance();
   double equity = AccountEquity();
   double profitCurrency = equity - balance; // Can be replaced by the total profit of all orders of this EA
   double profitPercent = profitCurrency / balance * 100.0;
   if(profitPercent >= inpTargetPercent)
      CloseAllTrade();
   //string text = profitPercent < inpTargetPercent ? "Target profit not yet reached" : "Target profit reached";
   //Comment(text + StringFormat(": (%.2f%%/%.2f%%)", profitPercent, inpTargetPercent));
  }

void CloseAllTrade()
  {
  
  }


I still believe you still did not understood what i am really looking for.


For example,


Account Balance = 1000

Account Equity = 1200

double profitCurrency = equity - balance;

1200 - 1000 = -200


Now, let say some trade got closed in profit. $50. Now account balance is 1050 and equity is $1400


1050 - 1400 = -350


Problem here is, it never meet the condition because the value of profitCurrency is floating because Account Balance and Account equity change on every tick. I request you to please check my this code https://www.mql5.com/en/forum/463287#comment_52562520 , so you can understand what i am really looking for....

 
anuj71 #:

Forum on trading, automated trading systems and testing trading strategies

Target Revenue in Percentage using Account Balance and Equity

Vladislav Boyko, 2024.02.29 18:37

#property strict

input double inpTargetPercent = 10.0;

void OnTick()
  {
   double profitCurrency = equity - balance; // Can be replaced by the total profit of all orders of this EA
  }

Close the order if its profit is 10% of the balance

#property strict

input double inpTargetPercent = 10.0;

void OnTick()
  {
   double balance = AccountBalance();
   double orderProfit = 123.4; // Let's imagine that you selected an order and assigned its profit to this variable
   double profitPercent = orderProfit / balance * 100.0;
   if(profitPercent >= inpTargetPercent)
      CloseAllTrade();
  }

void CloseAllTrade()
  {
   
  }

In case of several orders, use the total profit of several orders, as I wrote above

 
anuj71 #:

Account Balance = 1000

Account Equity = 1200

1200 - 1000 = -200

200, not -200

Reason: