ALI AMRIOUI:
i wana open trade for exemple at 11:00:00 and 12:00:00 and 13:00:00
can some slove my expert plz
did some one have idea plz ??
im becoms realy crazy with this code
You need a state machine.
Multiple conditions for taking a trade. - Expert Advisors and Automated Trading - MQL5 programming forum (2023)
- On a new day, reset to waiting for time 11.
- Wait for time to arrive or pass. Open. Set to waiting for 12.
- Wait for time to arrive or pass. Open. Set to waiting for 13.
- Wait for time to arrive or pass. Open. Set to waiting forever.
William Roeder #:
You need a state machine.
Multiple conditions for taking a trade. - Expert Advisors and Automated Trading - MQL5 programming forum (2023)
- On a new day, reset to waiting for time 11.
- Wait for time to arrive or pass. Open. Set to waiting for 12.
- Wait for time to arrive or pass. Open. Set to waiting for 13.
- Wait for time to arrive or pass. Open. Set to waiting forever.
//--- input parameters input string TimeToOpen1="11:00:00"; input string TimeToOpen2="12:00:00"; input string TimeToOpen3="13:00:00"; input TRADE_TYPE TradeType = BUY; input double Lots=0.01; input int StopLoss=40; input int TakeProfit=40; MqlDateTime time_to_open1 , time_to_open2 ; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- TimeToStruct( StringToTime( TimeToOpen1), time_to_open1 ) ; TimeToStruct( StringToTime( TimeToOpen2),time_to_open2) ; //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- MqlDateTime time1,time2; TimeCurrent(time2); TimeCurrent(time1); time1.hour = time_to_open1.hour; time1.min = time_to_open1.min; time1.sec = time_to_open1.sec; time2.hour = time_to_open2.hour; time2.min = time_to_open2.min; time2.sec = time_to_open2.sec; datetime time_current1 = TimeCurrent(); datetime time_current2 = TimeCurrent(); datetime time_trade1 = StructToTime(time1); datetime time_trade2 = StructToTime(time2); if( (time_current1 >= time_trade1 && time_current1 < time_trade1+(12*PeriodSeconds(PERIOD_M1)) && CanTrade()) || (time_current2 >= time_trade2 && time_current2 < time_trade1+(12*PeriodSeconds(PERIOD_M1)) && CanTrade()) ) if(!OpenTrade()) Print(__FUNCTION__," <!!!> ",ErrorDescription(GetLastError())); } //+------------------------------------------------------------------+
like that for expemle also dont work

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
i wana open trade for exemple at 11:00:00 and 12:00:00 and 13:00:00
can some slove my expert plz