Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1477

 
MrBrooklin #:

Taking into account the hints from the forum members, for what they are a big THANK YOU, we got this version of the script:

Regards, Vladimir.

I completely missed one very important point in the script. It was necessary to normalise the lot. Here is the corrected version:

//+------------------------------------------------------------------+
//|                            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=NormalizeDouble((AccountInfoDouble(ACCOUNT_MARGIN_FREE)*Risk*0.01)/
                              (Stop_Loss*trading_account_currency),2);
//--- блок проверки размера лота на минимум и максимум от возможного
   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!
After finishing forward testing of therobot, I encountered a persistent problem: when starting a single test with the best set of parameters, the strategy tester starts executing it and seems to execute it to the end (judging by the progress indicator engine), but then hangs. Metatrader has to be restarted and the results of the single test (and the whole forward testing in general) are lost.
Why does the tester hangs and how can it be cured?
Regards, Alexander
 
Experts, please tell me: how to set the platform to reflect the history of trades not on all timeframes, but only on some of them?
And what we have now: click the "show trading history" checkbox and all the history (arrows up and down) on the weekly chart are already a solid fence.
And I would like a setting like other tools (trend lines, arrows, etc.), the display of which can be set not on all timeframes.
 

Good afternoon. Can you tell me where to see the simplest example of an Expert Advisor based on the intersection of two MAs (you can give a lesson).
I know how to add one. I don't want to make a simple copy-paste and lengthen the code, I know there are other methods.
If in MQL4 I didn't have any questions, in MQL5 I can't fully understand how to do it.

 
makssub example of an Expert Advisor based on the intersection of two MAs (you can give a lesson).
I know how to add one. I don't want to make a simple copy-paste and lengthen the code, I know there are other methods.
If in MQL4 I didn't have any questions, in MQL5 I can't fully understand how to do it.

Hello. Open MetaEDitor 5. It has a built-in (standard) Expert Advisor based on the intersection of two MAs. Open the code and study it. Or look for it in CodeBase. Here, for example, is the first EA built on the intersection of two MAs.

Regards, Vladimir.


 
MrBrooklin #:

Hello. Open MetaEDitor 5. It has a built-in (standard) Expert Advisor based on the intersection of two MAs. Open the code and study it. Or search in CodeBase. Here, for example, is the first EA built on the intersection of two MAs.

Regards, Vladimir.


Thanks, I've had a look.

I understand what happens in OnInit.

How to screw it all correctly to OnTick?

 
makssub #:

Thanks, I looked it up.

In OnInit, I understand roughly what is happening.

How do I screw it all into OnTick?

I'm showing only one variant of writing an Expert Advisor, but there can be a huge number of such variants. It all depends on the qualification of the programmer. The structure of an Expert Advisor can look like this:

//+------------------------------------------------------------------+
//|                                                            1.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"
//+------------------------------------------------------------------+
//| Input variables                                                  |
//+------------------------------------------------------------------+

// здесь размещаем входные параметры советника

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   // здесь инициализируем то, что считаем нужным
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   // здесь деинициализируем то, что считаем нужным   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- абстрактный пример советника

   Check_Trading();           // проверим условия разрешающие торговлю
   Signal_Up();               // ищем сигнал для открытия длинной позиции
   Open_Buy_Position();       // открываем длинную позицию
   Close_Buy_Positions();     // закрываем длинную позицию
   
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void Check_Trading()
  {

   // здесь вставляем условия разрешающие торговлю

  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void  Signal_Up(); 
  {

   // здесь вставляем условия, при которых появляется сигнал на покупку

  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void Open_Buy_Position(); 
  {

   // здесь вставляем функцию открытия длинной позиции

  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void Close_Buy_Positions();
  {

   // здесь вставляем функцию закрытия длинной позиции

  }
//+------------------------------------------------------------------+

Something like this. Once again I emphasise - this is not a guide to writing Expert Advisors, but an approximate structure that I adhere to when writing my Expert Advisors.

Regards, Vladimir.

 
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   // здесь инициализируем то, что считаем нужным
   return(INIT_SUCCEEDED);

I don't know how to write it

 
Лауреат #:

I don't know how to write it

What exactly is not clear to you? How to create an EA initialisation function? Then try to study this article for beginners.

Regards, Vladimir.

 
MrBrooklin #:

What exactly do you not understand? How to create an EA initialisation function? Then try to study this article for beginners.

Regards, Vladimir.

and what does it mean to initialise))))) it is not clear to a person)))))

Reason: