Skip to content

Commit edeb6a7

Browse files
authored
1.20
1. Added an input parameter to avoid deleting the Position Sizer's lines when the robot is removed. 2. Fixed a bug with wrong currency shown in additional line labels. 3. Fixed a crash when broker reports in correct lot size value. 4. Fixed a crash when the trading symbol's name contains special characters. 5. Renamed Show Line Labels input parameter to Show Main Line Labels.
1 parent 6d4c26b commit edeb6a7

File tree

8 files changed

+142
-71
lines changed

8 files changed

+142
-71
lines changed

PositionSizer/PositionSizer/Model/TradeSize.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class TradeSize
1919
public double Volume => Symbol.QuantityToVolumeInUnits(Lots);
2020
public double RiskPercentage { get; set; }
2121
public double RiskPercentageResult { get; set; }
22+
public double RewardPercentageResult => RiskPercentageResult * RewardRiskRatioResult;
2223
public double RiskInCurrency { get; set; }
2324
public double RewardRiskRatio { get; set; }
2425
public double RiskInCurrencyResult { get; set; }

PositionSizer/PositionSizer/Parameters.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ public partial class PositionSizer
99
/// <summary>
1010
/// Show pip distance for TP/SL near lines
1111
/// </summary>
12-
[Parameter("Show Line Labels", DefaultValue = true, Group = "Compactness", Description = "Show pip distance for TP/SL near lines")]
13-
public bool InputShowLineLabels { get; set; }
12+
[Parameter("Show Main Line Labels", DefaultValue = true, Group = "Compactness", Description = "Show pip distance for TP/SL near lines")]
13+
public bool InputShowMainLineLabels { get; set; }
1414

1515
/// <summary>
1616
/// Show SL $/% label
@@ -490,6 +490,9 @@ public partial class PositionSizer
490490
[Parameter("Chart Trade Button Offset From The Right", DefaultValue = 50, Group = "Miscellaneous")]
491491
public int InputTradeButtonOffsetFromTheRight { get; set; }
492492

493+
[Parameter("Keep Lines When Robot Is Stopped", DefaultValue = false, Group = "Miscellaneous")]
494+
public bool InputKeepLinesWhenRobotIsStopped { get; set; }
495+
493496
#endregion
494497

495498
//[Parameter("Refresh (ms)", DefaultValue = 20)]

PositionSizer/PositionSizer/PositionSizer.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// WARNING: No warranty. This EA is offered "as is". Use at your own risk.
55
// Note: Pressing Shift+T will open a trade.
66
//
7-
// Version 1.19.
7+
// Version 1.20
88
// Copyright 2024-2025, EarnForex.com
99
// https://www.earnforex.com/ctrader-robots/cTrader-Position-Sizer/
1010
// -------------------------------------------------------------------------------
@@ -15,7 +15,6 @@
1515
using System.Text;
1616
using System.Text.RegularExpressions;
1717
using cAlgo.API;
18-
using cAlgo.API.Internals;
1918
using cAlgo.Robots.RiskManagers;
2019
using cAlgo.Robots.Tools;
2120
using PositionSizer.XTextBoxControl.ByTypes;
@@ -35,7 +34,7 @@ public partial class PositionSizer : Robot,
3534
public event EventHandler TimerEvent;
3635
public event EventHandler StopEvent;
3736
public IModel Model { get; set; }
38-
public const string Version = "v1.19";
37+
public const string Version = "v1.20";
3938
public CustomStyle CustomStyle { get; private set; }
4039
public BreakEven BreakEven { get; private set; }
4140
public TrailingStop TrailingStop { get; private set; }
@@ -57,6 +56,13 @@ public partial class PositionSizer : Robot,
5756

5857
protected override void OnStart()
5958
{
59+
if (Symbol.LotSize == 0)
60+
{
61+
var msgText = "This symbol reports a lot size of zero, which prevents the bot from operating correctly. Please select a symbol with a non-zero lot size or update the symbol's contract size and restart the bot.";
62+
MessageBox.Show(msgText, "Warning!", MessageBoxButton.OK, MessageBoxImage.Warning);
63+
Stop();
64+
}
65+
6066
//System.Diagnostics.Debugger.Launch();
6167

6268
// IndexForLabelReference = RunningMode == RunningMode.VisualBacktesting
@@ -345,8 +351,12 @@ public static string CleanName(string fileName)
345351
if (string.IsNullOrWhiteSpace(fileName))
346352
return string.Empty;
347353

348-
// Allow only letters (A-Z, a-z) and numbers (0-9)
349-
return Regex.Replace(fileName, "[^a-zA-Z0-9]", "").Replace(" ", "");
354+
// Allow only Latin letters (A-Z, a-z), numbers (0-9), and spaces
355+
// Remove all other characters (like &, @, etc.)
356+
var cleaned = Regex.Replace(fileName, "[^a-zA-Z0-9 ]", "").Replace(" ", "");;
357+
358+
// Trim leading and trailing spaces (LocalStorage requirement)
359+
return cleaned.Trim();
350360
}
351361

352362
private void SetAtrSettings(bool canImplementModel, IModel storageModel)

PositionSizer/PositionSizer/Presenter.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public partial class PositionSizer
1515

1616
public void StartPresenter()
1717
{
18+
SetupWindowView.ChartLinesView.RemoveLines();
1819
SetupWindowView.WindowActiveChanged += SetupWindowViewOnWindowActiveChanged;
1920

2021
#region MainViewSubscriptions
@@ -411,7 +412,16 @@ private void SymbolOnTick(SymbolTickEventArgs obj)
411412

412413
private void OnStopEvent(object sender, EventArgs e)
413414
{
414-
SetupWindowView.ChartLinesView.RemoveLines();
415+
if (!InputKeepLinesWhenRobotIsStopped)
416+
SetupWindowView.ChartLinesView.RemoveLines();
417+
else
418+
{
419+
foreach (var line in SetupWindowView.ChartLinesView.HorizontalLines)
420+
{
421+
line.IsInteractive = true;
422+
line.IsHidden = false;
423+
}
424+
}
415425
}
416426

417427
private void SetupWindowViewOnWindowActiveChanged(object sender, WindowActiveChangedEventArgs e)

0 commit comments

Comments
 (0)