- Home
- Comunidad
- Programación
- Strategy testing MQL4 at specific times
Edit Your Comment
Strategy testing MQL4 at specific times
Miembro desde Sep 20, 2022
posts 22
Feb 20, 2023 at 11:02
Miembro desde Sep 20, 2022
posts 22
Can you post your function for checking the time?
Here's an example function that checks if can trade depending on the hours. Do you use days as well or just hours ?
void checkIfCanTrade() {
datetime time_now = TimeCurrent();
datetime startTime = StrToTime(inptV.start_hours);
datetime stopTime = StrToTime(inptV.stop_hours);
if (inptV.useTradingHours)
{
if (time_now >= startTime && time_now <= stopTime)
{
tickV.allowed_to_trade = true;
if (dbg) {
Print("Trading hours allowed");
}
}
else
{
if (dbg) {
Print("Trading hours NOT allowed");
}
tickV.allowed_to_trade = false;
}
}
else
{
tickV.allowed_to_trade = true;
}
}
start_hours and stop hours are declared like strings:
string start_hours = "00:00"; // Start
string stop_hours = "23:59"; // Stop
I hope this helps.
Here's an example function that checks if can trade depending on the hours. Do you use days as well or just hours ?
void checkIfCanTrade() {
datetime time_now = TimeCurrent();
datetime startTime = StrToTime(inptV.start_hours);
datetime stopTime = StrToTime(inptV.stop_hours);
if (inptV.useTradingHours)
{
if (time_now >= startTime && time_now <= stopTime)
{
tickV.allowed_to_trade = true;
if (dbg) {
Print("Trading hours allowed");
}
}
else
{
if (dbg) {
Print("Trading hours NOT allowed");
}
tickV.allowed_to_trade = false;
}
}
else
{
tickV.allowed_to_trade = true;
}
}
start_hours and stop hours are declared like strings:
string start_hours = "00:00"; // Start
string stop_hours = "23:59"; // Stop
I hope this helps.
Empower your trading potential with RoboFxLearning - where knowledge meets success.
*El uso comercial y el spam no serán tolerados y pueden resultar en el cierre de la cuenta.
Consejo: Al publicar una imagen o una URL de YouTube, ésta se integrará automáticamente en su mensaje!
Consejo: Escriba el signo @ para completar automáticamente un nombre de usuario que participa en esta discusión.