Bug report: Swaps do not work on indices in latest cTrader version V4.8.15
Bug report: Swaps do not work on indices in latest cTrader version V4.8.15
16 Jul 2023, 15:42
Finally we have swaps calculation in backtests - halleluja!
While it works fine on Forex symbols, unfortunatelly, it still does not work on Indices like GER40 , etc.
When will this be fixed?
Replies
heinrich.munz
17 Jul 2023, 11:31
RE:
Spotware said:
Dear trader,
Thank you for reporting this issue. Can you please share the code you used to reproduce this problem?
Best regards,
cTrader Team
using cAlgo.API;
using cAlgo.API.Internals;
using System;
using System.Diagnostics;
using System.Linq;
namespace cAlgo.Robots
{
[Robot(AccessRights = AccessRights.FullAccess)]
public class Empty : Robot
{
DateTime mStartDt;
protected override void OnStart()
{
//Debugger.Launch();
mStartDt = Time;
}
protected override void OnTick()
{
if (0 == Positions.Count)
{
var investMoney = 10000;
var lotSize = Symbol.VolumeInUnitsToQuantity(investMoney * Symbol.TickSize / Symbol.TickValue / Symbol.Bid);
var volume = Symbol.NormalizeVolumeInUnits(Symbol.QuantityToVolumeInUnits(lotSize));
ExecuteMarketOrder(TradeType.Buy, SymbolName, volume);
}
else if (Time - Positions.Last().EntryTime > TimeSpan.FromDays(20))
Positions.Last().Close();
}
protected override void OnStop()
{
Print("Symbol: "+ Symbol.Name + " started on " + mStartDt.ToString());
Print("SwapLong: " + Symbol.SwapLong.ToString());
Print("SwapShort: " + Symbol.SwapShort.ToString());
foreach (var hist in History)
{
Print("Trade# " + hist.PositionId + ", Swap sum: " + hist.Swap.ToString());
}
}
}
}
Output for EURUSD which is ok:
14/07/2023 22:54:00.000 | CBot instance [Empty, EURUSD, h1] stopped.
14/07/2023 22:54:00.000 | Trade# 5, Swap sum: -13,65
14/07/2023 22:54:00.000 | Trade# 4, Swap sum: -13,65
14/07/2023 22:54:00.000 | Trade# 3, Swap sum: -13,65
14/07/2023 22:54:00.000 | Trade# 2, Swap sum: -13,65
14/07/2023 22:54:00.000 | Trade# 1, Swap sum: -13,65
14/07/2023 22:54:00.000 | SwapShort: 0,29
14/07/2023 22:54:00.000 | SwapLong: -0,73
14/07/2023 22:54:00.000 | Symbol: EURUSD started on 13.03.2023 00:00:00
13/03/2023 02:00:00.000 | CBot instance [Empty, EURUSD, h1] started.
Output for US500 which is NOT ok:
14/07/2023 22:54:00.000 | CBot instance [Empty, US500, h1] stopped.
14/07/2023 22:54:00.000 | Trade# 5, Swap sum: 0
14/07/2023 22:54:00.000 | Trade# 4, Swap sum: 0
14/07/2023 22:54:00.000 | Trade# 3, Swap sum: 0
14/07/2023 22:54:00.000 | Trade# 2, Swap sum: 0
14/07/2023 22:54:00.000 | Trade# 1, Swap sum: 0
14/07/2023 22:54:00.000 | SwapShort: 2,55
14/07/2023 22:54:00.000 | SwapLong: -7,55
14/07/2023 22:54:00.000 | Symbol: US500 started on 13.03.2023 00:00:00
13/03/2023 02:00:00.000 | CBot instance [Empty, US500, h1] started.
@heinrich.munz
heinrich.munz
17 Jul 2023, 11:59
RE:
Spotware said:
Dear trader,
Can you please let us know the broker as well?
Best regards,
cTrader Team
Good Question!
After your question I tried Pepperstone International, Pepperstone Europe and IC Markets.
The bug occurs ONLY on the Pepperstone accounts!
@heinrich.munz
ncel01
17 Jul 2023, 12:06
( Updated at: 17 Jul 2023, 12:33 )
Yes, I can confirm that swaps have not been included for indices when backtesting.
Unfortunately, this is just another example where, unlike forex, indices have been overlooked.
@Spotware
Why do you need the cBot code here?
Just run a backtest with any indice and you will get to the same conclusion. As simple as that.
@ncel01
Spotware
17 Jul 2023, 09:49
Dear trader,
Thank you for reporting this issue. Can you please share the code you used to reproduce this problem?
Best regards,
cTrader Team
@Spotware