Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1440

 
Alexey Viktorov #:

That's what many people start learning a programming language for. And so it turns out that in order for you to be able to test your illusory idea, someone will sit down to write. Of course, you can find such an enthusiast who can write for the sake of practice writing, out of boredom or for some other reason... But if you agree and get a strategy through LS, realising that it will not work refuse to write, then you will have a suspicion that you have been cheated, have a profitable strategy and into the bushes. And who needs such an attitude? If you publish a strategy and someone is interested, you will be lucky. And so, for your money any whim....

You are an interesting person.

So you have enough enthusiasm for such an indicator) https://c.mql5.com/1/237/vgif-ru-19978.gif.

And you don't want to insert two lines of code into RSI for the sake of writing practice, out of boredom or for some other reasons...

 
FYFRX #:

You're an interesting man.

So you have enough enthusiasm for such an indicator) https://c.mql5.com/1/237/vgif-ru-19978.gif

And you don't want to insert two lines of code into RSI for the sake of writing practice, out of boredom or for some other reasons...

Well, if you know that it is two lines, you should know what lines they are and where to insert them.

 

Good morning and good mood everyone!

Yesterday there was a confusion with my Expert Advisor. Until yesterday it had been testing for almost a month without any problems, but closer to the evening suddenly the calculation of risk depending on free margin stopped working properly and the EA started opening positions with the maximum possible lot. I decided to write a check function to allow trading under certain conditions to exclude such "gifts". I wrote it and added it to the EA code. I don't know whether this function helped or something else happened while writing it, but the work of the Expert Advisor has normalised.

Request to the respected community!

Please look at the code and advise what else should be added to the function to exclude such "gifts" for trading on a real account?

bool Check_Trading()
  {
   bool canTrade=false;
   if(!AccountInfoInteger(ACCOUNT_TRADE_ALLOWED))
     {
      Print("Ошибка разрешения торговли для текущего счёта!", GetLastError());
      canTrade=false;
     }
   if(!AccountInfoInteger(ACCOUNT_TRADE_EXPERT))
     {
      Print("Ошибка разрешения торговли для эксперта!", GetLastError());
      canTrade=false;
     }
   if(!AccountInfoInteger(ACCOUNT_MARGIN_MODE)==ACCOUNT_MARGIN_MODE_RETAIL_HEDGING)
     {
      Print("Ошибка при проверке режима расчёта маржи для счёта с режимом хэдж!", GetLastError());
      canTrade=false;
     }
   if(!AccountInfoDouble(ACCOUNT_MARGIN_FREE))
     {
      Print("Ошибка при получении размера свободных средств для открытия позиции!", GetLastError());
      canTrade=false;
     }
   if(!SymbolInfoInteger(_Symbol,SYMBOL_TRADE_CALC_MODE)==SYMBOL_CALC_MODE_FOREX)
     {
      Print("Ошибка способа расчета прибыли и маржи для рынка Форекс по текущему символу!", GetLastError());
      canTrade=false;
     }
   if(!SymbolInfoDouble(_Symbol,SYMBOL_MARGIN_HEDGED))
     {
      Print("Ошибка расчета маржи для позиций по текущему символу для счёта с режимом хэдж!", GetLastError());
      canTrade=false;
     }
   if(!SymbolIsSynchronized(_Symbol))
     {
      Print("Ошибка синхронизации данных по текущему символу!", GetLastError());
      canTrade=false;
     }
   canTrade=true;
   return(canTrade);
  }

Regards, Vladimir.

 

I can't understand how and what it needs, it takes and reads a file from Tester\Agent... folder in TERMINAL_DATA_PATH, but I need to read it in TERMINAL_PATH and I can't use absolute path.


 
mwwm #:

I can't understand how and what it needs, it takes and reads a file from Tester\Agent... folder in TERMINAL_DATA_PATH, but I need to read it in TERMINAL_PATH and I can't use absolute path.

If you need to work with files during testing, it is more convenient to use a common folder of all terminals and agents for this purpose. To do this, it is enough to add the FILE_COMMON flag to file opening operations.

You can get to this folder to put the necessary files in it from the MetaEditor main menu: FileOpen common data folder

 
Yuriy Bykov #:

If it is necessary to work with files during testing, it is more convenient to use a common folder of all terminals and agents for this purpose. For this purpose it is enough to add FILE_COMMON flag in file opening operations.

You can get to this folder to put the necessary files in it from the MetaEditor main menu: FileOpen common data folder

Thank you!)

 
FYFRX #:

You're an interesting man.

So you have enough enthusiasm for such an indicator) https://c.mql5.com/1/237/vgif-ru-19978.gif

And you don't want to insert two lines of code into RSI for the sake of writing practice, out of boredom or for some other reasons...

This is not my creation. Do you remember the Monna Lisa in the film "Office Romance"?

As for the two lines, I've explained it to you.

Forum on trading, automated trading systems and testing trading strategies.

Questions from MQL5 MT5 MetaTrader 5 beginners

Alexey Viktorov, 2023.01.30 07:17 AM

This is the reason why many people start learning a programming language. And so it turns out that so you can test your illusory idea someone will sit down to write. Of course you can find such an enthusiast who can write for the sake of practice writing, out of boredom or for some other reason ... But if you agree and get through LS strategy, realising that it will not work to refuse to write, then you will have a suspicion that you were cheated, have a profitable strategy and into the bushes. And who needs such an attitude? If you publish a strategy and someone is interested, you will be lucky. But for your money, any whim...

Write these desires in any topic about free code writing and someone will surely respond. Probably me too. though unlikely, I won't be here for 2-3 days...
 
MrBrooklin allow trading under certain conditions to exclude such "gifts". I wrote it and added it to the EA code. I don't know whether this function helped or something else happened while I was writing it, but the work of the Expert Advisor was normalised.

Request to the respected community!

Please look at the code and advise what else should be added to the function to exclude such "gifts" for trading on a real account?

Regards, Vladimir.

Vladimir, how did you

   if(!AccountInfoDouble(ACCOUNT_MARGIN_FREE))

converted into bool type

ACCOUNT_MARGIN_FREE

The amount of free funds on the account in the deposit currency available for opening a position.

double


This is what my eye stumbled on. I don't even want to look at the rest...

 
Alexey Viktorov #:

Vladimir, how did you convert this to a bool type

ACCOUNT_MARGIN_FREE

Amount of free funds on the account in the deposit currency available for opening a position

double


This is what I stumbled on. I don't even want to look at the rest....

Hi Alexey, I was thinking like this - if free funds on the account in the deposit currency available for opening a position are enough, then it is true. Now I realise that this value is for calculations only. Thank you for the hint.

Regards, Vladimir.

 

Good morning and good mood!

Taking into account constructive criticism, I have changed the code of the check function:

bool Check_Trading()
  {
//--- проверка разрешения автоматической торговли на терминале
   if(!AccountInfoInteger(ACCOUNT_TRADE_ALLOWED))
     {
      Print("Ошибка разрешения автоматической торговли на терминале! ",GetLastError());
      return(false);
     }
//--- проверка разрешения автоматической торговли на стороне сервера
   if(!AccountInfoInteger(ACCOUNT_TRADE_EXPERT))
     {
      Print("Ошибка разрешения автоматической торговли на стороне сервера! ",GetLastError());
      return(false);
     }
//--- проверка синхронизированности данных по текущему символу между терминалом и сервером
   if(!SymbolIsSynchronized(_Symbol))
     {
      Print("Ошибка синхронизированности данных по текущему символу! ",GetLastError());
      return(false);
     }
//--- проверка достаточности средств для торговли
   if(!CheckMoneyForTrade(_Symbol,GetLot(),ORDER_TYPE_SELL))
     {
      Print("Ошибка проверки достаточности средств для торговли! ",GetLastError());
      return(false);
     }
//--- проверки корректности объёма сделки
   string descript;
   if(!CheckVolumeValue(GetLot(),descript))
     {
      Print("Ошибка проверки корректности объёма сделки! ",GetLastError());
      return(false);
     }
//--- проверка прошла успешно
   return(true);
  }

CheckMoneyForTrade() and CheckVolumeValue() functions are not posted, as they are freely available and taken from here.

Will this minimum be enough to prevent the problem with the Expert Advisor that I had the day before yesterday?

Regards, Vladimir.

Reason: