- www.mql5.com
- Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes
- Machine learning in trading: theory, models, practice and algo-trading
- Bar Index Help
If you don't exit the event handler, you will not receive any new events.
Write your code to be event driven (for example, with a state machine) instead of holding up the execution with a loop.
If you don't exit the event handler, you will not receive any new events.
Write your code to be event driven (for example, with a state machine) instead of holding up the execution with a loop.
This is my event driven code with state of true or false. It still would not change state by clicking the button.
void OnInit() { EventSetMillisecondTimer(1); //------------------------------ ObjectCreate(0,"Run",OBJ_BUTTON,0,0,0); ObjectSetInteger(0,"Run",OBJPROP_XDISTANCE,115); ObjectSetInteger(0,"Run",OBJPROP_YDISTANCE,25); ObjectSetInteger(0,"Run",OBJPROP_XSIZE,80); ObjectSetInteger(0,"Run",OBJPROP_YSIZE,25); ObjectSetString(0,"Run",OBJPROP_TEXT,"Click to run"); ObjectSetInteger(0,"Run",OBJPROP_BGCOLOR, clrBlue); ObjectSetInteger(0,"Run",OBJPROP_BORDER_COLOR, clrBlue); ObjectSetInteger(0,"Run",OBJPROP_COLOR, clrWhite); ObjectSetInteger(0,"Run",OBJPROP_BORDER_TYPE,BORDER_FLAT); ObjectSetInteger(0,"Run",OBJPROP_HIDDEN,true); ObjectSetInteger(0,"Run",OBJPROP_STATE,false); ObjectSetInteger(0,"Run",OBJPROP_FONTSIZE,9); } void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { if (sparam == "Run" && id == CHARTEVENT_OBJECT_CLICK) { if (RunButton == true) { RunButton = false; } if (RunButton == false) { RunButton = true; } } } bool RunButton = false; int i = 1000; void OnTimer() { if (RunButton == false) { Print ("Countdown paussed"); } if (RunButton == true) { i = i - 1; Print("Next lower integer is ", i); } } void OnDeinit(const int reason) { EventKillTimer(); }
If you don't exit the event handler, you will not receive any new events.
Write your code to be event driven (for example, with a state machine) instead of holding up the execution with a loop.
I think I got it now. Thank you
void OnInit() { EventSetMillisecondTimer(1); //------------------------------ ObjectCreate(0,"Run",OBJ_BUTTON,0,0,0); ObjectSetInteger(0,"Run",OBJPROP_XDISTANCE,115); ObjectSetInteger(0,"Run",OBJPROP_YDISTANCE,25); ObjectSetInteger(0,"Run",OBJPROP_XSIZE,80); ObjectSetInteger(0,"Run",OBJPROP_YSIZE,25); ObjectSetString(0,"Run",OBJPROP_TEXT,"Click to run"); ObjectSetInteger(0,"Run",OBJPROP_BGCOLOR, clrBlue); ObjectSetInteger(0,"Run",OBJPROP_BORDER_COLOR, clrBlue); ObjectSetInteger(0,"Run",OBJPROP_COLOR, clrWhite); ObjectSetInteger(0,"Run",OBJPROP_BORDER_TYPE,BORDER_FLAT); ObjectSetInteger(0,"Run",OBJPROP_HIDDEN,true); ObjectSetInteger(0,"Run",OBJPROP_STATE,false); ObjectSetInteger(0,"Run",OBJPROP_FONTSIZE,9); } void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { if (sparam == "Run" && id == CHARTEVENT_OBJECT_CLICK) { if (RunButton == true) { RunButton = false; } else if (RunButton == false) { RunButton = true; } } } bool RunButton = false; int i = 1000; void OnTimer() { if (RunButton == false) { Print ("Countdown paussed"); } if (RunButton == true) { i = i - 1; Print("Next lower integer is ", i); } } void OnDeinit(const int reason) { EventKillTimer(); }
| Your Code | if (RunButton == true) { RunButton = false; } else if (RunButton == false) { RunButton = true; } |
| Simplified | RunButton = !RunButton; |
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use