Skip to content

Commit

Permalink
3.07
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
EarnForex committed Oct 20, 2023
1 parent 53bf639 commit 615929b
Show file tree
Hide file tree
Showing 11 changed files with 825 additions and 315 deletions.
5 changes: 5 additions & 0 deletions MQL4/Experts/Position Sizer/Defines.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ color DARKMODE_EDIT_BG_COLOR = 0xAAAAAA;
color DARKMODE_BUTTON_BG_COLOR = 0xA19999;
color DARKMODE_TEXT_COLOR = 0x000000;;

color CONTROLS_BUTTON_COLOR_TP_UNLOCKED, CONTROLS_BUTTON_COLOR_TP_LOCKED;

enum ENTRY_TYPE
{
Instant,
Expand Down Expand Up @@ -132,6 +134,8 @@ struct Settings
int MaxEntrySLDistance;
int MinEntrySLDistance;
// For SL/TP distance modes:
bool SLDistanceInPoints;
bool TPDistanceInPoints;
int StopLoss;
int TakeProfit;
// Only for SL distance mode:
Expand All @@ -151,6 +155,7 @@ struct Settings
double MaxPositionSizePerSymbol;
double MaxRiskTotal;
double MaxRiskPerSymbol;
int ExpiryMinutes;
// For ATR:
int ATRPeriod;
double ATRMultiplierSL;
Expand Down
18 changes: 14 additions & 4 deletions MQL4/Experts/Position Sizer/Position Sizer Trading.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ void Trade()
}
}

datetime expiry = 0;
if ((sets.EntryType == Pending) && (sets.ExpiryMinutes > 0))
{
expiry = TimeCurrent() + sets.ExpiryMinutes * 60;
}

if (sets.AskForConfirmation)
{
// Evoke confirmation modal window.
Expand Down Expand Up @@ -281,9 +287,13 @@ void Trade()
if (PositionMargin != 0) message += "Margin: " + FormatDouble(DoubleToString(PositionMargin, 2)) + " " + account_currency + "\n";
message += "Entry: " + DoubleToString(sets.EntryLevel, _Digits) + "\n";
if (!sets.DoNotApplyStopLoss) message += "Stop-loss: " + DoubleToString(sets.StopLossLevel, _Digits) + "\n";
if ((sets.TakeProfitLevel > 0) && (!sets.DoNotApplyTakeProfit)) message += "Take-profit: " + DoubleToString(sets.TakeProfitLevel, _Digits);
if (sets.TakeProfitsNumber > 1) message += " (multiple)";
message += "\n";
if ((sets.TakeProfitLevel > 0) && (!sets.DoNotApplyTakeProfit))
{
message += "Take-profit: " + DoubleToString(sets.TakeProfitLevel, _Digits);
if (sets.TakeProfitsNumber > 1) message += " (multiple)";
message += "\n";
}
if (expiry > 0) message += "Expiry: " + TimeToString(expiry, TIME_DATE|TIME_MINUTES|TIME_SECONDS);

int ret = MessageBox(message, caption, MB_OKCANCEL | MB_ICONWARNING);
if (ret == IDCANCEL)
Expand Down Expand Up @@ -363,7 +373,7 @@ void Trade()
sub_position_size = position_size;
position_size = 0; // End the cycle;
}
int ticket = OrderSend(Symbol(), ot, sub_position_size, sets.EntryLevel, sets.MaxSlippage, order_sl, order_tp, Commentary, sets.MagicNumber);
int ticket = OrderSend(Symbol(), ot, sub_position_size, sets.EntryLevel, sets.MaxSlippage, order_sl, order_tp, Commentary, sets.MagicNumber, expiry);
if (ticket == -1)
{
int error = GetLastError();
Expand Down
241 changes: 153 additions & 88 deletions MQL4/Experts/Position Sizer/Position Sizer.mq4

Large diffs are not rendered by default.

270 changes: 213 additions & 57 deletions MQL4/Experts/Position Sizer/Position Sizer.mqh

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion MQL5/Experts/Position Sizer/Defines.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ color DARKMODE_MAIN_AREA_BORDER_COLOR = 0x333333;
color DARKMODE_MAIN_AREA_BG_COLOR = 0x666666;
color DARKMODE_EDIT_BG_COLOR = 0xAAAAAA;
color DARKMODE_BUTTON_BG_COLOR = 0xA19999;
color DARKMODE_TEXT_COLOR = 0x000000;;
color DARKMODE_TEXT_COLOR = 0x000000;

color CONTROLS_BUTTON_COLOR_TP_UNLOCKED, CONTROLS_BUTTON_COLOR_TP_LOCKED;

enum ENTRY_TYPE
{
Expand Down Expand Up @@ -134,6 +136,8 @@ struct Settings
int MaxEntrySLDistance;
int MinEntrySLDistance;
// For SL/TP distance modes:
bool SLDistanceInPoints;
bool TPDistanceInPoints;
int StopLoss;
int TakeProfit;
// Only for SL distance mode:
Expand All @@ -155,6 +159,7 @@ struct Settings
double MaxPositionSizePerSymbol;
double MaxRiskTotal;
double MaxRiskPerSymbol;
int ExpiryMinutes;
// For ATR:
int ATRPeriod;
double ATRMultiplierSL;
Expand Down
Binary file modified MQL5/Experts/Position Sizer/Position Sizer Trading.mqh
Binary file not shown.
245 changes: 155 additions & 90 deletions MQL5/Experts/Position Sizer/Position Sizer.mq5

Large diffs are not rendered by default.

321 changes: 251 additions & 70 deletions MQL5/Experts/Position Sizer/Position Sizer.mqh

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions MQL5/Experts/Position Sizer/Translations/English.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@
#define TRANSLATION_TOOLTIP_CURRENT_PORTFOLIO "Trades that are currently open"
#define TRANSLATION_LABEL_POTENTIAL_PORTFOLIO "Potential portfolio"
#define TRANSLATION_TOOLTIP_POTENTIAL_PORTFOLIO "Including the position being calculated"

#define TRANSLATION_LABEL_CRRR_TOOLTIP "Risk-to-reward ratio of the current portfolio"
#define TRANSLATION_LABEL_PRRR_TOOLTIP "Risk-to-reward ratio of the potential portfolio"

// Margin tab
#define TRANSLATION_LABEL_POSITION_MARGIN "Position margin"
Expand Down Expand Up @@ -181,14 +182,18 @@
#define TRANSLATION_TOOLTIP_DO_NOT_APPLY_TAKEPROFIT "The EA won't apply take-profit to the trade it opens."
#define TRANSLATION_CHECKBOX_ASK_FOR_CONFIRMATION "Ask for confirmation"
#define TRANSLATION_TOOLTIP_ASK_FOR_CONFIRMATION "The EA will ask for confirmation before opening a trade."

#define TRANSLATION_LABEL_EXPIRY "Expiry"
#define TRANSLATION_TOOLTIP_EXPIRY "Expiration time in minutes for the next created pending order. Minimum = 2."
#define TRANSLATION_LABEL_MINUTES "min."
#define TRANSLATION_TOOLTIP_MINUTES "Minutes"

// Chart objects
#define TRANSLATION_TOOLTIP_STOP_PRICE_LINE "Stop Price (for Stop Limit orders)"
#define TRANSLATION_TOOLTIP_SL_LABEL "SL Distance, points"
#define TRANSLATION_TOOLTIP_TP_LABEL "TP Distance, points"
#define TRANSLATION_TOOLTIP_ENTRY_LABEL "Entry Distance, points"
#define TRANSLATION_TOOLTIP_STOP_PRICE_LABEL "Stop Price Distance, points"
#define TRANSLATION_TOOLTIP_ENTRY_LABEL_ADDITIONAL "Position Size, lots"


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


// Messages
#define TRANSLATION_MESSAGE_SL_SHOULD_BE_POSITIVE "Stop-loss should be positive."
#define TRANSLATION_MESSAGE_TRYING_TO_SAVE_FILE "Trying to save settings to file"
Expand Down Expand Up @@ -300,4 +306,5 @@
#define TRANSLATION_MESSAGE_FAILED_DELETE_INI "Failed to delete the PS panel's .ini file"
#define TRANSLATION_MESSAGE_CANNOT_CONVERT "Cannot convert"
#define TRANSLATION_MESSAGE_CANNOT_CONVERT_TO "to"
#define TRANSLATION_MESSAGE_CANNOT_CONVERT_CALCULATION "Calculations might be wrong for"
#define TRANSLATION_MESSAGE_CANNOT_CONVERT_CALCULATION "Calculations might be wrong for"
#define TRANSLATION_MESSAGE_MINIMUM_EXPIRY "Minimum expiry duration is 2 minutes."
10 changes: 9 additions & 1 deletion MQL5/Experts/Position Sizer/Translations/Russian.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@
#define TRANSLATION_TOOLTIP_CURRENT_PORTFOLIO "Сделки, которые сейчас открыты"
#define TRANSLATION_LABEL_POTENTIAL_PORTFOLIO "Потенц. портфол."
#define TRANSLATION_TOOLTIP_POTENTIAL_PORTFOLIO "Включая позицию в расчете"
#define TRANSLATION_LABEL_CRRR_TOOLTIP "Соотношение риска и прибыли текущего портфолио"
#define TRANSLATION_LABEL_PRRR_TOOLTIP "Соотношение риска и прибыли потенциального портфолио"


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


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

// Warnings
#define TRANSLATION_LABEL_WARNING_TOO_CLOSE "(Близко!)"
Expand Down Expand Up @@ -295,4 +302,5 @@
#define TRANSLATION_MESSAGE_FAILED_DELETE_INI "Не удалось удалить ini-файл панели"
#define TRANSLATION_MESSAGE_CANNOT_CONVERT "Не получается перевести"
#define TRANSLATION_MESSAGE_CANNOT_CONVERT_TO "в"
#define TRANSLATION_MESSAGE_CANNOT_CONVERT_CALCULATION "Расчет может быть неверен для"
#define TRANSLATION_MESSAGE_CANNOT_CONVERT_CALCULATION "Расчет может быть неверен для"
#define TRANSLATION_MESSAGE_MINIMUM_EXPIRY "Минимальный срок действия отложенного ордера - 2 минуты."
10 changes: 9 additions & 1 deletion MQL5/Experts/Position Sizer/Translations/Ukrainian.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@
#define TRANSLATION_TOOLTIP_CURRENT_PORTFOLIO "Угоди, що зараз є відкритими"
#define TRANSLATION_LABEL_POTENTIAL_PORTFOLIO "Потенц. портфол."
#define TRANSLATION_TOOLTIP_POTENTIAL_PORTFOLIO "Включно з позицією у розрахунку"
#define TRANSLATION_LABEL_CRRR_TOOLTIP "Співвідношення ризику та прибутку для поточного портфоліо"
#define TRANSLATION_LABEL_PRRR_TOOLTIP "Співвідношення ризику та прибутку для потенційного портфоліо"


// Margin tab
Expand Down Expand Up @@ -177,6 +179,10 @@
#define TRANSLATION_TOOLTIP_DO_NOT_APPLY_TAKEPROFIT "Експерт відкриє угоду без тейк-профіту."
#define TRANSLATION_CHECKBOX_ASK_FOR_CONFIRMATION "Запитувати підтвердження"
#define TRANSLATION_TOOLTIP_ASK_FOR_CONFIRMATION "Експерт буде запитувати підтвердження перед відкриттям угоди."
#define TRANSLATION_LABEL_EXPIRY "Термін"
#define TRANSLATION_TOOLTIP_EXPIRY "Термін дії у хвилинах для наступного створеного відкладеного ордеру. Мінімум = 2."
#define TRANSLATION_LABEL_MINUTES "хв."
#define TRANSLATION_TOOLTIP_MINUTES "Хвилини"


// Chart objects
Expand All @@ -185,6 +191,7 @@
#define TRANSLATION_TOOLTIP_TP_LABEL "Відстань до ТП, пункти"
#define TRANSLATION_TOOLTIP_ENTRY_LABEL "Відстань до Входу, пункти"
#define TRANSLATION_TOOLTIP_STOP_PRICE_LABEL "Відстань до стоп-ціни, пункти"
#define TRANSLATION_TOOLTIP_ENTRY_LABEL_ADDITIONAL "Розмір позиції, лоти"


// Warnings
Expand Down Expand Up @@ -297,4 +304,5 @@
#define TRANSLATION_MESSAGE_FAILED_DELETE_INI "Не вдалося видалити ini-файл панелі"
#define TRANSLATION_MESSAGE_CANNOT_CONVERT "Не можна перевести"
#define TRANSLATION_MESSAGE_CANNOT_CONVERT_TO "у"
#define TRANSLATION_MESSAGE_CANNOT_CONVERT_CALCULATION "Розрахунок може бути хибним для"
#define TRANSLATION_MESSAGE_CANNOT_CONVERT_CALCULATION "Розрахунок може бути хибним для"
#define TRANSLATION_MESSAGE_MINIMUM_EXPIRY "Мінімальний термін дії відкладеного ордеру - 2 хвилини."

0 comments on commit 615929b

Please sign in to comment.