Replies

G.A.F
16 Jun 2024, 13:17

RE: Discrepancy in Swap Calculation with cBot

PanagiotisCharalampous said: 

Hi there,

See the correct formula below

        private double CalculateSwap(double swap, double volume)        {             return AssetConverter.Convert(Symbol.SwapLong * Symbol.PipSize * volume, Symbol.QuoteAsset, Account.Asset );         }

Best regards,

Panagiotis

thanks a lot now is working Fine

 


@G.A.F

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

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

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
01 Sep 2023, 08:46

RE: swap on backtest

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
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
04 Aug 2022, 19:51

RE:

giuseppealessioferrandes said:

PanagiotisCharalampous said:

Hi there,

I tried with the attached code and there is no problem. Unfortunately we cannot help if we do not recieve the requested information.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

 

Eur Usd

start :14/6/2011

stop:26/6/2011

 

icmarkets

no pposition closed

 

 

 

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 NewcBot4 : Robot
    {
        [Parameter(DefaultValue = "Hello world!")]
        public string Message { get; set; }

        protected override void OnStart()
        {
          
        }

        protected override void OnBar()
        {
            ExecuteMarketOrder(TradeType.Sell, SymbolName, Symbol.VolumeInUnitsMin, "0", null, null, "A", false);
        }

        protected override void OnStop()
        {
           if (RunningMode == RunningMode.SilentBacktesting || RunningMode == RunningMode.VisualBacktesting || RunningMode == RunningMode.Optimization)
            {
                foreach (var posi in Positions)
                {
                   if (posi.SymbolName == SymbolName)
                    {

                        ClosePosition(posi);
                       
                    }
                }
               
                foreach (var pos in PendingOrders)
                {

                    if (pos.SymbolName == SymbolName)
                    {
                        pos.Cancel();
                    }



                }


            }
        }
    }
}

 

 

i forgot timeframe daily

 


@G.A.F

G.A.F
04 Aug 2022, 19:50

PanagiotisCharalampous said:

Hi there,

I tried with the attached code and there is no problem. Unfortunately we cannot help if we do not recieve the requested information.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

 

Eur Usd

start :14/6/2011

stop:26/6/2011

 

icmarkets

no pposition closed

 

 

 

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 NewcBot4 : Robot
    {
        [Parameter(DefaultValue = "Hello world!")]
        public string Message { get; set; }

        protected override void OnStart()
        {
          
        }

        protected override void OnBar()
        {
            ExecuteMarketOrder(TradeType.Sell, SymbolName, Symbol.VolumeInUnitsMin, "0", null, null, "A", false);
        }

        protected override void OnStop()
        {
           if (RunningMode == RunningMode.SilentBacktesting || RunningMode == RunningMode.VisualBacktesting || RunningMode == RunningMode.Optimization)
            {
                foreach (var posi in Positions)
                {
                   if (posi.SymbolName == SymbolName)
                    {

                        ClosePosition(posi);
                       
                    }
                }
               
                foreach (var pos in PendingOrders)
                {

                    if (pos.SymbolName == SymbolName)
                    {
                        pos.Cancel();
                    }



                }


            }
        }
    }
}

 

 


@G.A.F

G.A.F
04 Aug 2022, 12:32

RE: no matter the code, it happens at any date or time when I have to close various positions as I told you, the bot is also operational in live on icmarkets, so please solve it quickly or give the possibility to return to the previous working version

PanagiotisCharalampous said:

Hi there,

Please provide us with the following

  1. The complete cBot code
  2. Broker, cBot parameters and dates where we can run this and reproduce the problem

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

 


@G.A.F