huge error on calculation swap between visual mode an non visual mode version 4.8.21

Created at 21 Aug 2023, 09:14
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
G.

G.A.F

Joined 04.08.2022

huge error on calculation swap between visual mode an non visual mode version 4.8.21
21 Aug 2023, 09:14


 

 

Dear cTrader team,

During the backtesting of a cBot, I have noticed a significant difference between visual backtesting and silent backtesting. The difference concerns the calculation of the swap. As you can see in the visual version, in the historical data, the swap is not calculated, whereas in the non-visual version, it is. This creates a quite evident discrepancy in net profit and in the strategy decision when using the visual mode. Additionally, after downloading version 4.1 and adapting the code to the net.4.x version, I encountered the following errors:

Error: Unknown Guid format.
Error : No algo source file was found in "Remora Ultima 2023.csproj".

How should I proceed? What solutions do you have? Thank you for your assistance.

as you can see it has passed 12 days and 0 swap in visual mode

 

in not visual mode, it calculate the swap 

visual mode up

 not visual mode down, 

 


@G.A.F
Replies

Spotware
29 Aug 2023, 05:44

Dear trader,

Can you please update your cTrader to 4.8.23 and let us know if you still experience this problem?

Best regards,

cTrader Team


@Spotware

G.A.F
01 Sep 2023, 08:42

RE: huge error on calculation swap between visual mode an non visual mode version 4.8.21

Spotware said: 

Dear trader,

Can you please update your cTrader to 4.8.23 and let us know if you still experience this problem?

Best regards,

cTrader Team

Right now, I see everything working fine, thank you very much.


@G.A.F

G.A.F
29 Sep 2023, 21:52 ( Updated at: 21 Dec 2023, 09:23 )

RE: huge error on calculation swap between visual mode an non visual mode version 4.8.21

Spotware said: 

Dear trader,

Can you please update your cTrader to 4.8.23 and let us know if you still experience this problem?

Best regards,

cTrader Team

"Guys, unfortunately, a serious error keeps occurring. During the backtest, the net profit calculation is incorrect, as you can see from the image, the net profit is completely wrong when looking at the open positions. What should I do to avoid this error?"

 


@G.A.F

G.A.F
29 Sep 2023, 22:04 ( Updated at: 21 Dec 2023, 09:23 )

RE: huge error on calculation swap between visual mode an non visual mode version 4.8.21

Spotware said: 

Dear trader,

Can you please update your cTrader to 4.8.23 and let us know if you still experience this problem?

Best regards,

cTrader Team


@G.A.F

Spotware
02 Oct 2023, 06:09

Dear giuseppealessioferrandes,

Can you please share a cBot code that would allow us to reproduce this behavior?

Best regards,

cTrader Team


@Spotware

G.A.F
02 Oct 2023, 20:12 ( Updated at: 21 Dec 2023, 09:23 )

RE: huge error on calculation swap between visual mode an non visual mode version 4.8.21

Spotware said: 

Dear giuseppealessioferrandes,

Can you please share a cBot code that would allow us to reproduce this behavior?

Best regards,

cTrader Team

Certainly! I've created a small algorithm to demonstrate where and how the error occurs. The algorithm is designed for use on the EUR/USD daily time frame. In practice, I open a position, and for every certain number of pips of loss, I add volumes to the position to average it. The issue is that after a certain number of added volumes, I encounter an error in the unrealized net, and it appears not to take the swap into account. The same error also occurs in the equity calculation during backtesting, but as you can see in the last image, it includes all the swaps when I close all positions.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo.Robots
{
    [Robot(AccessRights = AccessRights.None)]
    public class NewcBot : Robot
    {
       
        protected override void OnStart()
        {
            MarketData.GetBars(TimeFrame.Minute10).BarOpened += On_10Min_OpenedBar;
            var EXC = ExecuteMarketOrder(TradeType.Buy, SymbolName, Symbol.VolumeInUnitsMin, "", null, null, "" + "-" + "");
            if (EXC.IsSuccessful == false) { Print("error due volumetotrade ", Symbol.VolumeInUnitsMin, "  Reason : ", EXC.Error); }

        }
        private void On_10Min_OpenedBar(BarOpenedEventArgs args)
        {
            try
            {
              

                 PacAccumulationMediation();
               

            }
            catch (Exception ex)
            {
               

                // Gestione generica di altre eccezioni
                Print("Si ? verificato un errore generico.inOn10MinOpenedBar ");
                Print("Dettagli dell'eccezione: " + ex.Message);
            }
        }

        private void PacAccumulationMediation()
        {
            foreach (var p in Positions)
            {
               
                if (p.SymbolName == SymbolName )
                {



                    var volumefactor = p.VolumeInUnits / Symbol.VolumeInUnitsMin;
                    var ATR = 100;
                    var e = ((p.Pips < ATR * -1 * volumefactor));
                    if (e)
                    {
                        var modifedVolume = p.VolumeInUnits + Symbol.VolumeInUnitsMin;
                        var TP = p.TradeType == TradeType.Buy ? Ask * 1000 : Ask / 1000;


                      
                       
                            p.ModifyVolume(modifedVolume);
                            if (p.TakeProfit == null)
                            {
                                p.ModifyTakeProfitPrice(TP);

                            }

                          
                        

                    }




                }
            }

          
        }

    }
}

 


@G.A.F