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_inputsinputuint Risk=6; // Размер риска (> 0, но не более 100 %)inputuint 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 |//+------------------------------------------------------------------+voidOnStart()
{
//---Print(DoubleToString(Lot_Size_Depending_On_Risk_And_SL(),2));
}
//+------------------------------------------------------------------+
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?
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.
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.
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 |//+------------------------------------------------------------------+intOnInit()
{
// здесь инициализируем то, что считаем нужнымreturn(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+//| Expert deinitialization function |//+------------------------------------------------------------------+voidOnDeinit(constint reason)
{
// здесь деинициализируем то, что считаем нужным
}
//+------------------------------------------------------------------+//| Expert tick function |//+------------------------------------------------------------------+voidOnTick()
{
//--- абстрактный пример советника
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.
//| Expert initialization function |//+------------------------------------------------------------------+intOnInit()
{
// здесь инициализируем то, что считаем нужнымreturn(INIT_SUCCEEDED);
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
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:
Regards, Vladimir.
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.
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.
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?
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:
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.
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.
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)))))