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\E nglish.mqh"
@@ -30,7 +30,7 @@ string Version = "3.10";
3030
3131input group " Compactness"
3232input 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?
3434input bool ShowAdditionalSLLabel = false ; // ShowAdditionalSLLabel: Show SL $/% label?
3535input bool ShowAdditionalTPLabel = false ; // ShowAdditionalTPLabel: Show TP $/% + R/R label?
3636input bool ShowAdditionalEntryLabel = false ; // ShowAdditionalEntryLabel: Show Position Size label?
@@ -87,10 +87,11 @@ input ACCOUNT_BUTTON DefaultAccountButton = Balance; // AccountButton: Balance/E
8787input double DefaultRisk = 1 ; // Risk: Initial risk tolerance in percentage points
8888input double DefaultMoneyRisk = 0 ; // MoneyRisk: If > 0, money risk tolerance in currency.
8989input 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?
9191input bool DefaultIgnoreOrdersWithoutSL = false ; // IgnoreOrdersWithoutSL: Ignore orders w/o SL in portfolio risk.
9292input 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?
9495input double DefaultCustomLeverage = 0 ; // CustomLeverage: Default custom leverage for Margin tab.
9596input int DefaultMagicNumber = 2022052714 ; // MagicNumber: Default magic number for Trading tab.
9697input string DefaultCommentary = " " ; // Commentary: Default order comment for Trading tab.
@@ -157,6 +158,10 @@ input bool PrefillAdditionalTPsBasedOnMain = true; // Prefill additional TPs bas
157158input bool AskBeforeClosing = false ; // Ask for confirmation before closing the panel?
158159input bool CapMaxPositionSizeBasedOnMargin = false ; // Cap position size based on available margin?
159160input 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
161166CPositionSizeCalculator * ExtDialog ;
162167
@@ -174,6 +179,7 @@ int DeinitializationReason = -1;
174179string OldSymbol = " " ;
175180int OldTakeProfitsNumber = -1 ;
176181int Mouse_Last_X = 0 , Mouse_Last_Y = 0 ; // For SL/TP hotkeys.
182+ color LongButtonColorAdjusted , ShortButtonColorAdjusted , TradeButtonColorAdjusted ; // Based on the DarkMode setting.
177183
178184int 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
584634void 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