Account Protector

Hello Enivid. I did many tests simultaneously on demo, maybe this got me confused with some of the results and hence my weird results. I was using some mt4's going long and some going short on BTCUSD because I had no idea which way the market was trending. I just wanted a quick way to see profits and to test the setup.

But definitely the first AP did get triggered consistently when the balance got inflated by 6% (I used 6% instead of 15% so that I could see the results faster for confirmation), but then when the floating profits fell down past the pull back point (I set floating loss 3% of balance), it just went past without triggering once, I reexamined every setting and I did not find the reason. I really want to retry but it's pointless because doing it again and again without modification of the same setup just simply exhausts me.
You are absolutely right! (Sorry for sounding like an LLM!) Because your balance doesn't change throughout that entire process, the second instance will be waiting for the loss to get to $30 (if we take the example with $1,000 starting balance and 3% loss on the second instance). When your profit reaches 6%, the balance doesn't change to $1,060, it stays at $1,000. The solution to this would be a little more complex:

The first instance: Enable GlobalSnapshots in input parameters - this will allow your two APs share their equity snapshots. Add 'Recapture snapshots' action (it will update the equity snapshot when triggered at 6% floating profit. Leave signal action enabled as before.

The second instance: Enable GlobalSnapshots in the input parameters. Change condition from that floating loss one to 'Equity <= % of snapshot' and put 97 in the value. Leave signal condition enabled as before.

When the first instance detects 6% of floating profit, it will not only emit a signal, it will also update the equity snapshot to $1,060 (or whatever value it will be at that moment, but it will be quite close to that). The second instance will then wait for the equity to fall to 97% of that $1,060.

The only issue that I see with this setup is that it may get triggered in reverse on the second instance - if the equity first goes to $970 and then it goes to $1,060, it will get triggered immediately by the signal from the first instance because conditions can be met in any order...
 
Thank you so much Enivid. I will have to take time to digest your post because I did not expect that what I wanted to achieve could have involved so much logic in it. I actually pasted your suggestion into an AI for further explanation. I am not sure if I will ever use it because I am ...... not comfortable. It's ...... just more complicated than what I could handle. I will keep studying it. Let me know if you are curious how AI (Deep Seek)analyzes your suggestion for fun's sake. I still have a copy of it.

On a side note, I find out that many of the buttons and check boxes of AP, become unresponsive or probably inconsistently responsive, when pasted onto the charts for a little while. I wonder if there is a problem with my computer and if anybody else has ever reported this.
 
Let me know if you are curious how AI (Deep Seek)analyzes your suggestion for fun's sake.
Sure! You can send it to me via a direct message.
On a side note, I find out that many of the buttons and check boxes of AP, become unresponsive or probably inconsistently responsive, when pasted onto the charts for a little while. I wonder if there is a problem with my computer and if anybody else has ever reported this.
No, I never encountered anything like that. Please let me know if you find some more or less reliable steps to reproduce the issue. Thank you!
 
Just sent you the direct message.

Regarding those glitches. It's there almost every time like I described. I am not that concerned because I have not got to used it on a live account. I just don't know how I could reproduce it and show it here. I don't want to video record it, at least for the time being. I am still figuring out how to set up that trailing stop thing. But thank you so much again Enivid.
 
Going around in circles trying to simply set a daily loss percentage of balance at 5% loss. Done various testing with greater than / less than and a positive or negative value and not working correctly.

Can someone please advise how to set a daily 5% loss please? (Whislt allowing over 5% profit)
 
Going around in circles trying to simply set a daily loss percentage of balance at 5% loss. Done various testing with greater than / less than and a positive or negative value and not working correctly.

Can someone please advise how to set a daily 5% loss please? (Whislt allowing over 5% profit)
You need to set the 'Daily profit/loss <= % of balance' to -5. Like this:
1764749207452.png
 
Hello,

I have identified an issue with the balance calculation in the Account Protector (I am using the latest version, 1.13).

My current balance is as follows:
1765406571033.png

However, the Account Protector displays the following:
1765406617352.png

I understand that the calculation is based on the previous day’s balance, which is absolutely fine.
The problem is that the Account Protector appears to subtract the Credit from the balance.
The correct previous-day balance should be 18001.69, not 16501.69.

Can you please review and fix this issue?

Thank you.
 
Hello, I'm happy to join the community.

I'm using Account Protector on the latest version of MT4. I only have the "Floating loss rise to currency units" condition active, and the first three actions are active too.

With Account Protector and Auto Trading active, I changed the condition to a higher value. At that moment, the floating was at -90, and the value I entered in the condition was 7,000. As soon as I finished entering the condition value and tab to another field, Account Protector triggered and executed the actions, closing all active operations. That wasn't what I wanted.

What should I do to prevent this from happening?

Thank you in advance.
 
Hello, I'm happy to join the community.

I'm using Account Protector on the latest version of MT4. I only have the "Floating loss rise to currency units" condition active, and the first three actions are active too.

With Account Protector and Auto Trading active, I changed the condition to a higher value. At that moment, the floating was at -90, and the value I entered in the condition was 7,000. As soon as I finished entering the condition value and tab to another field, Account Protector triggered and executed the actions, closing all active operations. That wasn't what I wanted.

What should I do to prevent this from happening?

Thank you in advance.
What was the value before you entered 7,000? What was the output in the Experts tab log?
 
What was the value before you entered 7,000? What was the output in the Experts tab log?
The value before was 4.200. I'm not sure what is the output in the Expert tab log. If you mean the log file, I'm afraid that I don't have it since I had change the VPS where the MT4 was running in that moment.
 
Hello,

I have identified an issue with the balance calculation in the Account Protector (I am using the latest version, 1.13).

My current balance is as follows:
View attachment 35331

However, the Account Protector displays the following:
View attachment 35332

I understand that the calculation is based on the previous day’s balance, which is absolutely fine.
The problem is that the Account Protector appears to subtract the Credit from the balance.
The correct previous-day balance should be 18001.69, not 16501.69.

Can you please review and fix this issue?

Thank you.
That's weird. Currently it calculates that starting balance value this way:
It gets the actual account balance value - in your case that would be 18 423.60 - then it calculates the realized profit/loss profit since the start of the day and subtracts that value from the balance. When calculating the realized profit/loss value, it ignores all deals that aren't either buy or sell deals (so, balance deals for example are ignored). Could you please show how your History tab looks when switched to the Deals view?
 
The value before was 4.200. I'm not sure what is the output in the Expert tab log. If you mean the log file, I'm afraid that I don't have it since I had change the VPS where the MT4 was running in that moment.
The Experts tab log is this:
1765464449087.png

Unfortunately, without the log there isn't much I can do since I cannot reproduce the issue.
 
That's weird. Currently it calculates that starting balance value this way:
It gets the actual account balance value - in your case that would be 18 423.60 - then it calculates the realized profit/loss profit since the start of the day and subtracts that value from the balance. When calculating the realized profit/loss value, it ignores all deals that aren't either buy or sell deals (so, balance deals for example are ignored). Could you please show how your History tab looks when switched to the Deals view?
It is strange because I understand the first part of your message: "It gets the actual account balance value - in your case that would be 18 423.60 - then it calculates the realized profit/loss profit since the start of the day and subtracts that value from the balance"; but definitely there is a problem with the rest as it subtracts the broker Credit.

This is the Account History tab related to the Credit:
1765571787314.png
 
It is strange because I understand the first part of your message: "It gets the actual account balance value - in your case that would be 18 423.60 - then it calculates the realized profit/loss profit since the start of the day and subtracts that value from the balance"; but definitely there is a problem with the rest as it subtracts the broker Credit.

This is the Account History tab related to the Credit:
View attachment 35349
OK. Now I see the problem. Account credit isn't considered a part of the account balance by MQL5 programs, so a call to AccountInfoDouble(ACCOUNT_BALANCE) returns only 16,501.69 in your case.

I think the best solution here would be to add an input parameter in the next version of the Account Protector to either include or not the account credit in balance calculations. If you need a quick fix for the daily % profit/loss condition, you can just change the following line (#1476) in Account Protector.mqh:
MQL5:
DailyStartingBalance = AccountInfoDouble(ACCOUNT_BALANCE) - realized_daily_profit_loss_units;
to this:
MQL5:
DailyStartingBalance = AccountInfoDouble(ACCOUNT_BALANCE) + AccountInfoDouble(ACCOUNT_CREDIT) - realized_daily_profit_loss_units;
Then re-compile Account Protector.mq5. Please note that the change goes to the .mqh file, while it's the .mq5 file that gets compiled.

Please let me know if you have any questions!
 
OK. Now I see the problem. Account credit isn't considered a part of the account balance by MQL5 programs, so a call to AccountInfoDouble(ACCOUNT_BALANCE) returns only 16,501.69 in your case.

I think the best solution here would be to add an input parameter in the next version of the Account Protector to either include or not the account credit in balance calculations. If you need a quick fix for the daily % profit/loss condition, you can just change the following line (#1476) in Account Protector.mqh:
MQL5:
DailyStartingBalance = AccountInfoDouble(ACCOUNT_BALANCE) - realized_daily_profit_loss_units;
to this:
MQL5:
DailyStartingBalance = AccountInfoDouble(ACCOUNT_BALANCE) + AccountInfoDouble(ACCOUNT_CREDIT) - realized_daily_profit_loss_units;
Then re-compile Account Protector.mq5. Please note that the change goes to the .mqh file, while it's the .mq5 file that gets compiled.

Please let me know if you have any questions!
For MT4, I see this (line 1398):
MQL4:
DailyStartingBalance = AccountInfoDouble(ACCOUNT_BALANCE) - realized_daily_profit_loss_units - deposit_withdrawal;

Anyway, I prefer to wait for the new official version of the Account Protector.

Thank you.
 
  • 👍
Reactions: Enivid
I meant can the Switch be toggled to off automatically after a trigger? 🙂
I'll consider adding such a feature in the next version, but normally it's not needed. By default, all actions get disabled after triggering, and if you set DoNotDisableActions to true, then you probably don't want the AP to be turned off either.

What's your use case where you'd need it to be toggled off after triggering?
 
I'm using a grid based ea where I want to close all my trades an hour before a high impact news when the floating pnl turns green. This is currently working well. However after the news, I often turn on the Autotrading button but forgotten to toggle this ea switch to off.

I would like to keep the Actions settings as I would need to reselect 5 options each time.