Skip to content

Commit bd62011

Browse files
author
EarnForex
authored
3.11
1. Added an input parameter to avoid deleting the Position Sizer's lines and line labels when the EA is removed. 2. Added two input parameters to set colors for the Long/Short order direction button. 3. Added an input parameter to set the color for the Trade buttons. 4. Added the Include directions switch to the Risk tab to filter either All, Buy only, or Sell only when calculating risk and reward data. 5. Changed how the TP-locked-on-SL feature works. It is now turned on and off via a dedicated checkbox on the Main tab rather than being bound to the TP button. 6. Changed the ShowLineLabels input parameter to ShowMainLineLabels and it no longer controls additional line labels. 7. Changed how often the Position Sizer refreshes the account and symbol information to avoid calculations based on stale data. 8. Changed the Count pending orders checkbox on the Risk tab to a button that switches between All, Pending orders, and Open positions. 9. Changed the Ignore symbols switch to the Include symbols switch on the Risk tab. 10. Fixed a minor bug in the MT5 version when the hide/show lines hotkey worked with some small delay. 11. Fixed a bug with the SL/TP values not resetting to defaults when changing the chart's symbol while the SymbolChange parameter is set to Reset to defaults on symbol change. 12. Fixed a bug with the outside Trade button not changing color when the Dark Mode is switched on.
1 parent a182c83 commit bd62011

25 files changed

Lines changed: 1217 additions & 856 deletions

MQL4/Experts/Position Sizer/Defines.mqh

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//+------------------------------------------------------------------+
22
//| Defines.mqh |
3-
//| Copyright © 2024, EarnForex.com |
3+
//| Copyright © 2025, EarnForex.com |
44
//| https://www.earnforex.com/ |
55
//+------------------------------------------------------------------+
66
#include <Controls\Button.mqh>
@@ -117,11 +117,25 @@ enum ADDITIONAL_TRADE_BUTTONS
117117
ADDITIONAL_TRADE_BUTTONS_BOTH // Both
118118
};
119119

120-
enum IGNORE_SYMBOLS
120+
enum INCLUDE_SYMBOLS
121121
{
122-
IGNORE_SYMBOLS_NONE, // No symbols
123-
IGNORE_SYMBOLS_OTHER, // Other symbols
124-
IGNORE_SYMBOLS_CURRENT, // Current symbol
122+
INCLUDE_SYMBOLS_ALL, // All symbols
123+
INCLUDE_SYMBOLS_CURRENT, // Current symbol only
124+
INCLUDE_SYMBOLS_OTHER, // Other symbols only
125+
};
126+
127+
enum INCLUDE_ORDERS
128+
{
129+
INCLUDE_ORDERS_ALL, // All orders
130+
INCLUDE_ORDERS_OPEN, // Open orders only
131+
INCLUDE_ORDERS_PENDING, // Pending orders only
132+
};
133+
134+
enum INCLUDE_DIRECTIONS
135+
{
136+
INCLUDE_DIRECTIONS_ALL, // All directions
137+
INCLUDE_DIRECTIONS_BUY, // Buy only
138+
INCLUDE_DIRECTIONS_SELL, // Sell only
125139
};
126140

127141
struct Settings
@@ -141,10 +155,11 @@ struct Settings
141155
ACCOUNT_BUTTON AccountButton;
142156
double CustomBalance;
143157
bool DeleteLines;
144-
bool CountPendingOrders;
158+
INCLUDE_ORDERS IncludeOrders;
145159
bool IgnoreOrdersWithoutSL;
146160
bool IgnoreOrdersWithoutTP;
147-
IGNORE_SYMBOLS IgnoreSymbols;
161+
INCLUDE_SYMBOLS IncludeSymbols;
162+
INCLUDE_DIRECTIONS IncludeDirections;
148163
bool HideAccSize;
149164
bool ShowLines;
150165
TABS SelectedTab;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//+------------------------------------------------------------------+
22
//| Position Sizer Trading.mqh |
3-
//| Copyright © 2024, EarnForex.com |
3+
//| Copyright © 2025, EarnForex.com |
44
//| https://www.earnforex.com/ |
55
//+------------------------------------------------------------------+
66
#include <stdlib.mqh>
@@ -622,7 +622,7 @@ void DoBreakEven()
622622
if (!OrderSelect(ticket, SELECT_BY_TICKET)) // No longer exists.
623623
{
624624
ObjectDelete(ChartID(), obj_name); // Delete the line.
625-
if (ShowLineLabels) ObjectDelete(ChartID(), ObjectPrefix + "BEL" + IntegerToString(ticket)); // Delete the label.
625+
if (ShowMainLineLabels) ObjectDelete(ChartID(), ObjectPrefix + "BEL" + IntegerToString(ticket)); // Delete the label.
626626
}
627627
else // Check if already triggered. Order selected.
628628
{
@@ -631,7 +631,7 @@ void DoBreakEven()
631631
|| ((OrderType() == OP_SELL) && (OrderStopLoss() <= be_price) && (OrderStopLoss() != 0)))
632632
{
633633
ObjectDelete(ChartID(), obj_name); // Delete the line.
634-
if (ShowLineLabels) ObjectDelete(ChartID(), ObjectPrefix + "BEL" + IntegerToString(ticket)); // Delete the label.
634+
if (ShowMainLineLabels) ObjectDelete(ChartID(), ObjectPrefix + "BEL" + IntegerToString(ticket)); // Delete the label.
635635
}
636636
}
637637
}
@@ -712,7 +712,7 @@ void DrawBELine(int ticket, double be_threshold, double be_price)
712712
if (sets.ShowLines) ObjectSetInteger(ChartID(), obj_name, OBJPROP_TIMEFRAMES, OBJ_ALL_PERIODS);
713713
else ObjectSetInteger(ChartID(), obj_name, OBJPROP_TIMEFRAMES, OBJ_NO_PERIODS);
714714

715-
if (ShowLineLabels)
715+
if (ShowMainLineLabels)
716716
{
717717
obj_name = ObjectPrefix + "BEL" + IntegerToString(ticket); // Label.
718718
ObjectCreate(ChartID(), obj_name, OBJ_LABEL, 0, 0, 0);

MQL4/Experts/Position Sizer/Position Sizer.mq4

Lines changed: 73 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
//+------------------------------------------------------------------+
22
//| Position Sizer.mq4 |
3-
//| Copyright © 2024, EarnForex.com |
3+
//| Copyright © 2025, EarnForex.com |
44
//| https://www.earnforex.com/ |
55
//+------------------------------------------------------------------+
66
#property copyright "EarnForex.com"
77
#property link "https://www.earnforex.com/metatrader-expert-advisors/Position-Sizer/"
88
#property icon "EF-Icon-64x64px.ico"
9-
#property version "3.10"
10-
string Version = "3.10";
9+
#property version "3.11"
10+
string Version = "3.11";
1111
#property strict
1212

1313
#include "Translations\English.mqh"
@@ -30,7 +30,7 @@ string Version = "3.10";
3030

3131
input group "Compactness"
3232
input string ____Compactness = "";
33-
input bool ShowLineLabels = true; // ShowLineLabels: Show point distance for TP/SL near lines?
33+
input bool ShowMainLineLabels = true; // ShowMainLineLabels: Show point distance for TP/SL near lines?
3434
input bool ShowAdditionalSLLabel = false; // ShowAdditionalSLLabel: Show SL $/% label?
3535
input bool ShowAdditionalTPLabel = false; // ShowAdditionalTPLabel: Show TP $/% + R/R label?
3636
input bool ShowAdditionalEntryLabel = false; // ShowAdditionalEntryLabel: Show Position Size label?
@@ -87,10 +87,11 @@ input ACCOUNT_BUTTON DefaultAccountButton = Balance; // AccountButton: Balance/E
8787
input double DefaultRisk = 1; // Risk: Initial risk tolerance in percentage points
8888
input double DefaultMoneyRisk = 0; // MoneyRisk: If > 0, money risk tolerance in currency.
8989
input double DefaultPositionSize = 0; // PositionSize: If > 0, position size in lots.
90-
input bool DefaultCountPendingOrders = false; // CountPendingOrders: Count pending orders for portfolio risk.
90+
input INCLUDE_ORDERS DefaultIncludeOrders = INCLUDE_ORDERS_ALL; // IncludeOrders: Include which orders for portfolio risk?
9191
input bool DefaultIgnoreOrdersWithoutSL = false; // IgnoreOrdersWithoutSL: Ignore orders w/o SL in portfolio risk.
9292
input bool DefaultIgnoreOrdersWithoutTP = false; // IgnoreOrdersWithoutTP: Ignore orders w/o TP in portfolio risk.
93-
input IGNORE_SYMBOLS DefaultIgnoreSymbols = IGNORE_SYMBOLS_NONE; // IgnoreSymbols: Ignore trades in some symbols for portfolio risk?
93+
input INCLUDE_SYMBOLS DefaultIncludeSymbols = INCLUDE_SYMBOLS_ALL; // IncludeSymbols: Include trades in which symbols for portfolio risk?
94+
input INCLUDE_DIRECTIONS DefaultIncludeDirections = INCLUDE_DIRECTIONS_ALL; // IncludeDirections: Include which directions for portfolio risk?
9495
input double DefaultCustomLeverage = 0; // CustomLeverage: Default custom leverage for Margin tab.
9596
input int DefaultMagicNumber = 2022052714; // MagicNumber: Default magic number for Trading tab.
9697
input string DefaultCommentary = ""; // Commentary: Default order comment for Trading tab.
@@ -157,6 +158,10 @@ input bool PrefillAdditionalTPsBasedOnMain = true; // Prefill additional TPs bas
157158
input bool AskBeforeClosing = false; // Ask for confirmation before closing the panel?
158159
input bool CapMaxPositionSizeBasedOnMargin = false; // Cap position size based on available margin?
159160
input bool LessRestrictiveMaxLimits = false; // Allow smaller trades when trading limits are exceeded?
161+
input color LongButtonColor = CONTROLS_BUTTON_COLOR_BG; // Long Button Color
162+
input color ShortButtonColor = CONTROLS_BUTTON_COLOR_BG; // Short Button Color
163+
input color TradeButtonColor = CONTROLS_BUTTON_COLOR_BG; // Trade Button Color
164+
input bool DoNotDeleteLinesLabels = false; // Do Not Delete Lines/Labels on on deinitialization?
160165

161166
CPositionSizeCalculator* ExtDialog;
162167

@@ -174,6 +179,7 @@ int DeinitializationReason = -1;
174179
string OldSymbol = "";
175180
int OldTakeProfitsNumber = -1;
176181
int Mouse_Last_X = 0, Mouse_Last_Y = 0; // For SL/TP hotkeys.
182+
color LongButtonColorAdjusted, ShortButtonColorAdjusted, TradeButtonColorAdjusted; // Based on the DarkMode setting.
177183

178184
int OnInit()
179185
{
@@ -195,6 +201,33 @@ int OnInit()
195201
CONTROLS_BUTTON_COLOR_TP_UNLOCKED = CONTROLS_BUTTON_COLOR_BG;
196202
CONTROLS_BUTTON_COLOR_TP_LOCKED = CONTROLS_BUTTON_COLOR_ENABLE;
197203
}
204+
if (LongButtonColor == CONTROLS_BUTTON_COLOR_BG) // Default color is used.
205+
{
206+
if (DarkMode) LongButtonColorAdjusted = DARKMODE_BUTTON_BG_COLOR;
207+
else LongButtonColorAdjusted = CONTROLS_BUTTON_COLOR_BG;
208+
}
209+
else
210+
{
211+
LongButtonColorAdjusted = LongButtonColor;
212+
}
213+
if (ShortButtonColor == CONTROLS_BUTTON_COLOR_BG) // Default color is used.
214+
{
215+
if (DarkMode) ShortButtonColorAdjusted = DARKMODE_BUTTON_BG_COLOR;
216+
else ShortButtonColorAdjusted = CONTROLS_BUTTON_COLOR_BG;
217+
}
218+
else
219+
{
220+
ShortButtonColorAdjusted = ShortButtonColor;
221+
}
222+
if (TradeButtonColor == CONTROLS_BUTTON_COLOR_BG) // Default color is used.
223+
{
224+
if (DarkMode) TradeButtonColorAdjusted = DARKMODE_BUTTON_BG_COLOR;
225+
else TradeButtonColorAdjusted = CONTROLS_BUTTON_COLOR_BG;
226+
}
227+
else
228+
{
229+
TradeButtonColorAdjusted = TradeButtonColor;
230+
}
198231

199232
TickSize = -1;
200233

@@ -279,10 +312,11 @@ int OnInit()
279312
sets.CommissionType = DefaultCommissionType;
280313
sets.CustomBalance = CustomBalance;
281314
sets.AccountButton = DefaultAccountButton;
282-
sets.CountPendingOrders = DefaultCountPendingOrders; // If true, portfolio risk calculation will also involve pending orders.
315+
sets.IncludeOrders = DefaultIncludeOrders; // Will portfolio risk calculation include all orders?
283316
sets.IgnoreOrdersWithoutSL = DefaultIgnoreOrdersWithoutSL; // If true, portfolio risk calculation will skip orders without stop-loss.
284317
sets.IgnoreOrdersWithoutTP = DefaultIgnoreOrdersWithoutTP; // If true, portfolio risk calculation will skip orders without take-profit.
285-
sets.IgnoreSymbols = DefaultIgnoreSymbols; // Skip trades in other/current/no symbols for portfolio risk calculation.
318+
sets.IncludeSymbols = DefaultIncludeSymbols; // Include all symbols in portfolio risk calculation?
319+
sets.IncludeDirections = DefaultIncludeDirections; // Include all trade directions in portfolio risk calculation?
286320
sets.HideAccSize = HideAccSize; // If true, account size line will not be shown.
287321
sets.ShowLines = DefaultShowLines;
288322
sets.SelectedTab = MainTab;
@@ -500,13 +534,26 @@ int OnInit()
500534
ObjectSetInteger(ChartID(), obj_name, OBJPROP_COLOR, DARKMODE_MAIN_AREA_BORDER_COLOR);
501535
ObjectSetInteger(ChartID(), obj_name, OBJPROP_BGCOLOR, DARKMODE_MAIN_AREA_BG_COLOR);
502536
}
503-
else if (StringSubstr(obj_name, 0, StringLen(ExtDialog.Name() + "m_Edt")) == ExtDialog.Name() + "m_Edt")
537+
else if (obj_name == ExtDialog.Name() + "m_BtnEntry") // Long/Short
504538
{
505-
ObjectSetInteger(ChartID(), obj_name, OBJPROP_BGCOLOR, DARKMODE_EDIT_BG_COLOR);
539+
if (sets.TradeDirection == Long)
540+
{
541+
ObjectSetInteger(ChartID(), obj_name, OBJPROP_BGCOLOR, LongButtonColorAdjusted);
542+
}
543+
else if (sets.TradeDirection == Short)
544+
{
545+
ObjectSetInteger(ChartID(), obj_name, OBJPROP_BGCOLOR, ShortButtonColorAdjusted);
546+
}
506547
ObjectSetInteger(ChartID(), obj_name, OBJPROP_BORDER_COLOR, DARKMODE_CONTROL_BRODER_COLOR);
507548
}
508-
else if (obj_name == ExtDialog.Name() + "m_BtnTakeProfit") // TakeProfit button has its own colors.
549+
else if ((obj_name == ExtDialog.Name() + "m_BtnMainTrade") || (obj_name == ExtDialog.Name() + "m_BtnTrade") || (obj_name == ExtDialog.Name() + "m_OutsideTradeButton")) // Any of the Trade buttons (Main tab, Trading tab, outside).
509550
{
551+
ObjectSetInteger(ChartID(), obj_name, OBJPROP_BGCOLOR, TradeButtonColorAdjusted);
552+
ObjectSetInteger(ChartID(), obj_name, OBJPROP_BORDER_COLOR, DARKMODE_CONTROL_BRODER_COLOR);
553+
}
554+
else if (StringSubstr(obj_name, 0, StringLen(ExtDialog.Name() + "m_Edt")) == ExtDialog.Name() + "m_Edt")
555+
{
556+
ObjectSetInteger(ChartID(), obj_name, OBJPROP_BGCOLOR, DARKMODE_EDIT_BG_COLOR);
510557
ObjectSetInteger(ChartID(), obj_name, OBJPROP_BORDER_COLOR, DARKMODE_CONTROL_BRODER_COLOR);
511558
}
512559
else if (StringSubstr(obj_name, 0, StringLen(ExtDialog.Name() + "m_Btn")) == ExtDialog.Name() + "m_Btn")
@@ -544,7 +591,7 @@ void OnDeinit(const int reason)
544591

545592
if ((reason == REASON_CLOSE) || (reason == REASON_REMOVE) || (reason == REASON_CHARTCLOSE) || (reason == REASON_PROGRAM))
546593
{
547-
ObjectsDeleteAll(0, ObjectPrefix); // Delete all lines if platform was closed.
594+
if (!DoNotDeleteLinesLabels) ObjectsDeleteAll(0, ObjectPrefix); // Delete all lines if platform was closed.
548595
if ((reason == REASON_REMOVE) || (reason == REASON_PROGRAM))
549596
{
550597
if (SettingsFile == "") ExtDialog.DeleteSettingsFile();
@@ -568,17 +615,20 @@ void OnDeinit(const int reason)
568615
}
569616
else
570617
{
571-
ObjectDelete(0, ObjectPrefix + "StopLossLabel");
572-
ObjectDelete(0, ObjectPrefix + "EntryLabel");
573-
ObjectsDeleteAll(0, ObjectPrefix + "TakeProfitLabel", -1, OBJ_LABEL);
574-
ObjectsDeleteAll(0, ObjectPrefix + "TPAdditionalLabel", -1, OBJ_LABEL);
575-
ObjectDelete(0, ObjectPrefix + "SLAdditionalLabel");
576-
ObjectDelete(0, ObjectPrefix + "EntryAdditionalLabel");
618+
if (!DoNotDeleteLinesLabels)
619+
{
620+
ObjectDelete(0, ObjectPrefix + "StopLossLabel");
621+
ObjectDelete(0, ObjectPrefix + "EntryLabel");
622+
ObjectsDeleteAll(0, ObjectPrefix + "TakeProfitLabel", -1, OBJ_LABEL);
623+
ObjectsDeleteAll(0, ObjectPrefix + "TPAdditionalLabel", -1, OBJ_LABEL);
624+
ObjectDelete(0, ObjectPrefix + "SLAdditionalLabel");
625+
ObjectDelete(0, ObjectPrefix + "EntryAdditionalLabel");
626+
}
577627
ExtDialog.Destroy();
578628
delete ExtDialog;
579629
}
580630

581-
ObjectsDeleteAll(0, ObjectPrefix + "BE"); // Delete all BE lines and labels.
631+
if (!DoNotDeleteLinesLabels) ObjectsDeleteAll(0, ObjectPrefix + "BE"); // Delete all BE lines and labels.
582632
}
583633

584634
void OnTick()
@@ -804,8 +854,10 @@ void OnChartEvent(const int id,
804854
// If "TP locked on SL" mode was on, turn it off.
805855
if (sets.TPLockedOnSL)
806856
{
807-
ExtDialog.SetTPButtonBackGroundColor(CONTROLS_BUTTON_COLOR_TP_UNLOCKED);
808857
sets.TPLockedOnSL = false;
858+
ObjectSetInteger(ChartID(), ObjectPrefix + "TakeProfitLine", OBJPROP_SELECTABLE, true);
859+
ObjectSetInteger(ChartID(), ObjectPrefix + "TakeProfitLine", OBJPROP_SELECTED, sets.WasSelectedTakeProfitLine);
860+
ExtDialog.ResetChkTPLockedOnSL();
809861
}
810862
if (TickSize > 0) price = NormalizeDouble(MathRound(price / TickSize) * TickSize, _Digits);
811863
ObjectSetDouble(ChartID(), ObjectPrefix + "TakeProfitLine", OBJPROP_PRICE, price);
@@ -919,7 +971,7 @@ void OnChartEvent(const int id,
919971
int chart_width = (int)ChartGetInteger(0, CHART_WIDTH_IN_PIXELS);
920972
if (ExtDialog.Left() > chart_width) ExtDialog.Move(chart_width - ExtDialog.Width(), ExtDialog.Top());
921973
// If chart was brought on top, refresh values to move labels.
922-
if ((prev_chart_on_top == false) && (ShowLineLabels)) ExtDialog.RefreshValues();
974+
if ((prev_chart_on_top == false) && ((ShowMainLineLabels) || (ShowAdditionalEntryLabel) || (ShowAdditionalTPLabel) || (ShowAdditionalSLLabel))) ExtDialog.RefreshValues();
923975
}
924976
// Remember if the chart is on top or is minimized.
925977
prev_chart_on_top = ChartGetInteger(ChartID(), CHART_BRING_TO_TOP);

0 commit comments

Comments
 (0)