Skip to content

Commit

Permalink
3.08
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
EarnForex committed May 16, 2024
1 parent 30b44f5 commit 903f700
Show file tree
Hide file tree
Showing 11 changed files with 726 additions and 185 deletions.
21 changes: 20 additions & 1 deletion MQL4/Experts/Position Sizer/Defines.mqh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//+------------------------------------------------------------------+
//| Defines.mqh |
//| Copyright © 2023, EarnForex.com |
//| Copyright © 2024, EarnForex.com |
//| https://www.earnforex.com/ |
//+------------------------------------------------------------------+
#include <Controls\Button.mqh>
Expand All @@ -25,6 +25,10 @@ color DARKMODE_TEXT_COLOR = 0x000000;;

color CONTROLS_BUTTON_COLOR_TP_UNLOCKED, CONTROLS_BUTTON_COLOR_TP_LOCKED;

#define MULTIPLIER_VALUE_CONTROL 10
#define MULTIPLIER_VALUE_SHIFT 100
#define MULTIPLIER_VALUE_CONTROL_SHIFT 1000

enum ENTRY_TYPE
{
Instant,
Expand Down Expand Up @@ -99,6 +103,20 @@ enum CALCULATE_RISK_FOR_TRADING_TAB
CALCULATE_RISK_FOR_TRADING_TAB_PER_SYMBOL // For Trading tab - per symbol
};

enum ADDITIONAL_TP_SCHEME
{
ADDITIONAL_TP_SCHEME_INWARD, // The "<<" button has been clicked.
ADDITIONAL_TP_SCHEME_OUTWARD // The ">>" button has been clicked.
};

enum ADDITIONAL_TRADE_BUTTONS
{
ADDITIONAL_TRADE_BUTTONS_NONE, // None
ADDITIONAL_TRADE_BUTTONS_LINE, // Above the Entry line
ADDITIONAL_TRADE_BUTTONS_MAIN, // Main tab
ADDITIONAL_TRADE_BUTTONS_BOTH // Both
};

struct Settings
{
ENTRY_TYPE EntryType;
Expand Down Expand Up @@ -173,6 +191,7 @@ struct Settings
bool TPLockedOnSL;
VOLUME_SHARE_MODE ShareVolumeMode;
bool TemplateChanged;
ADDITIONAL_TP_SCHEME LastAdditionalTPScheme;
} sets;

// 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.
Expand Down
14 changes: 11 additions & 3 deletions MQL4/Experts/Position Sizer/Position Sizer Trading.mqh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//+------------------------------------------------------------------+
//| Position Sizer Trading.mqh |
//| Copyright © 2023, EarnForex.com |
//| Copyright © 2024, EarnForex.com |
//| https://www.earnforex.com/ |
//+------------------------------------------------------------------+
#include <stdlib.mqh>
Expand All @@ -18,7 +18,7 @@ void Trade()
return;
}

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


ENUM_ORDER_TYPE ot;
if (sets.EntryType == Pending)
Expand Down Expand Up @@ -303,6 +302,15 @@ void Trade()
}
}

if (sets.DoNotApplyStopLoss)
{
Print("'Do not apply stop-loss' checkbox is ticked.");
}
if (sets.DoNotApplyTakeProfit)
{
Print("'Do not apply take-profit' checkbox is ticked.");
}

// Use ArrayPositionSize that has already been calculated in CalculateRiskAndPositionSize().
// Check if they are OK.
for (int j = sets.TakeProfitsNumber - 1; j >= 0; j--)
Expand Down
30 changes: 26 additions & 4 deletions MQL4/Experts/Position Sizer/Position Sizer.mq4
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//+------------------------------------------------------------------+
//| Position Sizer.mq4 |
//| Copyright © 2023, EarnForex.com |
//| Copyright © 2024, EarnForex.com |
//| https://www.earnforex.com/ |
//+------------------------------------------------------------------+
#property copyright "EarnForex.com"
#property link "https://www.earnforex.com/metatrader-expert-advisors/Position-Sizer/"
#property icon "EF-Icon-64x64px.ico"
#property version "3.07"
string Version = "3.07";
#property version "3.08"
string Version = "3.08";
#property strict

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

CPositionSizeCalculator* ExtDialog;

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

// If a hotkey is given, break up the string to check for hotkey presses in OnChartEvent().
if (TradeHotKey != "") DissectHotKeyCombination(TradeHotKey, ShiftRequired_TradeHotKey, CtrlRequired_TradeHotKey, MainKey_TradeHotKey);
else MainKey_TradeHotKey = 0;
if (SwitchEntryDirectionHotKey != "") DissectHotKeyCombination(SwitchEntryDirectionHotKey, ShiftRequired_SwitchEntryDirectionHotKey, CtrlRequired_SwitchEntryDirectionHotKey, MainKey_SwitchEntryDirectionHotKey);
else MainKey_SwitchEntryDirectionHotKey = 0;
if (SwitchOrderTypeHotKey != "") DissectHotKeyCombination(SwitchOrderTypeHotKey, ShiftRequired_SwitchOrderTypeHotKey, CtrlRequired_SwitchOrderTypeHotKey, MainKey_SwitchOrderTypeHotKey);
else MainKey_SwitchOrderTypeHotKey = 0;
if (SwitchHideShowLinesHotKey != "") DissectHotKeyCombination(SwitchHideShowLinesHotKey, ShiftRequired_SwitchHideShowLinesHotKey, CtrlRequired_SwitchHideShowLinesHotKey, MainKey_SwitchHideShowLinesHotKey);
else MainKey_SwitchHideShowLinesHotKey = 0;
if (SetStopLossHotKey != "") DissectHotKeyCombination(SetStopLossHotKey, ShiftRequired_SetStopLossHotKey, CtrlRequired_SetStopLossHotKey, MainKey_SetStopLossHotKey);
else MainKey_SetStopLossHotKey = 0;
if (SetTakeProfitHotKey != "") DissectHotKeyCombination(SetTakeProfitHotKey, ShiftRequired_SetTakeProfitHotKey, CtrlRequired_SetTakeProfitHotKey, MainKey_SetTakeProfitHotKey);
else MainKey_SetTakeProfitHotKey = 0;
if (SetEntryHotKey != "") DissectHotKeyCombination(SetEntryHotKey, ShiftRequired_SetEntryHotKey, CtrlRequired_SetEntryHotKey, MainKey_SetEntryHotKey);
else MainKey_SetEntryHotKey = 0;
if (SwitchSLPointsLevelHotKey != "") DissectHotKeyCombination(SwitchSLPointsLevelHotKey, ShiftRequired_SwitchSLPointsLevelHotKey, CtrlRequired_SwitchSLPointsLevelHotKey, MainKey_SwitchSLPointsLevelHotKey);
else MainKey_SwitchSLPointsLevelHotKey = 0;
if (SwitchTPPointsLevelHotKey != "") DissectHotKeyCombination(SwitchTPPointsLevelHotKey, ShiftRequired_SwitchTPPointsLevelHotKey, CtrlRequired_SwitchTPPointsLevelHotKey, MainKey_SwitchTPPointsLevelHotKey);
else MainKey_SwitchTPPointsLevelHotKey = 0;
if (MinimizeMaximizeHotkey != "") DissectHotKeyCombination(MinimizeMaximizeHotkey, ShiftRequired_MinimizeMaximizeHotkey, CtrlRequired_MinimizeMaximizeHotkey, MainKey_MinimizeMaximizeHotkey);
else MainKey_MinimizeMaximizeHotkey = 0;
}
else if (OldSymbol != _Symbol)
{
Expand Down Expand Up @@ -542,6 +556,7 @@ void OnDeinit(const int reason)
ObjectsDeleteAll(0, ObjectPrefix + "TakeProfitLabel", -1, OBJ_LABEL);
ObjectsDeleteAll(0, ObjectPrefix + "TPAdditionalLabel", -1, OBJ_LABEL);
ObjectDelete(0, ObjectPrefix + "SLAdditionalLabel");
ObjectDelete(0, ObjectPrefix + "EntryAdditionalLabel");
ExtDialog.Destroy();
delete ExtDialog;
}
Expand Down Expand Up @@ -604,6 +619,13 @@ void OnChartEvent(const int id,
}
}

// This cannot be done using the panel's event handler because the outside trade button isn't added to its list of controls.
if ((id == CHARTEVENT_OBJECT_CLICK) && (sparam == ExtDialog.Name() + "m_OutsideTradeButton"))
{
ExtDialog.m_OutsideTradeButton.Pressed(false);
Trade();
}

if (id == CHARTEVENT_CLICK) // Avoid "sticking" of xxxLineIsBeingMoved variables.
{
StopLossLineIsBeingMoved = false;
Expand Down Expand Up @@ -812,7 +834,7 @@ void OnChartEvent(const int id,
{
if (sets.TP[i] != 0) // With zero points TP, keep the TP lines at zero level - as with the main TP level.
{
ExtDialog.AdditionalTPEdits[i - 1].Text(DoubleToString(MathRound((sets.TP[i] - sets.EntryLevel) / _Point), 0));
ExtDialog.AdditionalTPEdits[i - 1].Text(DoubleToString(MathAbs(MathRound((sets.TP[i] - sets.EntryLevel) / _Point)), 0));
}
}
}
Expand Down
Loading

0 comments on commit 903f700

Please sign in to comment.