Skip to content

Commit 090283e

Browse files
authored
1.21
Changed how the cBot reacts to a zero lot size value reported by the broker. It now uses a fallback value set via parameters.
1 parent d9755b9 commit 090283e

File tree

6 files changed

+26
-10
lines changed

6 files changed

+26
-10
lines changed

PositionSizer/PositionSizer/Model/Main/Model.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace cAlgo.Robots;
99

1010
public interface IModelResources
1111
{
12+
double InputFallbackLotSize { get; }
1213
bool InputCalculateUnadjustedPositionSize { get; }
1314
bool InputSurpassBrokerMaxPositionSizeWithMultipleTrades { get; }
1415
//--
@@ -29,6 +30,7 @@ public partial class Model : IModel
2930

3031
private IModelResources _resources;
3132

33+
private double InputFallbackLotSize => _resources.InputFallbackLotSize;
3234
private bool InputCalculateUnadjustedPositionSize => _resources.InputCalculateUnadjustedPositionSize;
3335
private bool InputSurpassBrokerMaxPositionSizeWithMultipleTrades => _resources.InputSurpassBrokerMaxPositionSizeWithMultipleTrades;
3436
private IAccount Account => _resources.Account;
@@ -257,7 +259,8 @@ public double StandardCommission()
257259

258260
if (Symbol.CommissionType == SymbolCommissionType.UsdPerMillionUsdVolume)
259261
{
260-
var lotSizeOfBaseAssetInAccountCurrency = baseAsset.Convert(accountAsset, Symbol.LotSize);
262+
var lotSize = Symbol.LotSize == 0 ? InputFallbackLotSize : Symbol.LotSize;
263+
var lotSizeOfBaseAssetInAccountCurrency = baseAsset.Convert(accountAsset, lotSize);
261264
var commissionPerLotInAccountCurrency = Symbol.Commission / 1_000_000.0 * lotSizeOfBaseAssetInAccountCurrency;
262265

263266
return commissionPerLotInAccountCurrency;

PositionSizer/PositionSizer/Model/TradeSizeMethods.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Linq;
23
using cAlgo.API;
34
using cAlgo.API.Internals;
@@ -124,6 +125,8 @@ private double CommissionPerUnitVolume()
124125
{
125126
// round-trip commission per unit volume in account currency
126127
// uses StandardCommission() per lot, then divides by lot size and doubles (entry + exit)
127-
return 2.0 * StandardCommission() / Symbol.LotSize;
128+
return Symbol.LotSize == 0
129+
? 2.0 * StandardCommission() / InputFallbackLotSize
130+
: 2.0 * StandardCommission() / Symbol.LotSize;
128131
}
129132
}

PositionSizer/PositionSizer/Parameters.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,9 @@ public partial class PositionSizer
492492

493493
[Parameter("Keep Lines When Robot Is Stopped", DefaultValue = false, Group = "Miscellaneous")]
494494
public bool InputKeepLinesWhenRobotIsStopped { get; set; }
495+
496+
[Parameter("Fallback Lot Size", DefaultValue = 1, MinValue = 0.01, Step = 0.01, Group = "Miscellaneous")]
497+
public double InputFallbackLotSize { get; set; }
495498

496499
#endregion
497500

PositionSizer/PositionSizer/PositionSizer.cs

Lines changed: 3 additions & 4 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.20
7+
// Version 1.21
88
// Copyright 2024-2025, EarnForex.com
99
// https://www.earnforex.com/ctrader-robots/cTrader-Position-Sizer/
1010
// -------------------------------------------------------------------------------
@@ -34,7 +34,7 @@ public partial class PositionSizer : Robot,
3434
public event EventHandler TimerEvent;
3535
public event EventHandler StopEvent;
3636
public IModel Model { get; set; }
37-
public const string Version = "v1.20";
37+
public const string Version = "v1.21";
3838
public CustomStyle CustomStyle { get; private set; }
3939
public BreakEven BreakEven { get; private set; }
4040
public TrailingStop TrailingStop { get; private set; }
@@ -58,9 +58,8 @@ protected override void OnStart()
5858
{
5959
if (Symbol.LotSize == 0)
6060
{
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.";
61+
var msgText = $"This symbol reports zero lot size. Using the Fallback Lot Size value {InputFallbackLotSize}. Commission and swap calculation may be incorrect.";
6262
MessageBox.Show(msgText, "Warning!", MessageBoxButton.OK, MessageBoxImage.Warning);
63-
Stop();
6463
}
6564

6665
//System.Diagnostics.Debugger.Launch();

PositionSizer/PositionSizer/View/Pages/SwapsView.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public interface ISwapsViewResources
1111
IAccount Account { get; }
1212
CustomStyle CustomStyle { get; }
1313
bool InputDarkMode { get; }
14+
double InputFallbackLotSize { get; }
1415
}
1516

1617
public class SwapsView : Button, ISwapsViewResources
@@ -32,6 +33,10 @@ public SwapsView(ISwapsViewResources resources)
3233
_grid.AddRows(9);
3334
Content = _grid;
3435
Width = 400;
36+
37+
var lotSizeValue = Symbol.LotSize == 0
38+
? InputFallbackLotSize
39+
: Symbol.LotSize;
3540

3641
var row = 0;
3742

@@ -87,11 +92,11 @@ public SwapsView(ISwapsViewResources resources)
8792

8893
_grid.AddChild(dailyTextBlock, row, 0);
8994

90-
var longDailyTextBox = MakeTextBox((Symbol.SwapLong * Symbol.PipValue * Symbol.LotSize).ToString("F"));
95+
var longDailyTextBox = MakeTextBox((Symbol.SwapLong * Symbol.PipValue * lotSizeValue).ToString("F"));
9196

9297
_grid.AddChild(longDailyTextBox, row, 1);
9398

94-
var shortDailyTextBox = MakeTextBox((Symbol.SwapShort * Symbol.PipValue * Symbol.LotSize).ToString("F"));
99+
var shortDailyTextBox = MakeTextBox((Symbol.SwapShort * Symbol.PipValue * lotSizeValue).ToString("F"));
95100

96101
_grid.AddChild(shortDailyTextBox, row, 2);
97102

@@ -120,11 +125,11 @@ public SwapsView(ISwapsViewResources resources)
120125

121126
_grid.AddChild(yearlyTextBlock, row, 0);
122127

123-
var longYearlyTextBox = MakeTextBox($"{Symbol.SwapLong * Symbol.PipValue * Symbol.LotSize * 360:F2}");
128+
var longYearlyTextBox = MakeTextBox($"{Symbol.SwapLong * Symbol.PipValue * lotSizeValue * 360:F2}");
124129

125130
_grid.AddChild(longYearlyTextBox, row, 1);
126131

127-
var shortYearlyTextBox = MakeTextBox($"{Symbol.SwapShort * Symbol.PipValue * Symbol.LotSize * 360:F2}");
132+
var shortYearlyTextBox = MakeTextBox($"{Symbol.SwapShort * Symbol.PipValue * lotSizeValue * 360:F2}");
128133

129134
_grid.AddChild(shortYearlyTextBox, row, 2);
130135

@@ -248,4 +253,5 @@ private XTextBoxDouble MakeTextBox(double value)
248253
public IAccount Account => _resources.Account;
249254
public CustomStyle CustomStyle => _resources.CustomStyle;
250255
public bool InputDarkMode => _resources.InputDarkMode;
256+
public double InputFallbackLotSize => _resources.InputFallbackLotSize;
251257
}

PositionSizer/PositionSizer/View/SetupWindowView.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public interface ISetupWindowResources
7979
Color InputLongButtonColor { get; }
8080
Color InputShortButtonColor { get; }
8181
Color InputTradeButtonColor { get; }
82+
double InputFallbackLotSize { get; }
8283
}
8384

8485
public enum WindowActive
@@ -696,6 +697,7 @@ public void Stop()
696697

697698
public LocalStorage LocalStorage => _resources.LocalStorage;
698699
public string CleanBrokerName => _resources.CleanBrokerName;
700+
public double InputFallbackLotSize => _resources.InputFallbackLotSize;
699701

700702
private void OnHideShowClickEvent()
701703
{

0 commit comments

Comments
 (0)