events or callbacks once order is filled

Questions about MultiCharts .NET and user contributed studies.
User avatar
ernay
Posts: 14
Joined: 08 Jun 2020
Has thanked: 9 times

events or callbacks once order is filled

Postby ernay » 16 Jun 2020

I'd like to be able to receive an immediate notification via callback when an order is executed.

It would also be great to be able to register a time of day callback. i.e. At 2pm EST everyday a callback fires.

Are there examples for different types of events/callbacks available?

jules190
Posts: 20
Joined: 06 Aug 2014
Been thanked: 4 times

Re: events or callbacks once order is filled

Postby jules190 » 25 Jun 2020

TradeManager has events that you can subscribe to.

https://www.multicharts.com/downloads/M ... e-v1.0.pdf

Here's a quick example. It outputs when an order is added. A few points to note:
  1. The orders collection is only updated upon calling TradeManager.ProcessEvents(), so you need to call this from CalcBar.
  2. Enabling IOGMode is the best way to trigger the event asap after the collection changes.
  3. The entire orders array is passed to the callback, rather than the specific order that triggered the event.
For the time of day callback, I would probably start a timer in StartCalc and check the current datetime on tick. If the time matches your callback time, execute method.

Code: Select all

using System; using System.Drawing; using System.Linq; using System.Net; using PowerLanguage.Function; using PowerLanguage.TradeManager; using ATCenterProxy.interop; using Newtonsoft.Json; namespace PowerLanguage.Strategy { [IOGMode(IOGMode.Enabled)] public class CallbackExample : SignalObject { public CallbackExample(object _ctx) : base(_ctx) { } protected override void Create() { } protected override void StartCalc() { this.Output.Clear(); this.TradeManager.TradingData.Orders.Added += (orders) => { this.Output.WriteLine("Order Added"); }; } protected override void CalcBar() { this.TradeManager.ProcessEvents(); } } }

User avatar
Vlada MultiCharts
Posts: 293
Joined: 22 Apr 2020
Has thanked: 8 times
Been thanked: 76 times

Re: events or callbacks once order is filled

Postby Vlada MultiCharts » 30 Jun 2020

Hello,

You can enable the option Recalculate on Broker Events -> Order Filled by going Format -> Strategy Properties -> Auto Trading Tab (check the attached screenshot).

If you'd like to perform calculations at a specific time, you can use a keyword RecalcLastBarAfter.
Attachments
Auto Trading Settings_MultiCharts.png
(24.64 KiB) Not downloaded yet


Return to “MultiCharts .NET”