Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1476

 
Artyom Trishkin #:

Explosive.

Fair enough.

 
Aleksandr Slavskii #:

fxsaber if you are reading, please reply.

PositionID is stored in tst-file. Maybe it makes sense to convert tst->Virtual, then you can work with tst in MT4-style. Here is an example of such conversion.

You can also extract backtest history from objects. The library is easier to understand there.

ZЫ I am not subscribed to this thread, so I may not see it.

TesterReport - альтернативный отчет тестера стратегий Metatrader 5
TesterReport - альтернативный отчет тестера стратегий Metatrader 5
  • 2021.10.06
  • www.mql5.com
Торговые отчеты MetaTrader 5 довольно тяжелы для восприятия. По этой причине с определенного момента разработчики добавили в Терминал более понятный режим просмотра закрытых позиций. Однако, это не
 
Alexey Viktorov #:

Be sure to consider the cost per tick.

Good morning and good mood, everyone!

I have no time to write code. Taking into account the hints from forum members, for which they are a big THANK YOU, we have got this version of the script:

//+------------------------------------------------------------------+
//|                            Lot_Size_Depending_On_Risk_And_SL.mq5 |
//|                                  Copyright 2023, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property script_show_inputs
input uint Risk=6;         // Размер риска (> 0, но не более 100 %)
input uint Stop_Loss=1000; // Размер стоп-лосса (> 0, но не более 4294967295)
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double Lot_Size_Depending_On_Risk_And_SL()
  {
//--- блок проверки входных параметров на корректность
   if(Risk==0 || Risk>100 || Stop_Loss==0)
     {
      Print("<===== Введены не корректные размеры риска и/или стоп-лосса! =====>");
      return(0.0);
     }
//--- блок определения размера лота
   double trading_account_currency=SymbolInfoDouble(_Symbol,SYMBOL_POINT)*
                                   SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_VALUE)/
                                   SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_SIZE);
   double lot=(AccountInfoDouble(ACCOUNT_MARGIN_FREE)*Risk*0.01)/(Stop_Loss*trading_account_currency);
//--- блок проверки размера лота на минимум и максимум от возможного
   double min_volume=SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN);
   double max_volume=SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MAX);
   if(lot<min_volume)
      lot=min_volume;
   if(lot>max_volume)
      lot=max_volume;
//--- блок расчёта минимального шага изменения объёма необходимого для заключения сделки
   double step_volume=SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_STEP);
   int ratio=(int)MathRound(lot/step_volume);
   if(MathAbs(ratio*step_volume-lot)>0.0000001)
      lot=ratio*step_volume;
   return(lot);
  }
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   Print(DoubleToString(Lot_Size_Depending_On_Risk_And_SL(),2));
  }
//+------------------------------------------------------------------+

Regards, Vladimir.

 

Good afternoon!

Could you please suggest how to refine my robot so that it can only function on one computer?

(to protect it from copying)

Regards, Alexander

Документация по MQL5: Операции с массивами / ArraySetAsSeries
Документация по MQL5: Операции с массивами / ArraySetAsSeries
  • www.mql5.com
ArraySetAsSeries - Операции с массивами - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
klycko #:

Good afternoon!

Could you please advise how to refine my robot so that it can only function on one computer?

(to protect it from being copied)

Regards, Alexander

void OnInit()
  {
   if(AccountInfoInteger(ACCOUNT_LOGIN) != Номер счёта)
      return INIT_FAILED;
   return INIT_SUCCEEDED;
  }

The simplest variant.

Insert two lines of code into the OnInit function.

Instead of the account number, specify the account of the person to whom you give the Expert Advisor, compile and give only the ex5 file.

 
Aleksandr Slavskii #:

The easiest option.

Insert two lines of code into the OnInit function.

Instead of account number, specify the account of the person to whom you are giving the Expert Advisor, compile and give only the ex5 file.

Thank you very much!

 
Aleksandr Slavskii #:

The easiest option.

Insert two lines of code into the OnInit function.

Instead of account number, specify the account of the person to whom you are giving the Expert Advisor, compile and give only the ex5 file.

the client switches on the terminal and the Expert Advisor crashes :-))

because there are situations when ACCOUNT_LOGIN=0

 
Maxim Kuznetsov #:

the client switches on the terminal and the Expert Advisor crashes :-)

because there are situations when ACCOUNT_LOGIN=0

If you need reliable and high quality, it's for freelancing.

 

Strange. I set 5000 bars maximum in the terminal in "Settings -> Charts". I reloaded the terminal, when hovering over the tab with the symbol, it shows that 5000 bars.

But this code:

int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[],
                const double &open[], const double &high[], const double &low[], const double &close[],
                const long &tick_volume[], const long &volume[], const int &spread[])
{

  Print("rates_total=", rates_total);
  return rates_total;
}


displays information about 6201 bars.

Is this correct? I expected also in rates_total to be 5000.

 
Vasiliy Pushkaryov #:

displays 6201 bar information

What does it say on that?

printf((string)TerminalInfoInteger(TERMINAL_MAXBARS));
Most likely the story is more for the tester, so that the indicators are calculated correctly in it
Reason: