Topics
Replies

firemyst
02 Apr 2019, 09:03

Does stopping a bot close all open positions?

Hi everyone:

Reading this thread and for clarification -- does stopping a bot close all open positions and pending orders?

Or (most likely) do they have to be programmatically closed in the OnStop method since the orders/positions are on the server?

Thank you


@firemyst

firemyst
01 Apr 2019, 07:36

RE:

a.fernandez.martinez said:

Hello,

 

I have a doubt on the api to open a new position.

I don't understand the pending order, if I want to open a position I just use ExecuteMarketOrder right ?

Does that create a pending order that I have to wait to get accepted by the server ?

 

Thanks,

As far as I know and understand, the ExecuteMarketOrder creates a new "position", not an "order". 

Then you have to test to see if it was successful. Eg, TradeResult r; if r.IsSuccessful then ... 

If the result is successful, it was accepted by the server. 


@firemyst

firemyst
28 Mar 2019, 01:39

RE:

Panagiotis Charalampous said:

Hi FireMyst,

Try changing your cBot and indicator access rights e.g. try AccessRights = AccessRights.FullAccess.

Best Regards,

Panagiotis

Thank you! That was the issue exactly. Except, in this case, I only had to change the access rights on the bot, and not the indicator.

Funnily enough, after your response, I found the reference and guide online for access rights. Here it currently is for everyone else's reference:

https://ctrader.com/api/guides/access_rights

 


@firemyst

firemyst
26 Mar 2019, 16:02

Thank you for your reply, but that's not what I meant. :-)

In the "OnTick" method, after I place an order:

ExecuteMarketOrder(TradeType.Buy, Symbol, PositionSize, MyLabel, StopLossInPips, null, null, null, true);

I had an area of code that gets run through if I have at least 1 open position:

if (Positions.Count > 0)
                    {
                        Position position = Positions[0];
                        Print("Stoploss: {0},", position.StopLoss);
                    }

 

The value of position.StopLoss never seemed to change, even though I can see the trailing stop loss move on the chart in backtest mode.

 

However, I've since managed ot figure out my issue - I wasn't looking at the correct times in the log. Doh! :-) 

Anyway, I appreciate your response :-)

 


@firemyst