Skip to content

Commit c203da4

Browse files
author
EarnForex
authored
2.41
1. Added an input parameter StartPanelMinimized. 2. Added ATRCandle input parameter. 3. Fixed a compatibility bug with other panels. 4. Fixed a bug in portfolio risk calculation. 5. Fixed a bug that caused very large values in extra TP edit fields. 6. Fixed a minor glitch with extra TP lines. 7. Fixed a bug that caused the PSC-Trader script (version 1.14) to open a trade without stop-loss. 8. Fixed a bug in the PSC-Trader script that caused opening trades with random volume. 9. Renamed input parameters UseFixedSLDistance and UseFixedTPDistance to SLDistanceInPoints and TPDistanceInPoints.
1 parent 3bf4263 commit c203da4

File tree

8 files changed

+206
-125
lines changed

8 files changed

+206
-125
lines changed

MQL4/Indicators/PositionSizeCalculator/Defines.mqh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ enum ACCOUNT_BUTTON
2525
{
2626
Balance,
2727
Equity,
28-
Balance_minus_Risk
28+
Balance_minus_Risk // Balance - Risk
2929
};
3030

3131
enum TABS
@@ -49,6 +49,12 @@ enum PROFIT_LOSS
4949
Loss
5050
};
5151

52+
enum CANDLE_NUMBER
53+
{
54+
Current_Candle = 0, // Current candle
55+
Previous_Candle = 1 // Previous candle
56+
};
57+
5258
struct Settings
5359
{
5460
ENTRY_TYPE EntryType;

MQL4/Indicators/PositionSizeCalculator/PositionSizeCalculator.mq4

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
//+------------------------------------------------------------------+
77
#property copyright "EarnForex.com"
88
#property link "https://www.earnforex.com/metatrader-indicators/Position-Size-Calculator/"
9-
#property version "2.40"
10-
string Version = "2.40";
9+
#property version "2.41"
10+
string Version = "2.41";
1111
#property strict
1212
#property indicator_chart_window
1313
#property indicator_plots 0
@@ -22,12 +22,6 @@ string Version = "2.40";
2222

2323
#include "PositionSizeCalculator.mqh";
2424

25-
// Default values for settings:
26-
double EntryLevel = 0;
27-
double StopLossLevel = 0;
28-
double TakeProfitLevel = 0;
29-
string PanelCaption = "";
30-
3125
input group "Compactness"
3226
input bool ShowLineLabels = true; // ShowLineLabels: Show pip distance for TP/SL near lines?
3327
input bool ShowAdditionalSLLabel = false; // ShowAdditionalSLLabel: Show SL $/% label?
@@ -37,6 +31,7 @@ input bool PanelOnTopOfChart = true; // PanelOnTopOfChart: Draw chart as backgro
3731
input bool HideAccSize = false; // HideAccSize: Hide account size?
3832
input bool ShowPipValue = false; // ShowPipValue: Show pip value?
3933
input bool ShowMaxPSButton = false; // ShowMaxPSButton: Show Max Position Size button?
34+
input bool StartPanelMinimized = false; // StartPanelMinimized: Start the panel minimized?
4035
input group "Fonts"
4136
input color sl_label_font_color = clrLime; // SL Label Color
4237
input color tp_label_font_color = clrYellow; // TP Label Font Color
@@ -94,9 +89,10 @@ input bool UseCommissionToSetTPDistance = false; // UseCommissionToSetTPDistance
9489
input bool ShowSpread = false; // ShowSpread: If true, shows current spread in window caption.
9590
input double AdditionalFunds = 0; // AdditionalFunds: Added to account balance for risk calculation.
9691
input double CustomBalance = 0; // CustomBalance: Overrides AdditionalFunds value.
97-
input bool UseFixedSLDistance = false; // UseFixedSLDistance: SL distance in points instead of a level.
98-
input bool UseFixedTPDistance = false; // UseFixedTPDistance: TP distance in points instead of a level.
92+
input bool SLDistanceInPoints = false; // SLDistanceInPoints: SL distance in points instead of a level.
93+
input bool TPDistanceInPoints = false; // TPDistanceInPoints: TP distance in points instead of a level.
9994
input bool ShowATROptions = false; // ShowATROptions: If true, SL and TP can be set via ATR.
95+
input CANDLE_NUMBER ATRCandle = Current_Candle; // ATRCandle: Candle to get ATR value from.
10096
input int ScriptTakePorfitsNumber = 1; // ScriptTakePorfitsNumber: More than 1 target for script to split trades.
10197
input bool CalculateUnadjustedPositionSize = false; // CalculateUnadjustedPositionSize: Ignore broker's restrictions.
10298
input bool RoundDown = true; // RoundDown: Position size and potential reward are rounded down.
@@ -115,10 +111,12 @@ uint LastRecalculationTime = 0;
115111
//+------------------------------------------------------------------+
116112
int OnInit()
117113
{
114+
MathSrand(GetTickCount() + 293029); // Used by CreateInstanceId() in Dialog.mqh (standard library). Keep the second number unique across other panel indicators/EAs.
115+
118116
string indicator_short_name = "Position Size Calculator" + IntegerToString(ChartID());
119117
Dont_Move_the_Panel_to_Default_Corner_X_Y = true;
120118

121-
// Prevent attachment of second panel if it is not a timeframe/parameters change.
119+
// Prevent attachment of second panel if it is not a timeframe/parameters change.
122120
if (GlobalVariableGet("PSC-" + IntegerToString(ChartID()) + "-Flag") > 0)
123121
{
124122
GlobalVariableDel("PSC-" + IntegerToString(ChartID()) + "-Flag");
@@ -207,22 +205,22 @@ int OnInit()
207205

208206
if (!ExtDialog.Create(0, PanelCaption, 0, DefaultPanelPositionX, DefaultPanelPositionY)) return INIT_FAILED;
209207

210-
// Prevent problems with trading instruments containing more than one dot in their name.
211-
// Also, bypasses a bug in Dialog.mqh with indicator name detection.
208+
// Prevent problems with trading instruments containing more than one dot in their name.
209+
// Also, bypasses a bug in Dialog.mqh with indicator name detection.
212210
string symbol = Symbol();
213211
StringReplace(symbol, ".", "_dot_");
214212
string filename = indicator_short_name + "_" + symbol + "_Ini" + ExtDialog.IniFileExt();
215213
ExtDialog.IniFileNameSet(filename);
216214

217-
// No ini file - move the panel according to the inputs.
215+
// No ini file - move the panel according to the inputs.
218216
if (!FileIsExist(filename)) Dont_Move_the_Panel_to_Default_Corner_X_Y = false;
219217

220218
ExtDialog.IniFileLoad();
221219
ExtDialog.Run();
222220

223221
Initialization();
224222

225-
// Brings panel on top of other objects without actual maximization of the panel.
223+
// Brings panel on top of other objects without actual maximization of the panel.
226224
ExtDialog.HideShowMaximize();
227225

228226
if (!Dont_Move_the_Panel_to_Default_Corner_X_Y)
@@ -253,6 +251,19 @@ int OnInit()
253251
ExtDialog.FixatePanelPosition(); // Remember the panel's new position for the INI file.
254252
}
255253

254+
if ((StartPanelMinimized) && (!ExtDialog.IsMinimized()) && (!Dont_Move_the_Panel_to_Default_Corner_X_Y)) // Minimize only if needs minimization. We check Dont_Move_the_Panel_to_Default_Corner_X_Y to make sure we didn't load an INI-file. An INI-file already contains a more preferred state for the panel.
255+
{
256+
// No access to the minmax button, no way to edit the chart height.
257+
// Dummy variables for passing as references.
258+
long lparam = 0;
259+
double dparam = 0;
260+
string sparam = "";
261+
// Increasing the height of the panel beyond that of the chart will trigger its minimization.
262+
ExtDialog.Height((int)ChartGetInteger(ChartID(), CHART_HEIGHT_IN_PIXELS) + 1);
263+
// Call the chart event processing function.
264+
ExtDialog.ChartEvent(CHARTEVENT_CHART_CHANGE, lparam, dparam, sparam);
265+
}
266+
256267
EventSetTimer(1);
257268

258269
return INIT_SUCCEEDED;
@@ -322,14 +333,14 @@ void OnChartEvent(const int id,
322333
const double &dparam,
323334
const string &sparam)
324335
{
325-
// Remember the panel's location to have the same location for minimized and maximized states.
336+
// Remember the panel's location to have the same location for minimized and maximized states.
326337
if ((id == CHARTEVENT_CUSTOM + ON_DRAG_END) && (lparam == -1))
327338
{
328339
ExtDialog.remember_top = ExtDialog.Top();
329340
ExtDialog.remember_left = ExtDialog.Left();
330341
}
331342

332-
// Catch multiple TP fields.
343+
// Catch multiple TP fields.
333344
if (ScriptTakePorfitsNumber > 1)
334345
{
335346
if (id == CHARTEVENT_CUSTOM + ON_END_EDIT)
@@ -355,19 +366,19 @@ void OnChartEvent(const int id,
355366
}
356367
}
357368

358-
// Call Panel's event handler only if it is not a CHARTEVENT_CHART_CHANGE - workaround for minimization bug on chart switch.
369+
// Call Panel's event handler only if it is not a CHARTEVENT_CHART_CHANGE - workaround for minimization bug on chart switch.
359370
if (id != CHARTEVENT_CHART_CHANGE) ExtDialog.OnEvent(id, lparam, dparam, sparam);
360-
361-
// Recalculate on chart changes, clicks, and certain object dragging.
371+
372+
// Recalculate on chart changes, clicks, and certain object dragging.
362373
if ((id == CHARTEVENT_CLICK) || (id == CHARTEVENT_CHART_CHANGE) ||
363374
((id == CHARTEVENT_OBJECT_DRAG) && ((sparam == ObjectPrefix + "EntryLine") || (sparam == ObjectPrefix + "StopLossLine") || (StringFind(sparam, ObjectPrefix + "TakeProfitLine") != -1))))
364375
{
365376
// Moving lines when fixed SL/TP distance is enabled. Should set a new fixed SL/TP distance.
366-
if ((id == CHARTEVENT_OBJECT_DRAG) && ((UseFixedSLDistance) || (UseFixedTPDistance) || (ShowATROptions)))
377+
if ((id == CHARTEVENT_OBJECT_DRAG) && ((SLDistanceInPoints) || (TPDistanceInPoints) || (ShowATROptions)))
367378
{
368379
if (sparam == ObjectPrefix + "StopLossLine") ExtDialog.UpdateFixedSL();
369380
else if (sparam == ObjectPrefix + "TakeProfitLine") ExtDialog.UpdateFixedTP();
370-
else if (StringFind(sparam, ObjectPrefix + "TakeProfitLine") != -1)
381+
else if ((ScriptTakePorfitsNumber > 1) && (StringFind(sparam, ObjectPrefix + "TakeProfitLine") != -1))
371382
{
372383
int len = StringLen(ObjectPrefix + "TakeProfitLine");
373384
int i = (int)StringToInteger(StringSubstr(sparam, len));

0 commit comments

Comments
 (0)