Idea: purposely send a rejected order to test IB connection?

Questions about MultiCharts and user contributed studies.
User avatar
pcrespo
Posts: 49
Joined: 07 Feb 2015
Has thanked: 7 times
Been thanked: 4 times

Idea: purposely send a rejected order to test IB connection?

Postby pcrespo » 03 Mar 2019

Say at 1:00 AM you send an invalid order of some sort. If you're connected, the order will get sent and rejected, and you can use a command like RejectedOrderCategory to detect that an order was rejected.

If you're disconnected, the order won't get sent to broker in the first place, and the command will return 0 (no rejected order). So now you can have the signal send an alert that you're disconnected.

Is everything above correct?

User avatar
pcrespo
Posts: 49
Joined: 07 Feb 2015
Has thanked: 7 times
Been thanked: 4 times

Re: Idea: purposely send a rejected order to test IB connection?

Postby pcrespo » 04 Mar 2019

It worked! I wrote a signal based on my OP. Last night, IB disconnected in the midnight hour and failed to reconnect. (It seems to happen more on Sunday nights for some reason.) My signal detected that and sent me an alert.

Code: Select all

//Sends a purposely rejected order to test the connection.
//Use a current instrument in Data2 so that there are calculations.

[AllowSendOrdersAlways = true] //There will be no Data1 bar closes.

vars:
intrabarpersist sentorder(false),
intrabarpersist rejection(false),
intrabarpersist discon(false),
intrabarpersist ordertimer(0);

if date>date[1] then begin
discon = false;
rejection = false;
sentorder = false;
ordertimer = 0;
end;
if ((rejection or discon)=false) then begin
if sentorder then begin
rejection = rejection or (RejectedOrderCategory>0);
if rejection=false then begin
ordertimer = ordertimer+1;
if ordertimer=3 then begin
alert("Disconnected from IB");
discon = true;
end;
end;
end;
if (time>114 and time<131) then begin
buy 1 contract this bar close;
sentorder = true;
rejection = rejection or (RejectedOrderCategory>0);
end;
end;
For Data1 I used @ES#C (IQF) mapped to an expired December contract ESZ8 (IB). Mapping to ESZ8 causes an order to be rejected if sent; using @ES#C allows there to be backtestable data so that I'm able to start the signal to begin with. For Data2 I used a current contract @ESM19 so that there are new bars coming in (and therefore, calculations for the signal to make). I left the account / financial advisor settings blank. I checkmarked "Recalculate on event: Order Rejected".

This is probably the simplest (if not only?) way to check your connection to IB if IB isn't your data provider.

Cheers

User avatar
pcrespo
Posts: 49
Joined: 07 Feb 2015
Has thanked: 7 times
Been thanked: 4 times

Re: Idea: purposely send a rejected order to test IB connection?

Postby pcrespo » 04 Mar 2019

I take it back: it doesn't work. It sends the "disconnected" alert whether you're connected or not.

It fails because the command RejectedOrderCategory always returns 0 even in the presence of a rejected order, whether trading from PT or the chart, with IOG on or off.

If that command were to actually work, then this idea would probably work. I suppose this is a bug in MC?

User avatar
Anna MultiCharts
Posts: 560
Joined: 14 Jul 2017
Has thanked: 42 times
Been thanked: 140 times

Re: Idea: purposely send a rejected order to test IB connection?

Postby Anna MultiCharts » 07 Mar 2019

Hello, pcrespo!

We’ve checked this on our end and the keyword works fine on our end. Please let us know the details: what happens in MultiCharts when RejectedOrderCategory returns 0 and you expect it to return a different value? Can you describe the setup in which this is reproduced on steady basis or attach the workspace and other signals so we could run them on our end? Can you provide a step-by-step instruction to reproduce this?


Return to “MultiCharts”