change a stop loss while it was disconnected

Created at 01 Dec 2021, 09:30
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!
EY

eynt

Joined 08.05.2020

change a stop loss while it was disconnected
01 Dec 2021, 09:30


My cBot add an error running live yesterday. When I looked at the logs it seems it tried to change a stop loss while it was disconnected.

I'm not sure how can that be but how can I prevent such a think from happening?

 

Thanks


@eynt
Replies

eynt
01 Dec 2021, 09:40

RE:

OK but how is it possible that the OnTick method was even running while the cBot is disconnected?

 

Thanks

 


@eynt

amusleh
01 Dec 2021, 10:32

RE: RE:

yuval.ein said:

OK but how is it possible that the OnTick method was even running while the cBot is disconnected?

 

Thanks

 

It's not possible, if your platform is not connected then there will be no new tick data and the OnTick method will not be called.


@amusleh

eynt
01 Dec 2021, 11:12

RE: RE: RE:

I want to show you the error. Does the journal is saved to somewhere?

 


@eynt

amusleh
01 Dec 2021, 12:37

RE: RE: RE: RE:

yuval.ein said:

I want to show you the error. Does the journal is saved to somewhere?

 

Hi,

You can post the cTrader logs for your cBot and if possible the portion of your cBot code that can replicate this issue.


@amusleh

eynt
01 Dec 2021, 13:58

RE: RE: RE: RE: RE:

 

Please view the "DISCONNECTED" errors I got below. I can upload the entire logf but i'm not sure how to upload files to the forum.

They happened during a simple 'ModifyStopLossPrice' which always works fine, including on the day of the errors, until the errors occured.

 

2021.11.30 16:02:17.920 | Request to amend position PID64902077 (SL: 1.49319) is sent to server
2021.11.30 16:02:19.186 | Request to amend position PID64919920 (SL: 1577.54) is sent to server
2021.11.30 16:02:21.202 | Request to Buy 0.01 Lots SpotCrude is sent to server
2021.11.30 16:02:22.137 | → Request to amend position PID64902077 (SL: 1.49319) is REJECTED with error "DISCONNECTED"
2021.11.30 16:02:22.146 | → Request to amend position PID64919920 (SL: 1577.54) is REJECTED with error "DISCONNECTED"
2021.11.30 16:02:22.211 | → Order OID0 is REJECTED with error "DISCONNECTED"
2021.11.30 16:02:22.315 | Request to close position PID64902077 is sent to server
2021.11.30 16:02:22.362 | → Failed to close position PID64902077 with error "DISCONNECTED"
2021.11.30 16:02:22.365 | Request to close position PID64919920 is sent to server
2021.11.30 16:02:22.376 | → Failed to close position PID64919920 with error "DISCONNECTED"
2021.11.30 16:02:23.651 | cBot "Main" was stopped for SpotCrude, Ra1.
2021.11.30 16:02:28.941 | Request to close position PID64902077 is sent to server
2021.11.30 16:02:29.109 | → Request to close position PID64902077 is ACCEPTED, order OID101746508 created (30/11/2021 16:02:29.028 UTC+0)
2021.11.30 16:02:29.420 | → Order OID101746508 is FILLED at 1.48182, position PID64902077 closed (30/11/2021 16:02:29.059 UTC+0)
2021.11.30 16:02:29.597 | cBot "Main" was stopped for CHFSGD, Ra1.
2021.11.30 16:12:40.758 | cBot "Main" was stopped for XAUEUR, Ra1.
2021.11.30 16:38:17.105 | cTrader started

 

 


@eynt

amusleh
02 Dec 2021, 08:45

RE: RE: RE: RE: RE: RE:

yuval.ein said:

 

Please view the "DISCONNECTED" errors I got below. I can upload the entire logf but i'm not sure how to upload files to the forum.

They happened during a simple 'ModifyStopLossPrice' which always works fine, including on the day of the errors, until the errors occured.

 

2021.11.30 16:02:17.920 | Request to amend position PID64902077 (SL: 1.49319) is sent to server
2021.11.30 16:02:19.186 | Request to amend position PID64919920 (SL: 1577.54) is sent to server
2021.11.30 16:02:21.202 | Request to Buy 0.01 Lots SpotCrude is sent to server
2021.11.30 16:02:22.137 | → Request to amend position PID64902077 (SL: 1.49319) is REJECTED with error "DISCONNECTED"
2021.11.30 16:02:22.146 | → Request to amend position PID64919920 (SL: 1577.54) is REJECTED with error "DISCONNECTED"
2021.11.30 16:02:22.211 | → Order OID0 is REJECTED with error "DISCONNECTED"
2021.11.30 16:02:22.315 | Request to close position PID64902077 is sent to server
2021.11.30 16:02:22.362 | → Failed to close position PID64902077 with error "DISCONNECTED"
2021.11.30 16:02:22.365 | Request to close position PID64919920 is sent to server
2021.11.30 16:02:22.376 | → Failed to close position PID64919920 with error "DISCONNECTED"
2021.11.30 16:02:23.651 | cBot "Main" was stopped for SpotCrude, Ra1.
2021.11.30 16:02:28.941 | Request to close position PID64902077 is sent to server
2021.11.30 16:02:29.109 | → Request to close position PID64902077 is ACCEPTED, order OID101746508 created (30/11/2021 16:02:29.028 UTC+0)
2021.11.30 16:02:29.420 | → Order OID101746508 is FILLED at 1.48182, position PID64902077 closed (30/11/2021 16:02:29.059 UTC+0)
2021.11.30 16:02:29.597 | cBot "Main" was stopped for CHFSGD, Ra1.
2021.11.30 16:12:40.758 | cBot "Main" was stopped for XAUEUR, Ra1.
2021.11.30 16:38:17.105 | cTrader started

 

 

Hi,

It looks like cTrader got disconnected while your cBot code was running, and all the code commands failed as cTrader was disconnected.

So you were already inside OnTick, it wasn't called after disconnection, it was called while cTrader was connected and while it was executing cTrader got disconnected.


@amusleh

eynt
02 Dec 2021, 09:19

RE: RE: RE: RE: RE: RE: RE:

OK so how can I prevent from running code inside OnTick after disconnection?

 


@eynt

amusleh
02 Dec 2021, 09:50

RE: RE: RE: RE: RE: RE: RE: RE:

yuval.ein said:

OK so how can I prevent from running code inside OnTick after disconnection?

 

Hi,

You can guard your code by using the Server.IsConnected property like I said before.


@amusleh