major error, does not close open positions during the OnStop event

Created at 04 Aug 2022, 04:22
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

major error, does not close open positions during the OnStop event
04 Aug 2022, 04:22


  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();
                    }

                }


            }
           


        }

 

log plotted error: 24/07/2011 04:53:00.000 | CBot instance [TF Ax Bot 2022, EURUSD, D1] aborted by timeout.
      


@G.A.F
Replies

PanagiotisCharalampous
04 Aug 2022, 09:17

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


@PanagiotisCharalampous

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

... Deleted by UFO ...

PanagiotisCharalampous
04 Aug 2022, 12:53

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


@PanagiotisCharalampous

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, 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

PanagiotisCharalampous
05 Aug 2022, 08:30 ( Updated at: 21 Dec 2023, 09:22 )

Hi,

It worked fine for me

Can you record a video so that we can see what you are doing?

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous