Skip to content

Commit c5a07da

Browse files
author
EarnForex
authored
1.03
1. Added an option to load a text file with a long-term schedule. 2. Added some helpful tooltips to the panel's controls. 3. Added a switch between Enabled schedule and Disabled schedule. 4. Changed how non-enforced schedule works. It will now also attempt to toggle AutoTrading either off or on when the Scheduler is launched inside a period. 5. Fixed an off-screen position of the panel after a chart resizing event. 6. Fixed a crash that could occur if the panel is loaded without enabling DLL imports. 7. Fixed a bug that prevented the schedule from resetting when the ScheduleFile input parameter was cleared or changed.
1 parent 4f04e1a commit c5a07da

File tree

7 files changed

+1117
-579
lines changed

7 files changed

+1117
-579
lines changed

MQL4/Experts/AutoTrading Scheduler/AutoTrading Scheduler.mq4

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#property copyright "EarnForex.com"
22
#property link "https://www.earnforex.com/metatrader-expert-advisors/AutoTrading-Scheduler/"
3-
#property version "1.02"
4-
string Version = "1.02";
3+
#property version "1.03"
4+
string Version = "1.03";
55
#property strict
66

77
#property description "Creates a weekly schedule when AutoTrading is enabled."
@@ -28,6 +28,7 @@ input string DefaultSaturday = ""; // Default enabled Saturday periods
2828
input string DefaultSunday = ""; // Default enabled Sunday periods
2929
input bool DefaultClosePos = false; // Close all positions before turning AutoTrading OFF?
3030
input bool DefaultEnforce = true; // Always enforce schedule?
31+
input ENUM_ALLOWDENY DefaultAllowDeny = ALLOWDENY_ALLOW; // Schedule for allowing or denying AutoTrading?
3132
input string ____Miscellaneous = "================";
3233
input int Slippage = 2; // Slippage
3334
input string ScheduleFile = ""; // ScheduleFile (optional)
@@ -58,13 +59,16 @@ int OnInit()
5859
sets.Sunday = DefaultSunday;
5960
sets.Enforce = DefaultEnforce;
6061
sets.ClosePos = DefaultClosePos;
62+
sets.LastToggleTime = 0;
63+
sets.AllowDeny = DefaultAllowDeny;
64+
sets.LongTermSchedule = "";
6165
}
6266

6367
if (!Panel.Create(0, "AutoTrading Scheduler (ver. " + Version + ")", 0, 20, 20)) return(-1);
6468
Panel.Run();
6569
Panel.IniFileLoad();
6670

67-
if (ScheduleFile != "") Panel.LoadScheduleFile();
71+
if (ScheduleFile != "") Panel.LoadScheduleFile(); // Load schedule from file.
6872

6973
// Brings panel on top of other objects without actual maximization of the panel.
7074
Panel.HideShowMaximize();
@@ -122,6 +126,23 @@ void OnChartEvent(const int id,
122126
// Call Panel's event handler only if it is not a CHARTEVENT_CHART_CHANGE - workaround for minimization bug on chart switch.
123127
if (id != CHARTEVENT_CHART_CHANGE) Panel.OnEvent(id, lparam, dparam, sparam);
124128

129+
// Handle a potential panel-out-of-view situation.
130+
if ((id == CHARTEVENT_CLICK) || (id == CHARTEVENT_CHART_CHANGE))
131+
{
132+
static bool prev_chart_on_top = false;
133+
// If this is an active chart, make sure the panel is visible (not behind the chart's borders). For inactive chart, this will work poorly, because inactive charts get minimized by MetaTrader.
134+
if (ChartGetInteger(ChartID(), CHART_BRING_TO_TOP))
135+
{
136+
if (Panel.Top() < 0) Panel.Move(Panel.Left(), 0);
137+
int chart_height = (int)ChartGetInteger(0, CHART_HEIGHT_IN_PIXELS);
138+
if (Panel.Top() > chart_height) Panel.Move(Panel.Left(), chart_height - Panel.Height());
139+
int chart_width = (int)ChartGetInteger(0, CHART_WIDTH_IN_PIXELS);
140+
if (Panel.Left() > chart_width) Panel.Move(chart_width - Panel.Width(), Panel.Top());
141+
}
142+
// Remember if the chart is on top or is minimized.
143+
prev_chart_on_top = ChartGetInteger(ChartID(), CHART_BRING_TO_TOP);
144+
}
145+
125146
if (Panel.Top() < 0) Panel.Move(Panel.Left(), 0);
126147
}
127148

MQL4/Experts/AutoTrading Scheduler/AutoTrading Scheduler.mqh

Lines changed: 468 additions & 278 deletions
Large diffs are not rendered by default.

MQL4/Experts/AutoTrading Scheduler/Defines.mqh

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <Controls\CheckBox.mqh>
44
#include <Controls\Label.mqh>
55
#include <Controls\RadioGroup.mqh>
6+
#include <Arrays\List.mqh>
67

78
color CONTROLS_EDIT_COLOR_DISABLE = C'221,221,211';
89

@@ -12,13 +13,48 @@ enum ENUM_TIME_TYPE
1213
Server
1314
};
1415

16+
// Used for the schedule's setting - whether it's showing allowed periods or forbidden ones.
17+
enum ENUM_ALLOWDENY
18+
{
19+
ALLOWDENY_ALLOW, // Allow
20+
ALLOWDENY_DENY // Deny
21+
};
22+
1523
enum ENUM_TOGGLE
1624
{
17-
ENUM_TOGGLE_DONT_TOGGLE, // Don't toggle
18-
ENUM_TOGGLE_TOGGLE_ON, // Toggle ON
19-
ENUM_TOGGLE_TOGGLE_OFF // Toggle OFF
25+
TOGGLE_DONT_TOGGLE, // Don't toggle
26+
TOGGLE_TOGGLE_ON, // Toggle ON
27+
TOGGLE_TOGGLE_OFF // Toggle OFF
28+
};
29+
30+
// An object class for storing timestamp + enable/disable state.
31+
class CTimeStamp : public CObject
32+
{
33+
public:
34+
datetime time;
35+
bool enable;
36+
CTimeStamp(datetime t, bool e) {time = t; enable = e;}
37+
virtual int Compare(const CObject *node, const int mode = 0) override const;
2038
};
2139

40+
int CTimeStamp::Compare(const CObject *node, const int mode = 0) override const
41+
{
42+
CTimeStamp *ts = (CTimeStamp*)node; // Cast the generic object pointer to the timestamp object pointer.
43+
44+
if (mode == 0) // Ascending:
45+
{
46+
if (time > ts.time) return 1;
47+
else if (time < ts.time) return -1;
48+
return 0;
49+
}
50+
else // Descending:
51+
{
52+
if (time < ts.time) return 1;
53+
else if (time > ts.time) return -1;
54+
return 0;
55+
}
56+
}
57+
2258
struct Settings
2359
{
2460
ENUM_TIME_TYPE TimeType;
@@ -32,5 +68,8 @@ struct Settings
3268
string Saturday;
3369
string Sunday;
3470
bool Enforce;
71+
datetime LastToggleTime; // For Enforce = false.
72+
ENUM_ALLOWDENY AllowDeny;
73+
string LongTermSchedule;
3574
} sets;
3675
//+------------------------------------------------------------------+

MQL5/Experts/AutoTrading Scheduler/AutoTrading Scheduler.mq5

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#property copyright "EarnForex.com"
22
#property link "https://www.earnforex.com/metatrader-expert-advisors/AutoTrading-Scheduler/"
3-
#property version "1.02"
4-
string Version = "1.02";
3+
#property version "1.03"
4+
string Version = "1.03";
55
#property strict
66

77
#property description "Creates a weekly schedule when AutoTrading is enabled."
@@ -29,6 +29,7 @@ input string DefaultSaturday = ""; // Default enabled Saturday periods
2929
input string DefaultSunday = ""; // Default enabled Sunday periods
3030
input bool DefaultClosePos = false; // Close all positions before turning AutoTrading OFF?
3131
input bool DefaultEnforce = true; // Always enforce schedule?
32+
input ENUM_ALLOWDENY DefaultAllowDeny = ALLOWDENY_ALLOW; // Schedule for allowing or denying AutoTrading?
3233
input group "Miscellaneous"
3334
input int Slippage = 2; // Slippage
3435
input string ScheduleFile = ""; // ScheduleFile (optional)
@@ -59,6 +60,9 @@ int OnInit()
5960
sets.Sunday = DefaultSunday;
6061
sets.Enforce = DefaultEnforce;
6162
sets.ClosePos = DefaultClosePos;
63+
sets.LastToggleTime = 0;
64+
sets.AllowDeny = DefaultAllowDeny;
65+
sets.LongTermSchedule = "";
6266
}
6367

6468
if (!Panel.Create(0, "AutoTrading Scheduler (ver. " + Version + ")", 0, 20, 20)) return(-1);
@@ -123,6 +127,23 @@ void OnChartEvent(const int id,
123127
// Call Panel's event handler only if it is not a CHARTEVENT_CHART_CHANGE - workaround for minimization bug on chart switch.
124128
if (id != CHARTEVENT_CHART_CHANGE) Panel.OnEvent(id, lparam, dparam, sparam);
125129

130+
// Handle a potential panel-out-of-view situation.
131+
if ((id == CHARTEVENT_CLICK) || (id == CHARTEVENT_CHART_CHANGE))
132+
{
133+
static bool prev_chart_on_top = false;
134+
// If this is an active chart, make sure the panel is visible (not behind the chart's borders). For inactive chart, this will work poorly, because inactive charts get minimized by MetaTrader.
135+
if (ChartGetInteger(ChartID(), CHART_BRING_TO_TOP))
136+
{
137+
if (Panel.Top() < 0) Panel.Move(Panel.Left(), 0);
138+
int chart_height = (int)ChartGetInteger(0, CHART_HEIGHT_IN_PIXELS);
139+
if (Panel.Top() > chart_height) Panel.Move(Panel.Left(), chart_height - Panel.Height());
140+
int chart_width = (int)ChartGetInteger(0, CHART_WIDTH_IN_PIXELS);
141+
if (Panel.Left() > chart_width) Panel.Move(chart_width - Panel.Width(), Panel.Top());
142+
}
143+
// Remember if the chart is on top or is minimized.
144+
prev_chart_on_top = ChartGetInteger(ChartID(), CHART_BRING_TO_TOP);
145+
}
146+
126147
if (Panel.Top() < 0) Panel.Move(Panel.Left(), 0);
127148
ChartRedraw();
128149
}

0 commit comments

Comments
 (0)