Callback method upon order execution?

Questions about MultiCharts .NET and user contributed studies.
tradetree
Posts: 81
Joined: 29 Apr 2013
Location: www.threefoldmarkets.com
Has thanked: 12 times
Been thanked: 16 times
Contact:

Callback method upon order execution?

Postby tradetree » 10 Apr 2014

I asked this on the forum awhile back, "What is the callback method upon order execution? I noticed there is OnBrokerStrategyOrderFilled, but is that the main method or is OnBrokerPositionChange?" I have not seen any response to this question. Can someone from MC please answer (or someone who has written code for this)? Thx.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Callback method upon order execution?

Postby Henry MultiСharts » 14 Apr 2014

Hello tradetree,

Help file describes these events the following way:
OnBrokerPositionChange - Event that occurs after MarketPosition and/or average Entry Price changed at broker.

OnBrokerStategyOrderFilled - Event that occurs after strategy Order has been Filled at broker. This method can be used only for automated trading, not for manual trading.

If you are looking for a callback method upon order execution for automated trading then OnBrokerStategyOrderFilled looks like the proper one for you. Let me know in case you have any further questions.

tradetree
Posts: 81
Joined: 29 Apr 2013
Location: www.threefoldmarkets.com
Has thanked: 12 times
Been thanked: 16 times
Contact:

Re: Callback method upon order execution?

Postby tradetree » 15 Apr 2014

It doesn't do what I thought it would, so let me explain what I need. I want to know when the "GenerateStopLoss" is hit. Currently I have no way of knowing other than inferences. Here is some code to attempt to detect a stop loss execution:

In CalcBar():

Code: Select all

// I set myTrade.Order when I place a trade, so if null I did not place the trade
if( myTrade.Order == null & (StrategyInfo.MarketPosition == 0 & prevMarketPosition != 0) ){
myTrade.Order = m_ExitShort.Info.Action.ToString();
if( prevMarketPosition > 0 )
myTrade.Order = m_ExitLong.Info.Action.ToString();
// Do something now that I know if it hit a long or short stop.
}
myTrade.Order = null;
As you can see it is a lot of work to find out what should be given to us.
prevMarketPosition = StrategyInfo.MarketPosition;

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Callback method upon order execution?

Postby Henry MultiСharts » 15 Apr 2014

OnBrokerStrategyOrderFilled, OnBrokerPositionChange, market position, amount of contracts in the current position, collections of Open and Closed Trades are indirect methods of checking whether an order was filled or not.

If you want to check the status of a specific order (whether it is filled, pending, working, cancelled, etc.) - please refer to the following code sample.

We are going to improve the algorithms of order handling in backtesting and auto trading in the new Auto Trading and Backtesting engine that is coming in one of the future versions of MultiCharts.


Return to “MultiCharts .NET”