Dark Theme
Light Theme
Trading Articles
Article Categories
Article Tools
Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to
register in order to view the content of the threads and start contributing to our community.
It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
OnOrderUpdate event in Indicator?
Updated July 10, 2016
trending_up
1,333 views
thumb_up
1 thanks given
group
2 followers
forum
7 posts
attach_file
0 attachments
OnOrderUpdate event in Indicator?
July 9th, 2016, 02:01 PM
Vilcabamba, Ecuador
Experience: Intermediate
Platform: Ninja
Trading: NQ, UB
Posts: 204 since Jul 2012
Ok, you gurus....
Is there anyway to have the function of the OnOrderUpdate event in an Indicator?
:-)
Can you help answer these questions from other members on NexusFi?
Best Threads (Most Thanked) in the last 7 days on NexusFi
July 9th, 2016, 03:54 PM
Gits (Hooglede) Belgium
Legendary Market Wizard
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,863
Yes this is possible,
but you can not override the OnOrderUpdate
The way to do it is to the event itself, like something like below :
Code
protected override void Initialize()
{
}
protected override void OnStartUp()
{
// you have to reinitialze if connection gets lost
NinjaTrader.Cbi.Globals.Connections.ConnectionStatus += new ConnectionStatusEventHandler(OnConnection);
account = NinjaTrader.Cbi.Globals.Accounts.FindByName(accountName);
//return if cannot find the account
if (account == null)
{
this.DrawTextFixed("msg", "Could not retrieve the account", TextPosition.BottomRight);
return;
}
//does not works in market replay connection or simulated data feed
if (account.Connection.Name == "Market Replay Connection" || account.Connection.Name == "Simulated Data Feed")
{
DrawTextFixed("msg", "Email Trades indicator does not works with " + account.Connection.Name, TextPosition.BottomRight);
account = null;
return;
}
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
}
private void OnExecution(object sender, ExecutionUpdateEventArgs e)
{
if (e.Execution.Order != null)
{
if (e.Execution.Order.OrderState == OrderState.Filled)
{
this.SendMail(fromEmailAddress, toEmailAddress, "NinjaTrader Trade Confirmation", "Trade filled for: " + e.Execution.ToString());
return;
}
if (emailPartFilled && e.Execution.Order.OrderState == OrderState.PartFilled)
{
this.SendMail(fromEmailAddress, toEmailAddress, "NinjaTrader Trade Confirmation", "Trade filled for: " + e.Execution.ToString());
}
}
}
private void OnConnection(object sender, ConnectionStatusEventArgs e)
{
if (e.Status == ConnectionStatus.Connected)
{
Account a = e.Connection.Accounts.FindByName(accountName);
if (a != null)
{
account = NinjaTrader.Cbi.Globals.Accounts.FindByName(accountName);
if (account != null)
{
if (account.Connection.Name == "Market Replay Connection" || account.Connection.Name == "Simulated Data Feed")
return;
account.Execution += new ExecutionUpdateEventHandler(OnExecution);
DrawTextFixed("msg", "Sending execution email for account: " + account.Name, TextPosition.BottomRight);
Log("Subscribing to Email Trades indicator for account " + account.Name, LogLevel.Information);
return;
}
}
}
else if (e.Status == ConnectionStatus.ConnectionLost || e.Status == ConnectionStatus.Disconnected)
{
if (account != null && e.Connection.Accounts.Contains(account))
{
account.Execution -= new ExecutionUpdateEventHandler(OnExecution);
account = null;
Log("Unsubscribing to Email Trades indicator on " + e.Status.ToString(), LogLevel.Information);
}
}
}
protected override void OnTermination()
{
NinjaTrader.Cbi.Globals.Connections.ConnectionStatus -= new ConnectionStatusEventHandler(OnConnection);
if (account != null)
{
if (!(account.Connection.Name == "Market Replay Connection" || account.Connection.Name == "Simulated Data Feed"))
{
account.Execution -= new ExecutionUpdateEventHandler(OnExecution);
Log("Unsubscribing to Email Trades indicator for account " + account.Name, LogLevel.Information);
}
}
account = null;
}
July 9th, 2016, 08:11 PM
Vilcabamba, Ecuador
Experience: Intermediate
Platform: Ninja
Trading: NQ, UB
Posts: 204 since Jul 2012
Thanks, it looks like OnExecution can be used in an indicator. (but not overridden...?)
That will give me the first part...when an order is filled/partially filled.
Any easy way to know when the position has been closed?
IOrder.OrderState.Unknown?
--------------------------
also, would really like to test this in SIM or Replay.... no way to do that?
July 10th, 2016, 03:27 AM
Gits (Hooglede) Belgium
Legendary Market Wizard
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,863
vantojo
Thanks, it looks like OnExecution can be used in an indicator. (but not overridden...?)
The example shows the mechanism to subscribe to an 'event' opposed to a method, that is only available
in a strategy. The result is the same, you just need to do a bit more handling.
You should be able to do replay and sim, just play with it and test it out
vantojo
Any easy way to know when the position has been closed?
You should be able to walk through the structures and read that information.
Code
for (int i=0; i < NinjaTrader.Cbi.Globals.Accounts.Count; i++ ) {
for (int j=0; j < NinjaTrader.Cbi.Globals.Accounts[i].Positions.Count; j++ ) {
Print(" "
+NinjaTrader.Cbi.Globals.Accounts[i].Name +" "
+NinjaTrader.Cbi.Globals.Accounts[i].Positions[j].Instrument.FullName +" "
+NinjaTrader.Cbi.Globals.Accounts[i].Positions[j].MarketPosition +" "
+NinjaTrader.Cbi.Globals.Accounts[i].Positions[j].Quantity +" "
+NinjaTrader.Cbi.Globals.Accounts[i].Positions[j].AvgPrice
);
}
}
July 10th, 2016, 10:50 AM
Vilcabamba, Ecuador
Experience: Intermediate
Platform: Ninja
Trading: NQ, UB
Posts: 204 since Jul 2012
Hi,
If this is possible....
account.Execution += new ExecutionUpdateEventHandler(OnExecution);
would this also be possible?
account.OnOrderUpdate += new ExecutionUpdateEventHandler(OnOrderUpdate);
????
(C# is not my first language... )
July 10th, 2016, 11:00 AM
Gits (Hooglede) Belgium
Legendary Market Wizard
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,863
Give it a shot and try it...
July 10th, 2016, 12:40 PM
Vilcabamba, Ecuador
Experience: Intermediate
Platform: Ninja
Trading: NQ, UB
Posts: 204 since Jul 2012
many thanks!
Last Updated on July 10, 2016