"stop all" doesn't always stop all bots

Created at 05 Aug 2019, 09:33
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!
FI

firemyst

Joined 26.03.2019

"stop all" doesn't always stop all bots
05 Aug 2019, 09:33


Hello Team SpotWare:

I've encountered this issue twice over the last week.

I have multiple bot instances running. When I click the "stop all" button, not all the bots always stop. This happens infrequently, but frequently enough to be noticed.

Below is one such position today where it happened:

Here's the last entry in the log tab

Here is the code in the OnStop method:

protected override void OnStop()
        {
            if (CloseAllOpenPositionsWhenBotStopped)
            {
                if (DebugLogMode)
                    Print("OST01: closing all \"{0}\" positions.", _positionLabel);

                //Close off all open positions.
                //Make sure to only close those positions for the current Label/Symbol. 
                foreach (Position p in Positions.FindAll(_positionLabel, Symbol.Name))
                {
                    ClosePositionAsync(p, (TradeResult r) =>
                    {
                        if (r.IsSuccessful)
                        {
                            Print("OST01: Closed position \"{0} {1}\".", p.Id, p.Label);
                        }
                        else if (!r.IsSuccessful)
                        {
                            Print("OST01: WARNING! Could not close position \"{0} {1}\"!", p.Id, p.Label);
                            Print("OST01: Error message: {0}", r.Error.Value);
                        }
                    });
                }
            }
            else if (SetStopLossesToTrailingStopLossesWhenBotStopped && DefaultStopLossPips > 0)
            {
//
//This is the last line that gets printed in the log tab
//
                if (DebugLogMode)
                    Print("OST02: setting all stop losses to trailing stop losses on \"{0}\" positions.", _positionLabel);

                //Change SL's for all open positions.
                //Make sure to only do it for the current Label/Symbol. 
                foreach (Position p in Positions.FindAll(_positionLabel, Symbol.Name))
                {
//
//I BELIEVE using p.StopLoss.Value is causing the issue, as I recently changed
//it from p.StopLoss.GetValueOrDefault()
//But as you can see from the screen capture, the SL has a value.
//It doesn't happen every time though, and I can't pinpoint what causes it to occur
//other than I've only noticed it happeneds when I click on the "stop all" button.
//
                    ModifyPositionAsync(p, p.StopLoss.Value, null, true, null, (TradeResult r) =>
                    {
                        if (r.IsSuccessful)
                        {
                            Print("OST02: Successfully set TSL of position \"{0} {1}\" to true.", p.Id, p.Label);
                        }
                        else if (!r.IsSuccessful)
                        {
                            Print("OST02: WARNING! Could not set TSL of position \"{0} {1}\" to true!", p.Id, p.Label);
                            Print("OST02: Error message: {0}", r.Error.Value);
                        }
                    });
                }
            }

            //cleanup to free up member
            _breakEvenPoints.Clear();
            _breakEvenPoints = null;
            _lockObject = null;
            _p = null;

            NullifyIndicatorObjects();

            Print("Over and out.");
        }

I also have an MP4 video I recorded showing the log tab, and my clicks, that nothing happens. It also shows me able to start/stop other bot instances (of the same bot) normally. Let me know where I can email it and I'll send a copy through as it's approximately 200kb.

I also did a ctrl-alt-shift-T and sent information that way with a note I'd post more details to the forums here.

I have to stop cTrader and restart to actually stop the bot.

Thank you.

 


@firemyst
Replies

firemyst
06 Aug 2019, 17:14

Hi Team Spotware:

After running on multiple computers today, it didn't happen once when I switched back to using:

p.StopLoss.GetValueOrDefault() in the ModifyPositionAsync call.

Yesterday after I reported it in the forums here, but before making the code change, it happened again on the GBPAUD pair.

So I definitely believe that using p.StopLoss.Value in the ModifyPositionAsync call is causing the issue and needs further investigation.

 

Thank you.


@firemyst

PanagiotisCharalampous
06 Aug 2019, 17:19

Hi FireMyst,

Send us the video at community@spotware.com.

Best Regards,

Panagiotis


@PanagiotisCharalampous

firemyst
06 Aug 2019, 17:36

RE:

Panagiotis Charalampous said:

Hi FireMyst,

Send us the video at community@spotware.com.

Best Regards,

Panagiotis

Sent the mp4 file as requested.

It will show you me clicking on the button and not doing anything; however, I can click on other buttons fine to start/stop bot instances.

 

 


@firemyst

PanagiotisCharalampous
09 Aug 2019, 14:53

Hi FireMyst,

We tried reproducing the problem but we could not. To investigate further we will need more information like the full cBot code, the number of instances running concurrently and the cBot parameters for each of them. We need to setup the exact same environment as you have. If you can send this information we can have another look.

Best Regards,

Panagiotis


@PanagiotisCharalampous

firemyst
09 Aug 2019, 15:03

RE:

Panagiotis Charalampous said:

Hi FireMyst,

We tried reproducing the problem but we could not. To investigate further we will need more information like the full cBot code, the number of instances running concurrently and the cBot parameters for each of them. We need to setup the exact same environment as you have. If you can send this information we can have another look.

Best Regards,

Panagiotis

I will try setting it up with simplified code and let you know. It didn't happen often, but often enough. I typically had 23 bot instances running.


@firemyst