I have created an Expert that works with an indicator, every time the indicator gives us an buy or sell signal my expert opens a position but I want to change it in a way that the expert only opens a position when it is in the specific period of time, for example I want it just to open position when it is 3:00:00 am until 5:00:00 am every day. I have already tried many ways but didn't work. please help.
Asked
Active
Viewed 83 times
1 Answers
0
There must be many solutions for this problem of yours. I solved this problem as follows. You can use this code:
in input section do like this:
input string Start_of_the_desired_time_period = "3:00:00";
input string End_of_the_desired_time_period = "5:00:00";
in start
function write like this:
string current_time= string((string)TimeHour(iTime(Symbol(), Time_Frame, 0)) +
":" + (string)TimeMinute(iTime(Symbol(), Time_Frame, 0)) +
":" + (string)TimeSeconds(iTime(Symbol(), Time_Frame, 0)));
and you must write this code for open order in specified period:
if(StringToTime(current_time) >= StringToTime(Start_of_the_desired_time_period) &&
StringToTime(current_time) <= StringToTime(End_of_the_desired_time_period))
{
Print("do evry thing you want here :) ");
}
The only thing that remains is that every time you want to change the start and end time of the period, you have to remove the expert from the chart and add it to chart again. I did not try to find out what is the cause of this problem. Of course, maybe this problem is just for me. Please test and see if you can change the time frames without removing and then adding the expert to the chart. Thank you for letting me know the result.

Jalal Nouri
- 26
- 5