Skip to content

Commit

Permalink
3.05
Browse files Browse the repository at this point in the history
1. Added a new input parameter (PrefillAdditionalTPsBasedOnMain) to control whether newly added TPs are pre-filled or not.
2. Added a file with Portuguese (Brazilian) translation (contributed by Matheus Sevaroli) for the MT5 version of the expert advisor.
3. Fixed the Reward calculation display when some of the additional take-profit levels are zero. It will now calculate reward only for those trades that have a non-zero TP.
4. Fixed a bug with position size restriction and subtraction settings not actually working.
5. Fixed a bug that caused the SymbolChange = Reset to Defaults to not work for most fields.
6. Fixed a bug that prevented normal updating of entry and TP levels when lines were hidden.
7. Fixed a bug in MT4 version that could sometimes cause an 'array out of range' error.
  • Loading branch information
EarnForex authored Jul 25, 2023
1 parent e23e2f2 commit 87872f5
Show file tree
Hide file tree
Showing 10 changed files with 694 additions and 362 deletions.
10 changes: 7 additions & 3 deletions MQL4/Experts/Position Sizer/Position Sizer Trading.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,18 @@ void Trade()
if ((ot == OP_BUY) || (ot == OP_BUYLIMIT) || (ot == OP_BUYSTOP)) PositionSize -= existing_volume_buy;
else PositionSize -= existing_volume_sell;
Print("Adjusted position size = ", DoubleToString(PositionSize, LotStep_digits));
if (PositionSize < 0)
if (PositionSize <= 0)
{
Alert("Adjusted position size is less than zero. Not executing any trade.");
Alert("Adjusted position size is less or equal to zero. Not executing any trade.");
return;
}
if (PositionSize != OutputPositionSize) // If changed, recalculate the array of position sizes.
{
PositionSizeToArray(PositionSize); // Re-fills ArrayPositionSize[].
}
}

if ((sets.MaxPositionSizeTotal > 0) && (sets.MaxPositionSizePerSymbol > 0))
if ((sets.MaxPositionSizeTotal > 0) || (sets.MaxPositionSizePerSymbol > 0))
{
int total = OrdersTotal();
double volume = 0, volume_persymbol = 0;
Expand Down
10 changes: 8 additions & 2 deletions MQL4/Experts/Position Sizer/Position Sizer.mq4
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#property copyright "EarnForex.com"
#property link "https://www.earnforex.com/metatrader-expert-advisors/Position-Sizer/"
#property icon "EF-Icon-64x64px.ico"
#property version "3.04"
string Version = "3.04";
#property version "3.05"
string Version = "3.05";
#property strict

#property description "Calculates risk-based position size for your account."
Expand Down Expand Up @@ -134,6 +134,7 @@ input bool IgnoreMarketExecutionMode = true; // IgnoreMarketExecutionMode: If tr
input bool MarketModeApplySLTPAfterAllTradesExecuted = false; // Market Mode - Apply SL/TP After All Trades Executed
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?

CPositionSizeCalculator* ExtDialog;

Expand Down Expand Up @@ -214,6 +215,7 @@ int OnInit()
else LinesSelectedStatus = 2; // Flip lines to unselected.
}
}
bool is_InitControlsValues_required = false;
// Normal attempt to load settings fails (attempted in not chart change case and in chart case with 'each pair own settings' case
if ((((DeinitializationReason != REASON_CHARTCHANGE) || ((DeinitializationReason == REASON_CHARTCHANGE) && (OldSymbol != _Symbol) && (SymbolChange == SYMBOL_CHART_CHANGE_EACH_OWN))) && (!ExtDialog.LoadSettingsFromDisk()))
// OR chart change with hard_reset configured and with symbol change.
Expand Down Expand Up @@ -300,6 +302,7 @@ int OnInit()
if ((sets.MaxRiskTotal < sets.MaxRiskPerSymbol) && (sets.MaxRiskTotal != 0)) sets.MaxRiskTotal = sets.MaxRiskPerSymbol;
sets.ShareVolumeMode = Decreasing;
sets.TemplateChanged = false;
if (DeinitializationReason == REASON_CHARTCHANGE) is_InitControlsValues_required = true;
}
if (sets.TakeProfitsNumber < 1) sets.TakeProfitsNumber = 1; // At least one TP.
if (DeinitializationReason != REASON_CHARTCHANGE)
Expand Down Expand Up @@ -463,6 +466,9 @@ int OnInit()
}
}
}

// If symbol change with a reset was enacted.
if (is_InitControlsValues_required) ExtDialog.InitControlsValues();

return INIT_SUCCEEDED;
}
Expand Down
346 changes: 177 additions & 169 deletions MQL4/Experts/Position Sizer/Position Sizer.mqh

Large diffs are not rendered by default.

Binary file modified MQL5/Experts/Position Sizer/Position Sizer Trading.mqh
Binary file not shown.
11 changes: 9 additions & 2 deletions MQL5/Experts/Position Sizer/Position Sizer.mq5
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
#property copyright "EarnForex.com"
#property link "https://www.earnforex.com/metatrader-expert-advisors/Position-Sizer/"
#property icon "EF-Icon-64x64px.ico"
#property version "3.04"
string Version = "3.04";
#property version "3.05"
string Version = "3.05";

#include "Translations\English.mqh"
//#include "Translations\Ukrainian.mqh"
//#include "Translations\Russian.mqh"
//#include "Translations\Portuguese.mqh" // Contributed by Matheus Sevaroli.

#property description "Calculates risk-based position size for your account."
#property description "Allows trade execution based the calculation results.\r\n"
Expand Down Expand Up @@ -146,6 +147,7 @@ input bool IgnoreMarketExecutionMode = true; // IgnoreMarketExecutionMode: If tr
input bool MarketModeApplySLTPAfterAllTradesExecuted = false; // Market Mode - Apply SL/TP After All Trades Executed
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?

CPositionSizeCalculator* ExtDialog;

Expand Down Expand Up @@ -222,6 +224,7 @@ int OnInit()
}
}

bool is_InitControlsValues_required = false;
// Normal attempt to load settings fails (attempted in not chart change case and in chart case with 'each pair own settings' case
if ((((DeinitializationReason != REASON_CHARTCHANGE) || ((DeinitializationReason == REASON_CHARTCHANGE) && (OldSymbol != _Symbol) && (SymbolChange == SYMBOL_CHART_CHANGE_EACH_OWN))) && (!ExtDialog.LoadSettingsFromDisk()))
// OR chart change with hard_reset configured and with symbol change.
Expand Down Expand Up @@ -311,6 +314,7 @@ int OnInit()
// Because it is the first load:
Dont_Move_the_Panel_to_Default_Corner_X_Y = false;
sets.ShareVolumeMode = Decreasing;
if (DeinitializationReason == REASON_CHARTCHANGE) is_InitControlsValues_required = true;
}
if (sets.TakeProfitsNumber < 1) sets.TakeProfitsNumber = 1; // At least one TP.

Expand Down Expand Up @@ -483,6 +487,9 @@ int OnInit()
}
}

// If symbol change with a reset was enacted.
if (is_InitControlsValues_required) ExtDialog.InitControlsValues();

return INIT_SUCCEEDED;
}

Expand Down
Loading

0 comments on commit 87872f5

Please sign in to comment.