One robot influences other - HOW TO STOP?

Created at 22 Jan 2017, 10:36
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!
DA

davidp13

Joined 06.05.2014

One robot influences other - HOW TO STOP?
22 Jan 2017, 10:36


Hi all. I have multiple robots in my test environment and have noticed that certain robots impacts open positions they should not. Now other than using lables or position ID, how else can one stop it form happening. A code example of an exit strategy is below. What can I add, like maybe robot name, to stop this from happening?

             foreach (var position in Positions)
            {
              if (MarketSeries.OpenTime.LastValue.Hour == 20 && MarketSeries.OpenTime.LastValue.DayOfWeek == DayOfWeek.Friday)
                {
                    ClosePosition(position);
                }
            }

 

Thanks


@davidp13
Replies

davidp13
22 Jan 2017, 19:33

I figured that I wll use the Robot name, equal that to the comment of the trade and then filter that with a unique lable. Not elegant at all, but what can I do...


@davidp13

whis.gg
22 Jan 2017, 20:53

You can make a collection of all opened positions within robot memory and handle it from there rather than using built-in collection which contains all positions opened by the account.


@whis.gg

kricka
26 Jan 2017, 01:25

Stop and start another cBot

A new method is needed within the API, how to stop and start another cBot.


@kricka

FMogyi
26 Jan 2017, 15:02

Hi,

If you use more cBots simultaneously  you should use Label parameter (means cBot ID) when managing your positions and orders.

Here is an example for closing:

//
            var positions = Positions.FindAll(Label, Symbol);  // cBot gets own positions only. 

            foreach (var position in positions)
            {
                TradeResult result = ClosePosition(position);
                if (!result.IsSuccessful)
                {
                    Print("*** ClosePos Err: {0} {1} {2} {3}", position.Id, position.Label, position.TradeType, result.Error);
                    error++;
                }
                else if (debug)
                    Print("--> {0} ClosePosition Ok.", position.Id);

            }
        }

Best Regards


@FMogyi