Questions from Beginners MQL5 MT5 MetaTrader 5 - page 837

 
Aleksey Vyazmikin:

Are you on the whole story looking for replenishment? About the equity drawdown, that's how it works for me

The man doesn't need to close everything, he doesn't need to look for anything in the history, he wrote:

Forum on trading, automated trading systems and testing trading strategies

Questions from beginners MQL5 MT5 MetaTrader 5

Denis Pershin, 2018.03.22 21:13

I have deposit 500, if balance has increased by 10%, then withdraw this 10%, provided current drawdown is not more than 5%. These inputs are in the function, it does not work to calculate exactly the growth and drawdown.

And following that, as it is clear from the message:

if(_ldd < _dd) TesterWithdrawal(_dep-_bal); // Снимаем: нач.депозит - баланс }

TesterWithdrawal

Документация по MQL5: Общие функции / TesterWithdrawal
Документация по MQL5: Общие функции / TesterWithdrawal
  • www.mql5.com
Общие функции / TesterWithdrawal - справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
Vitaly Muzichenko:

The man doesn't need to close everything, he doesn't need to look up anything in history, he wrote:

Well, as a follow up to how clear the message is:

TesterWithdrawal

I thought the man needs to make a decision on withdrawal on the real, having stopped the trade beforehand...

Well didn't understand what he wanted.

 
Aleksey Vyazmikin:


That's right, I need to keep one amount on the balance during testing, withdraw the increase, the robot is without reinvestment, and trades a grid on a martingale basis, so there are constantly open trades in the market

 
Denis Pershin:

All right, I need to keep one amount on balance during testing, withdraw increment, robot has no reinvestment, and trades a grid on martingale, so there are constantly open trades in the market

Well, in any case, the logic does not change, remember the initial balance and monitor the growth and drawdown, then withdraw... do you need anything on the code?

 
Aleksey Vyazmikin:

If you can help me, please help me with the code:

// dep=нач.депозит, growth=прирост %, _dd=допустимая просадка %
void Withdraw(double _dep=500, double _growth=10, double _dd=5) {
  double _bal=AccountInfoDouble(ACCOUNT_BALANCE);
  double _eq=AccountInfoDouble(ACCOUNT_EQUITY);
  double _ldd="что сюда?";
  
   if(_ldd < _dd) TesterWithdrawal(_bal-dep); // Снимаем: баланс - нач.депозит
 }
 
Denis Pershin:

If you don't mind, help me with the code:

You have to take free margin into account, not equity!

You may have a situation where the drawdown allows you to withdraw a profit from the balance, but there is a large margin involved, and after withdrawal the drawdown will be greater than your 5%.

I cannot help you with formulas in the code right now, maybe someone else will connect and write you a code, it is not long, but you need a little thinking)
 
Denis Pershin:

If you don't mind, help me complete the code:

I don't understand... Do you need a formula to calculate the percentage of funds from the balance?

_ldd=100-_eq/_bal*100;
 
Denis Pershin:

If you don't mind, help me finish the code:

Here you go. The logic is the one I suggested, and if anything is wrong, we'll fix it:

//===============================================================================================
//--------------------------------- Снимает прибыль в тестере ----------------------------------+
//===============================================================================================
void Withdraw(double _dep=500, double _growth=10, double _dd=5) {
 double _now_bal=0,_now_mg=0,_now_pr=0,_surplus=0,_GR=0,_DR=0;
 _now_bal= AccountInfoDouble(ACCOUNT_BALANCE);
 _now_mg = AccountInfoDouble(ACCOUNT_MARGIN_FREE);
 _now_pr = _now_bal-_dep; // Сумма к снятию
 _surplus= _now_mg-_now_pr; // Считаем остаток после снятия
 _GR = (_now_bal-_dep)/_dep*100; // Прирост %
 _DR = (_surplus-_dep)/_dep*100; // Просадка %
 //Comment(DTS(_GR,2)," = ",DTS(_DR,2));
  if(_GR>_growth && _DR<_dd) TesterWithdrawal(_now_pr); // Снимаем
 }
 
Vitaly Muzichenko:


Thank you, just what I needed)
 
Nilog:

There is an indicator file only in ex5.

Can I use the iCustom function to turn it into a multitemporal indicator? So it takes values from ex5 from other periods and draws them on the current chart?

It is possible.

Reason: