Skip to content

Commit 903f700

Browse files
author
EarnForex
authored
3.08
1. Added optional additional Trade buttons. 2. Added keyboard modifiers for the increase and decrease buttons to add/subtract in multiples of the tick size. 3. Added some additional logging when a trade is executed. 4. Added an option to hide the Entry line for Instant orders. 5. Added an automatic replacement from comma to period as a decimal separator for values entered via the panel's input fields. 6. Added an input parameter to ask for a confirmation when closing the panel. 7. Fixed a bug in MT5 that could sometimes cause the Breakeven feature to fail. 8. Fixed a bug that prevented hotkeys from being turned off. 9. Fixed a bug with the Maximum Position Size Total value overwriting the the Maximum Position Size per Symbol value. 10. Fixed a bug with trades not executing when stop-loss or take-profit are too close to entry but the respective ignore SL or ignore TP checkboxes are ticked. 11. Fixed a bug when additional TP values could change when switching from Short to Long or vice versa. 12. Fixed a bug that could lead to a glitch with take-profit values when switching TP from levels to points via a hotkey. 13. Fixed a bug with the additional Entry label remaining on the chart when the respective input parameter has been switched to false. 14. Changed the additional take-profits to follow the main take-profit when it is "locked" on the stop-loss. 15. Changed all warning messages from alerts to prints.
1 parent 30b44f5 commit 903f700

File tree

11 files changed

+726
-185
lines changed

11 files changed

+726
-185
lines changed

MQL4/Experts/Position Sizer/Defines.mqh

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//+------------------------------------------------------------------+
22
//| Defines.mqh |
3-
//| Copyright © 2023, EarnForex.com |
3+
//| Copyright © 2024, EarnForex.com |
44
//| https://www.earnforex.com/ |
55
//+------------------------------------------------------------------+
66
#include <Controls\Button.mqh>
@@ -25,6 +25,10 @@ color DARKMODE_TEXT_COLOR = 0x000000;;
2525

2626
color CONTROLS_BUTTON_COLOR_TP_UNLOCKED, CONTROLS_BUTTON_COLOR_TP_LOCKED;
2727

28+
#define MULTIPLIER_VALUE_CONTROL 10
29+
#define MULTIPLIER_VALUE_SHIFT 100
30+
#define MULTIPLIER_VALUE_CONTROL_SHIFT 1000
31+
2832
enum ENTRY_TYPE
2933
{
3034
Instant,
@@ -99,6 +103,20 @@ enum CALCULATE_RISK_FOR_TRADING_TAB
99103
CALCULATE_RISK_FOR_TRADING_TAB_PER_SYMBOL // For Trading tab - per symbol
100104
};
101105

106+
enum ADDITIONAL_TP_SCHEME
107+
{
108+
ADDITIONAL_TP_SCHEME_INWARD, // The "<<" button has been clicked.
109+
ADDITIONAL_TP_SCHEME_OUTWARD // The ">>" button has been clicked.
110+
};
111+
112+
enum ADDITIONAL_TRADE_BUTTONS
113+
{
114+
ADDITIONAL_TRADE_BUTTONS_NONE, // None
115+
ADDITIONAL_TRADE_BUTTONS_LINE, // Above the Entry line
116+
ADDITIONAL_TRADE_BUTTONS_MAIN, // Main tab
117+
ADDITIONAL_TRADE_BUTTONS_BOTH // Both
118+
};
119+
102120
struct Settings
103121
{
104122
ENTRY_TYPE EntryType;
@@ -173,6 +191,7 @@ struct Settings
173191
bool TPLockedOnSL;
174192
VOLUME_SHARE_MODE ShareVolumeMode;
175193
bool TemplateChanged;
194+
ADDITIONAL_TP_SCHEME LastAdditionalTPScheme;
176195
} sets;
177196

178197
// An object class for a list of panel objects with their names for fields located on a given tab of the panel. There will be one list per tab.

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//+------------------------------------------------------------------+
22
//| Position Sizer Trading.mqh |
3-
//| Copyright © 2023, EarnForex.com |
3+
//| Copyright © 2024, EarnForex.com |
44
//| https://www.earnforex.com/ |
55
//+------------------------------------------------------------------+
66
#include <stdlib.mqh>
@@ -18,7 +18,7 @@ void Trade()
1818
return;
1919
}
2020

21-
if (WarningSL != "") // Too close or wrong value.
21+
if ((WarningSL != "") && (!sets.DoNotApplyStopLoss)) // Too close or wrong value.
2222
{
2323
Alert("Stop-loss problem: " + WarningSL);
2424
return;
@@ -164,7 +164,6 @@ void Trade()
164164
string warning_suffix = "";
165165
if ((Execution_Mode == SYMBOL_TRADE_EXECUTION_MARKET) && (IgnoreMarketExecutionMode) && (sets.EntryType == Instant)) warning_suffix = ", but IgnoreMarketExecutionMode = true. Switch to false if trades aren't executing.";
166166
Print("Execution mode: ", EnumToString(Execution_Mode), warning_suffix);
167-
168167

169168
ENUM_ORDER_TYPE ot;
170169
if (sets.EntryType == Pending)
@@ -303,6 +302,15 @@ void Trade()
303302
}
304303
}
305304

305+
if (sets.DoNotApplyStopLoss)
306+
{
307+
Print("'Do not apply stop-loss' checkbox is ticked.");
308+
}
309+
if (sets.DoNotApplyTakeProfit)
310+
{
311+
Print("'Do not apply take-profit' checkbox is ticked.");
312+
}
313+
306314
// Use ArrayPositionSize that has already been calculated in CalculateRiskAndPositionSize().
307315
// Check if they are OK.
308316
for (int j = sets.TakeProfitsNumber - 1; j >= 0; j--)

MQL4/Experts/Position Sizer/Position Sizer.mq4

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
//+------------------------------------------------------------------+
22
//| Position Sizer.mq4 |
3-
//| Copyright © 2023, EarnForex.com |
3+
//| Copyright © 2024, 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.07"
10-
string Version = "3.07";
9+
#property version "3.08"
10+
string Version = "3.08";
1111
#property strict
1212

1313
#property description "Calculates risk-based position size for your account."
@@ -33,6 +33,8 @@ input bool ShowATROptions = false; // ShowATROptions: If true, SL and TP can be
3333
input bool ShowMaxParametersOnTrading = true; // Show max parameters on Trading tab?
3434
input bool ShowFusesOnTrading = true; // Show trading "fuses" on Trading tab?
3535
input bool ShowCheckboxesOnTrading = true; // Show checkboxes on Trading tab?
36+
input bool HideEntryLineOnInstant = false; // Hide Entry line for Instant orders?
37+
input ADDITIONAL_TRADE_BUTTONS AdditionalTradeButtons = ADDITIONAL_TRADE_BUTTONS_NONE; // Additional Trade buttons:
3638
input group "Fonts"
3739
input string ____Fonts = "";
3840
input color sl_label_font_color = clrGreen; // SL Label Color
@@ -141,6 +143,7 @@ input bool MarketModeApplySLTPAfterAllTradesExecuted = false; // Market Mode - A
141143
input bool DarkMode = false; // DarkMode: Enable dark mode for a less bright panel.
142144
input string SettingsFile = ""; // SettingsFile: Load custom panel settings from \Files\ folder.
143145
input bool PrefillAdditionalTPsBasedOnMain = true; // Prefill additional TPs based on Main?
146+
input bool AskBeforeClosing = false; // Ask for confirmation before closing the panel?
144147

145148
CPositionSizeCalculator* ExtDialog;
146149

@@ -317,6 +320,7 @@ int OnInit()
317320
sets.SLDistanceInPoints = DefaultSLDistanceInPoints;
318321
sets.TPDistanceInPoints = DefaultTPDistanceInPoints;
319322
if (DeinitializationReason == REASON_CHARTCHANGE) is_InitControlsValues_required = true;
323+
sets.LastAdditionalTPScheme = ADDITIONAL_TP_SCHEME_OUTWARD;
320324
}
321325
if (sets.TakeProfitsNumber < 1) // Read an old settings file with absent or bogus TakeProfitNumber parameter
322326
{
@@ -342,15 +346,25 @@ int OnInit()
342346

343347
// If a hotkey is given, break up the string to check for hotkey presses in OnChartEvent().
344348
if (TradeHotKey != "") DissectHotKeyCombination(TradeHotKey, ShiftRequired_TradeHotKey, CtrlRequired_TradeHotKey, MainKey_TradeHotKey);
349+
else MainKey_TradeHotKey = 0;
345350
if (SwitchEntryDirectionHotKey != "") DissectHotKeyCombination(SwitchEntryDirectionHotKey, ShiftRequired_SwitchEntryDirectionHotKey, CtrlRequired_SwitchEntryDirectionHotKey, MainKey_SwitchEntryDirectionHotKey);
351+
else MainKey_SwitchEntryDirectionHotKey = 0;
346352
if (SwitchOrderTypeHotKey != "") DissectHotKeyCombination(SwitchOrderTypeHotKey, ShiftRequired_SwitchOrderTypeHotKey, CtrlRequired_SwitchOrderTypeHotKey, MainKey_SwitchOrderTypeHotKey);
353+
else MainKey_SwitchOrderTypeHotKey = 0;
347354
if (SwitchHideShowLinesHotKey != "") DissectHotKeyCombination(SwitchHideShowLinesHotKey, ShiftRequired_SwitchHideShowLinesHotKey, CtrlRequired_SwitchHideShowLinesHotKey, MainKey_SwitchHideShowLinesHotKey);
355+
else MainKey_SwitchHideShowLinesHotKey = 0;
348356
if (SetStopLossHotKey != "") DissectHotKeyCombination(SetStopLossHotKey, ShiftRequired_SetStopLossHotKey, CtrlRequired_SetStopLossHotKey, MainKey_SetStopLossHotKey);
357+
else MainKey_SetStopLossHotKey = 0;
349358
if (SetTakeProfitHotKey != "") DissectHotKeyCombination(SetTakeProfitHotKey, ShiftRequired_SetTakeProfitHotKey, CtrlRequired_SetTakeProfitHotKey, MainKey_SetTakeProfitHotKey);
359+
else MainKey_SetTakeProfitHotKey = 0;
350360
if (SetEntryHotKey != "") DissectHotKeyCombination(SetEntryHotKey, ShiftRequired_SetEntryHotKey, CtrlRequired_SetEntryHotKey, MainKey_SetEntryHotKey);
361+
else MainKey_SetEntryHotKey = 0;
351362
if (SwitchSLPointsLevelHotKey != "") DissectHotKeyCombination(SwitchSLPointsLevelHotKey, ShiftRequired_SwitchSLPointsLevelHotKey, CtrlRequired_SwitchSLPointsLevelHotKey, MainKey_SwitchSLPointsLevelHotKey);
363+
else MainKey_SwitchSLPointsLevelHotKey = 0;
352364
if (SwitchTPPointsLevelHotKey != "") DissectHotKeyCombination(SwitchTPPointsLevelHotKey, ShiftRequired_SwitchTPPointsLevelHotKey, CtrlRequired_SwitchTPPointsLevelHotKey, MainKey_SwitchTPPointsLevelHotKey);
365+
else MainKey_SwitchTPPointsLevelHotKey = 0;
353366
if (MinimizeMaximizeHotkey != "") DissectHotKeyCombination(MinimizeMaximizeHotkey, ShiftRequired_MinimizeMaximizeHotkey, CtrlRequired_MinimizeMaximizeHotkey, MainKey_MinimizeMaximizeHotkey);
367+
else MainKey_MinimizeMaximizeHotkey = 0;
354368
}
355369
else if (OldSymbol != _Symbol)
356370
{
@@ -542,6 +556,7 @@ void OnDeinit(const int reason)
542556
ObjectsDeleteAll(0, ObjectPrefix + "TakeProfitLabel", -1, OBJ_LABEL);
543557
ObjectsDeleteAll(0, ObjectPrefix + "TPAdditionalLabel", -1, OBJ_LABEL);
544558
ObjectDelete(0, ObjectPrefix + "SLAdditionalLabel");
559+
ObjectDelete(0, ObjectPrefix + "EntryAdditionalLabel");
545560
ExtDialog.Destroy();
546561
delete ExtDialog;
547562
}
@@ -604,6 +619,13 @@ void OnChartEvent(const int id,
604619
}
605620
}
606621

622+
// This cannot be done using the panel's event handler because the outside trade button isn't added to its list of controls.
623+
if ((id == CHARTEVENT_OBJECT_CLICK) && (sparam == ExtDialog.Name() + "m_OutsideTradeButton"))
624+
{
625+
ExtDialog.m_OutsideTradeButton.Pressed(false);
626+
Trade();
627+
}
628+
607629
if (id == CHARTEVENT_CLICK) // Avoid "sticking" of xxxLineIsBeingMoved variables.
608630
{
609631
StopLossLineIsBeingMoved = false;
@@ -812,7 +834,7 @@ void OnChartEvent(const int id,
812834
{
813835
if (sets.TP[i] != 0) // With zero points TP, keep the TP lines at zero level - as with the main TP level.
814836
{
815-
ExtDialog.AdditionalTPEdits[i - 1].Text(DoubleToString(MathRound((sets.TP[i] - sets.EntryLevel) / _Point), 0));
837+
ExtDialog.AdditionalTPEdits[i - 1].Text(DoubleToString(MathAbs(MathRound((sets.TP[i] - sets.EntryLevel) / _Point)), 0));
816838
}
817839
}
818840
}

0 commit comments

Comments
 (0)