OnBrokerStategyOrderFilled  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
User avatar
fbertram
Posts: 166
Joined: 16 Oct 2014
Location: Seattle, USA
Has thanked: 36 times
Been thanked: 76 times
Contact:

OnBrokerStategyOrderFilled

Postby fbertram » 30 Nov 2016

Dear MultiCharts fans,

I am using Portfolio Trader to trade about 200 stocks on daily bars. I am shutting down my trading server every night, and firing it up in the morning before the session opens. Positions stay open for multiple days, and across multiple shutdowns/ restarts of MultiCharts. I am using synchronous auto-trading, and I have set my strategy to use the actual position at the broker as the initial market position. I have implemented email notification in OnBrokerStrategyOrderFilled, which is supposed to send me an email, for every order filled. While my strategy works fine, I find that OnBrokerStrategyOrderFilled is called when the strategy assigns the position at the broker as the initial market position during startup, even though at this point, there is actually no order executed or filled. I'd like to get rid of these 'fake' order filled emails.

This brings me to the following questions:
* is this a bug?
* should I use a different callback?
* should I use a different setting for assigning the initial market position?
* is there a way to distinguish between initialization of the market position and an actual order being filled?

Thank you,
best regards, Felix

User avatar
Kristina MultiCharts
Posts: 63
Joined: 04 Sep 2014
Has thanked: 5 times
Been thanked: 34 times

Re: OnBrokerStategyOrderFilled

Postby Kristina MultiCharts » 01 Dec 2016

Hello Felix,

It’s not a bug, it’s expected that OnBrokerStrategyOrderFilled event is called when marketposition is changed. In your case when you turn on auto-trading, your broker position is assigned to your strategy and the marketposition is changed. That is why you receive alert for this event as well. Please do not generate alerts on the first call of this event OnBrokerStrategyOrderFilled after you turn on auto-trading and you will not receive an email alert when no order is actually executed.

darob
Posts: 207
Joined: 20 Nov 2014
Has thanked: 57 times
Been thanked: 33 times

Re: OnBrokerStategyOrderFilled

Postby darob » 01 Dec 2016

Hi Felix, you could have your broker send emails on position changes as an alternative.

User avatar
fbertram
Posts: 166
Joined: 16 Oct 2014
Location: Seattle, USA
Has thanked: 36 times
Been thanked: 76 times
Contact:

Re: OnBrokerStategyOrderFilled

Postby fbertram » 01 Dec 2016

Please do not generate alerts on the first call of this event OnBrokerStrategyOrderFilled after you turn on auto-trading and you will not receive an email alert when no order is actually executed.
Hi Kristina,

thanks a lot for your response. Unfortunately, filtering 'the first call of this event' is non-trivial. Is there any status information within MultiCharts that I can use to distinguish initialization from valid order filled events? There really should be something... e.g. creating these events while Environment.IsRealTimeCalc is still false. Any help in these regards would be appreciated.

Thank you,
best regards, Felix

User avatar
Kristina MultiCharts
Posts: 63
Joined: 04 Sep 2014
Has thanked: 5 times
Been thanked: 34 times

Re: OnBrokerStategyOrderFilled

Postby Kristina MultiCharts » 02 Dec 2016

Hi Felix,

Please see a sample code attached.
Attachments
Test_ATEvents.pln
(2.15 KiB) Downloaded 524 times

User avatar
fbertram
Posts: 166
Joined: 16 Oct 2014
Location: Seattle, USA
Has thanked: 36 times
Been thanked: 76 times
Contact:

Re: OnBrokerStategyOrderFilled  [SOLVED]

Postby fbertram » 02 Dec 2016

Hi Kristina,

thanks a lot for your code example. Unfortunately, I believe your code will also suppress the message when a new position is intentionally opened.

The best I could come up with is this, but I am not sure this will work under all circumstances. It is not clear to me when exactly the 'initialization confirmation' event is created; can I rely on at least one bar being processed prior to that?

Code: Select all

public class Test_ATEvents : SignalObject {
...
private bool? IgnoreFirstOrderConf;
...
protected override void StartCalc() {
...
IgnoreFirstOrderConf = null;
...
}

protected override void CalcBar() {
...
if (IgnoreFirstOrderConf == null)
IgnoreFirstOrderConf = StrategyInfo.MarketPositionAtBroker != 0 ? true : false;
...
}

protected override void OnBrokerStategyOrderFilled(bool is_buy, int quantity, double avg_fill_price) {
...
if (IgnoreFirstOrderConf == true) {
IgnoreFirstOrderConf = false;
return;
}
...
}

Thank you,
best regards, Felix


Return to “MultiCharts .NET”