OnOrderUpdate event in Indicator? - NinjaTrader Programming | futures io social day trading
futures io futures trading


OnOrderUpdate event in Indicator?
Updated: Views / Replies:359 / 7
Created: by vantojo Attachments:0

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 
Thread Tools Search this Thread
 

OnOrderUpdate event in Indicator?

  #1 (permalink)
Elite Member
Neuquen, Argentina
 
Futures Experience: Intermediate
Platform: Ninja
Favorite Futures: CL, TF, 6S, NG, sometimes GC
 
Posts: 195 since Jul 2012
Thanks: 25 given, 39 received

OnOrderUpdate event in Indicator?

Ok, you gurus....

Is there anyway to have the function of the OnOrderUpdate event in an Indicator?

:-)

Reply With Quote
 
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

 
  #3 (permalink)
Elite Member
Omer עומר / Israel י
 
Futures Experience: Master
Platform: NinjaTrader, Proprietary,
Broker/Data: Ninjabrokerage/IQfeed + Synthetic datafeed
Favorite Futures: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
 
rleplae's Avatar
 
Posts: 2,488 since Sep 2013
Thanks: 1,702 given, 3,690 received
Forum Reputation: Legendary


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;
		
}

Reply With Quote
 
  #4 (permalink)
Elite Member
Neuquen, Argentina
 
Futures Experience: Intermediate
Platform: Ninja
Favorite Futures: CL, TF, 6S, NG, sometimes GC
 
Posts: 195 since Jul 2012
Thanks: 25 given, 39 received

reply

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?

Reply With Quote
 
  #5 (permalink)
Elite Member
Omer עומר / Israel י
 
Futures Experience: Master
Platform: NinjaTrader, Proprietary,
Broker/Data: Ninjabrokerage/IQfeed + Synthetic datafeed
Favorite Futures: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
 
rleplae's Avatar
 
Posts: 2,488 since Sep 2013
Thanks: 1,702 given, 3,690 received
Forum Reputation: Legendary


vantojo View Post
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 View Post

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
        );
    }
}

Reply With Quote
 
  #6 (permalink)
Elite Member
Neuquen, Argentina
 
Futures Experience: Intermediate
Platform: Ninja
Favorite Futures: CL, TF, 6S, NG, sometimes GC
 
Posts: 195 since Jul 2012
Thanks: 25 given, 39 received

reply

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... )

Reply With Quote
 
  #7 (permalink)
Elite Member
Omer עומר / Israel י
 
Futures Experience: Master
Platform: NinjaTrader, Proprietary,
Broker/Data: Ninjabrokerage/IQfeed + Synthetic datafeed
Favorite Futures: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
 
rleplae's Avatar
 
Posts: 2,488 since Sep 2013
Thanks: 1,702 given, 3,690 received
Forum Reputation: Legendary

Give it a shot and try it...

Reply With Quote
The following user says Thank You to rleplae for this post:
 
  #8 (permalink)
Elite Member
Neuquen, Argentina
 
Futures Experience: Intermediate
Platform: Ninja
Favorite Futures: CL, TF, 6S, NG, sometimes GC
 
Posts: 195 since Jul 2012
Thanks: 25 given, 39 received

ok

many thanks!

Reply With Quote

Reply



futures io > > > > > OnOrderUpdate event in Indicator?

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Linda Bradford Raschke: Reading The Tape

Elite only

Adam Grimes: TBA

Elite only

NinjaTrader: TBA

January

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Event Trading haonkered Traders Hideout 3 January 14th, 2015 09:47 AM
OnOrderUpdate questions ericson NinjaTrader Programming 2 February 1st, 2014 11:57 AM
Chart event notify? Joseph689 NinjaTrader 0 October 27th, 2012 02:42 PM
Millisecond timer event arjfca EasyLanguage Programming 5 July 3rd, 2011 07:37 AM
Need help with an event ghoti NinjaTrader Programming 1 March 14th, 2011 02:44 PM


All times are GMT -4. The time now is 03:40 AM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts
Page generated 2017-12-13 in 0.11 seconds with 19 queries on phoenix via your IP 54.226.132.197