Skip to content

Commit 615929b

Browse files
author
EarnForex
authored
3.07
1. Added an optional additional label for the Entry line to display the total position volume calculated by the Position Sizer. 2. Added new hotkeys (Shift+S and Shift+P by default) to switch stop-loss and take-profit values from level to points and vice versa. 3. Added risk-to-reward ratio calculations to the Risk tab. 4. Added the expiration time field and parameter to allow setting a time limit for pending orders. 5. Added a new hotkey ('`' by default) to minimize/maximize the panel. 6. Fixed TP button colors in the dark mode. 7. Fixed hotkeys to not trigger when they are set to work without Shift/Ctrl, but either Shift or Ctrl are pressed. 8. Fixed the margin calculation in the MT5 version to take into account the maintenance margin when required. 9. Fixed a bug when changing the hotkey input parameters for an already attached Position Sizer could fail to work. 10. Fixed a potential array out-of-range error that could appear under certain rare circumstances. 11. Fixed additional TP fields scaling on the panel for HiDPI screens. 12. Changed the take-profit hotkey to switch off the TP-lock-on-SL when triggered. 13. Changed where the panel setting files are stored. They are now saved and loaded from the PS_Settings subfolder of MetaTrader's Files folder. Older settings files will be loaded correctly if they are found in the previous location. 14. Changed default colors for TP and SL lines to goldenrod and green respectively.
1 parent 53bf639 commit 615929b

File tree

11 files changed

+825
-315
lines changed

11 files changed

+825
-315
lines changed

MQL4/Experts/Position Sizer/Defines.mqh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ color DARKMODE_EDIT_BG_COLOR = 0xAAAAAA;
2323
color DARKMODE_BUTTON_BG_COLOR = 0xA19999;
2424
color DARKMODE_TEXT_COLOR = 0x000000;;
2525

26+
color CONTROLS_BUTTON_COLOR_TP_UNLOCKED, CONTROLS_BUTTON_COLOR_TP_LOCKED;
27+
2628
enum ENTRY_TYPE
2729
{
2830
Instant,
@@ -132,6 +134,8 @@ struct Settings
132134
int MaxEntrySLDistance;
133135
int MinEntrySLDistance;
134136
// For SL/TP distance modes:
137+
bool SLDistanceInPoints;
138+
bool TPDistanceInPoints;
135139
int StopLoss;
136140
int TakeProfit;
137141
// Only for SL distance mode:
@@ -151,6 +155,7 @@ struct Settings
151155
double MaxPositionSizePerSymbol;
152156
double MaxRiskTotal;
153157
double MaxRiskPerSymbol;
158+
int ExpiryMinutes;
154159
// For ATR:
155160
int ATRPeriod;
156161
double ATRMultiplierSL;

MQL4/Experts/Position Sizer/Position Sizer Trading.mqh

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,12 @@ void Trade()
240240
}
241241
}
242242

243+
datetime expiry = 0;
244+
if ((sets.EntryType == Pending) && (sets.ExpiryMinutes > 0))
245+
{
246+
expiry = TimeCurrent() + sets.ExpiryMinutes * 60;
247+
}
248+
243249
if (sets.AskForConfirmation)
244250
{
245251
// Evoke confirmation modal window.
@@ -281,9 +287,13 @@ void Trade()
281287
if (PositionMargin != 0) message += "Margin: " + FormatDouble(DoubleToString(PositionMargin, 2)) + " " + account_currency + "\n";
282288
message += "Entry: " + DoubleToString(sets.EntryLevel, _Digits) + "\n";
283289
if (!sets.DoNotApplyStopLoss) message += "Stop-loss: " + DoubleToString(sets.StopLossLevel, _Digits) + "\n";
284-
if ((sets.TakeProfitLevel > 0) && (!sets.DoNotApplyTakeProfit)) message += "Take-profit: " + DoubleToString(sets.TakeProfitLevel, _Digits);
285-
if (sets.TakeProfitsNumber > 1) message += " (multiple)";
286-
message += "\n";
290+
if ((sets.TakeProfitLevel > 0) && (!sets.DoNotApplyTakeProfit))
291+
{
292+
message += "Take-profit: " + DoubleToString(sets.TakeProfitLevel, _Digits);
293+
if (sets.TakeProfitsNumber > 1) message += " (multiple)";
294+
message += "\n";
295+
}
296+
if (expiry > 0) message += "Expiry: " + TimeToString(expiry, TIME_DATE|TIME_MINUTES|TIME_SECONDS);
287297

288298
int ret = MessageBox(message, caption, MB_OKCANCEL | MB_ICONWARNING);
289299
if (ret == IDCANCEL)
@@ -363,7 +373,7 @@ void Trade()
363373
sub_position_size = position_size;
364374
position_size = 0; // End the cycle;
365375
}
366-
int ticket = OrderSend(Symbol(), ot, sub_position_size, sets.EntryLevel, sets.MaxSlippage, order_sl, order_tp, Commentary, sets.MagicNumber);
376+
int ticket = OrderSend(Symbol(), ot, sub_position_size, sets.EntryLevel, sets.MaxSlippage, order_sl, order_tp, Commentary, sets.MagicNumber, expiry);
367377
if (ticket == -1)
368378
{
369379
int error = GetLastError();

MQL4/Experts/Position Sizer/Position Sizer.mq4

Lines changed: 153 additions & 88 deletions
Large diffs are not rendered by default.

MQL4/Experts/Position Sizer/Position Sizer.mqh

Lines changed: 213 additions & 57 deletions
Large diffs are not rendered by default.

MQL5/Experts/Position Sizer/Defines.mqh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ color DARKMODE_MAIN_AREA_BORDER_COLOR = 0x333333;
2121
color DARKMODE_MAIN_AREA_BG_COLOR = 0x666666;
2222
color DARKMODE_EDIT_BG_COLOR = 0xAAAAAA;
2323
color DARKMODE_BUTTON_BG_COLOR = 0xA19999;
24-
color DARKMODE_TEXT_COLOR = 0x000000;;
24+
color DARKMODE_TEXT_COLOR = 0x000000;
25+
26+
color CONTROLS_BUTTON_COLOR_TP_UNLOCKED, CONTROLS_BUTTON_COLOR_TP_LOCKED;
2527

2628
enum ENTRY_TYPE
2729
{
@@ -134,6 +136,8 @@ struct Settings
134136
int MaxEntrySLDistance;
135137
int MinEntrySLDistance;
136138
// For SL/TP distance modes:
139+
bool SLDistanceInPoints;
140+
bool TPDistanceInPoints;
137141
int StopLoss;
138142
int TakeProfit;
139143
// Only for SL distance mode:
@@ -155,6 +159,7 @@ struct Settings
155159
double MaxPositionSizePerSymbol;
156160
double MaxRiskTotal;
157161
double MaxRiskPerSymbol;
162+
int ExpiryMinutes;
158163
// For ATR:
159164
int ATRPeriod;
160165
double ATRMultiplierSL;
1.05 KB
Binary file not shown.

MQL5/Experts/Position Sizer/Position Sizer.mq5

Lines changed: 155 additions & 90 deletions
Large diffs are not rendered by default.

MQL5/Experts/Position Sizer/Position Sizer.mqh

Lines changed: 251 additions & 70 deletions
Large diffs are not rendered by default.

MQL5/Experts/Position Sizer/Translations/English.mqh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@
111111
#define TRANSLATION_TOOLTIP_CURRENT_PORTFOLIO "Trades that are currently open"
112112
#define TRANSLATION_LABEL_POTENTIAL_PORTFOLIO "Potential portfolio"
113113
#define TRANSLATION_TOOLTIP_POTENTIAL_PORTFOLIO "Including the position being calculated"
114-
114+
#define TRANSLATION_LABEL_CRRR_TOOLTIP "Risk-to-reward ratio of the current portfolio"
115+
#define TRANSLATION_LABEL_PRRR_TOOLTIP "Risk-to-reward ratio of the potential portfolio"
115116

116117
// Margin tab
117118
#define TRANSLATION_LABEL_POSITION_MARGIN "Position margin"
@@ -181,14 +182,18 @@
181182
#define TRANSLATION_TOOLTIP_DO_NOT_APPLY_TAKEPROFIT "The EA won't apply take-profit to the trade it opens."
182183
#define TRANSLATION_CHECKBOX_ASK_FOR_CONFIRMATION "Ask for confirmation"
183184
#define TRANSLATION_TOOLTIP_ASK_FOR_CONFIRMATION "The EA will ask for confirmation before opening a trade."
184-
185+
#define TRANSLATION_LABEL_EXPIRY "Expiry"
186+
#define TRANSLATION_TOOLTIP_EXPIRY "Expiration time in minutes for the next created pending order. Minimum = 2."
187+
#define TRANSLATION_LABEL_MINUTES "min."
188+
#define TRANSLATION_TOOLTIP_MINUTES "Minutes"
185189

186190
// Chart objects
187191
#define TRANSLATION_TOOLTIP_STOP_PRICE_LINE "Stop Price (for Stop Limit orders)"
188192
#define TRANSLATION_TOOLTIP_SL_LABEL "SL Distance, points"
189193
#define TRANSLATION_TOOLTIP_TP_LABEL "TP Distance, points"
190194
#define TRANSLATION_TOOLTIP_ENTRY_LABEL "Entry Distance, points"
191195
#define TRANSLATION_TOOLTIP_STOP_PRICE_LABEL "Stop Price Distance, points"
196+
#define TRANSLATION_TOOLTIP_ENTRY_LABEL_ADDITIONAL "Position Size, lots"
192197

193198

194199
// Warnings
@@ -197,6 +202,7 @@
197202
#define TRANSLATION_LABEL_WARNING_INVALID_TP "Invalid TP"
198203
#define TRANSLATION_TOOLTIP_WARNING_PS "Greater than maximum position size by margin!"
199204

205+
200206
// Messages
201207
#define TRANSLATION_MESSAGE_SL_SHOULD_BE_POSITIVE "Stop-loss should be positive."
202208
#define TRANSLATION_MESSAGE_TRYING_TO_SAVE_FILE "Trying to save settings to file"
@@ -300,4 +306,5 @@
300306
#define TRANSLATION_MESSAGE_FAILED_DELETE_INI "Failed to delete the PS panel's .ini file"
301307
#define TRANSLATION_MESSAGE_CANNOT_CONVERT "Cannot convert"
302308
#define TRANSLATION_MESSAGE_CANNOT_CONVERT_TO "to"
303-
#define TRANSLATION_MESSAGE_CANNOT_CONVERT_CALCULATION "Calculations might be wrong for"
309+
#define TRANSLATION_MESSAGE_CANNOT_CONVERT_CALCULATION "Calculations might be wrong for"
310+
#define TRANSLATION_MESSAGE_MINIMUM_EXPIRY "Minimum expiry duration is 2 minutes."

MQL5/Experts/Position Sizer/Translations/Russian.mqh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@
107107
#define TRANSLATION_TOOLTIP_CURRENT_PORTFOLIO "Сделки, которые сейчас открыты"
108108
#define TRANSLATION_LABEL_POTENTIAL_PORTFOLIO "Потенц. портфол."
109109
#define TRANSLATION_TOOLTIP_POTENTIAL_PORTFOLIO "Включая позицию в расчете"
110+
#define TRANSLATION_LABEL_CRRR_TOOLTIP "Соотношение риска и прибыли текущего портфолио"
111+
#define TRANSLATION_LABEL_PRRR_TOOLTIP "Соотношение риска и прибыли потенциального портфолио"
110112

111113

112114
// Margin tab
@@ -177,6 +179,10 @@
177179
#define TRANSLATION_TOOLTIP_DO_NOT_APPLY_TAKEPROFIT "Советник откроет сделку без тейк-профита."
178180
#define TRANSLATION_CHECKBOX_ASK_FOR_CONFIRMATION "Спрашивать подтверждение"
179181
#define TRANSLATION_TOOLTIP_ASK_FOR_CONFIRMATION "Советник будет спрашивать подтверждение перед открытием сделки."
182+
#define TRANSLATION_LABEL_EXPIRY "Срок"
183+
#define TRANSLATION_TOOLTIP_EXPIRY "Срок истечения в минутах для следующего созданного отложенного ордера. Минимум = 2."
184+
#define TRANSLATION_LABEL_MINUTES "мин."
185+
#define TRANSLATION_TOOLTIP_MINUTES "Минуты"
180186

181187

182188
// Chart objects
@@ -185,6 +191,7 @@
185191
#define TRANSLATION_TOOLTIP_TP_LABEL "Расстояние до ТП, пункты"
186192
#define TRANSLATION_TOOLTIP_ENTRY_LABEL "Расстояние до Входа, пункты"
187193
#define TRANSLATION_TOOLTIP_STOP_PRICE_LABEL "Расстояние до стоп-цены, пункты"
194+
#define TRANSLATION_TOOLTIP_ENTRY_LABEL_ADDITIONAL "Размер позиции, лоты"
188195

189196
// Warnings
190197
#define TRANSLATION_LABEL_WARNING_TOO_CLOSE "(Близко!)"
@@ -295,4 +302,5 @@
295302
#define TRANSLATION_MESSAGE_FAILED_DELETE_INI "Не удалось удалить ini-файл панели"
296303
#define TRANSLATION_MESSAGE_CANNOT_CONVERT "Не получается перевести"
297304
#define TRANSLATION_MESSAGE_CANNOT_CONVERT_TO "в"
298-
#define TRANSLATION_MESSAGE_CANNOT_CONVERT_CALCULATION "Расчет может быть неверен для"
305+
#define TRANSLATION_MESSAGE_CANNOT_CONVERT_CALCULATION "Расчет может быть неверен для"
306+
#define TRANSLATION_MESSAGE_MINIMUM_EXPIRY "Минимальный срок действия отложенного ордера - 2 минуты."

0 commit comments

Comments
 (0)