Using Account Object in NinjaTrader - NinjaTrader Programming | futures io social day trading
futures io futures trading


Using Account Object in NinjaTrader
Updated: Views / Replies:4,872 / 26
Created: by maxi 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
 

Using Account Object in NinjaTrader

  #1 (permalink)
Trading Apprentice
Rome, Italy
 
Futures Experience: Advanced
Platform: NinjaTrader
Favorite Futures: Equity Index Futures
 
Posts: 17 since Jul 2010
Thanks: 2 given, 0 received

Using Account Object in NinjaTrader

Hello everybody,

this is my first post in this fantastic forum.

I'm writing from Italy and I'd like to ask something to more experienced Ninja Programmer.

I'm trying to use the Account Object in a Ninja Indicator to create orders on the market.

This means to use i.e. Account.CreateOrders(..........) function.

I've no problem in creating orders (buy/sell/limit/stop), nevertheless I'd like to insert a stoploss order as soon as my order is filled.
I did not find any example on how to do it, neither on how to manage filling.

I'm getting crazy on trying to make the code recognize the position or the filling but no way to make it work.

If somebody faced a similar matter or has examples I'd be very grateful.

I can provide strings of my code if needed.

Thanks in advance to anybody who will answer.

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
Zurich Switzerland
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: IB
Favorite Futures: ES, 6E, CL
 
Posts: 404 since Sep 2009
Thanks: 64 given, 511 received


Hi maxi

In the elite section you could find some stuff.
Try something with OrderState:

 
Code
int c = a.Orders.Count;
Order order = a.Orders[c-1];
if (order.OrderState == OrderState.Filled){isFill=true;} // Order is filled
if (order.OrderState == OrderState.Accepted || order.OrderState == OrderState.Working){btnMoveOrder.Enabled = true;btnMoveOrder.Font = boldfont;} // Order can be moved
if (order.OrderState == OrderState.Cancelled) // Order is cancelled
Enjoy Germany-Italy!

Reply With Quote
 
  #4 (permalink)
Trading Apprentice
Rome, Italy
 
Futures Experience: Advanced
Platform: NinjaTrader
Favorite Futures: Equity Index Futures
 
Posts: 17 since Jul 2010
Thanks: 2 given, 0 received

Thanks for your reply (I enjoyed the football match, by the way......)

Are the lines you suggested suitable for indicators also or only in strategies?

Reply With Quote
 
  #5 (permalink)
Elite Member
Zurich Switzerland
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: IB
Favorite Futures: ES, 6E, CL
 
Posts: 404 since Sep 2009
Thanks: 64 given, 511 received


maxi View Post
Thanks for your reply (I enjoyed the football match, by the way......)

I enjoyed too, nice match with cracy Balotelli....


maxi View Post
Are the lines you suggested suitable for indicators also or only in strategies?

I only use it in indicators, in strategies we have the normal ways to get these infos.

Reply With Quote
 
  #6 (permalink)
Trading Apprentice
Rome, Italy
 
Futures Experience: Advanced
Platform: NinjaTrader
Favorite Futures: Equity Index Futures
 
Posts: 17 since Jul 2010
Thanks: 2 given, 0 received

Thanks very much also for PM!!

Reply With Quote
 
  #7 (permalink)
Trading Apprentice
Rome, Italy
 
Futures Experience: Advanced
Platform: NinjaTrader
Favorite Futures: Equity Index Futures
 
Posts: 17 since Jul 2010
Thanks: 2 given, 0 received

terratec, need more help please.

I need to insert an order and, if filled, a stop and target orders must be placed on the market.

I tried with you suggestion this way:

 
Code
 #region Variables        
		
Order b = null;
		
#endregion

protected override void OnStartUp()
        {
string accName = ChartControl.Controls["pnlChartTrader"].Controls["ctrChartTraderControl"].Controls["cboAccount"].Text;		
			accnt = null;		
			for (int i = 0;i <= NinjaTrader.Cbi.Globals.Accounts.Count - 1; i++)
				{
					if (NinjaTrader.Cbi.Globals.Accounts[i].Name == accName)
					{
					accnt = NinjaTrader.Cbi.Globals.Accounts[i];
					}
				}

// I created a button where I linked the following to enter a buy stop order:

#region Entry
		private void btnOrdSend_Click(object s, EventArgs e)
		{
			
		int quantity = 1;
		
		if (quantity < 1 || entryprice <=1) return;			
		
		if (accnt != null)
			{
				
				b = accnt.CreateOrder(Instrument,OrderAction.Buy,OrderType.Stop,TimeInForce.Day,quantity,0,entryprice,"","Buy");
				b.Submit();	
				
			}		
		}		
		#endregion

// I'm trying to see if the order is filled with the following on OnBarUpdate

protected override void OnBarUpdate()
        {
            
           if (b.OrderState == OrderState.Filled)
			{
			MessageBox.Show("Filled");
			}
			
			
        }
The button perfectly insert the buy stop order on the market but, once filled, no message is shown.
I'm a bit confused on the way the stop/target orders should be coded.

Probably they shouldn't be inserted in the OnBarUpdate space?

I've seen the use of the override Plot, but I've never used it so I don't know how to manage it.

Thanks for any hint

Reply With Quote
 
  #8 (permalink)
Elite Member
Zurich Switzerland
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: IB
Favorite Futures: ES, 6E, CL
 
Posts: 404 since Sep 2009
Thanks: 64 given, 511 received

Hi maxi

You don't have to use the code in the Plot section as I did in the bTPAnaked indicator that I did PM to you. This is just the fastest way to place the orders, but OnBarUpdate should work too.
But have a look at my code in the indicator or in the code in Post#3. This has nothing to do with your code in your last post in OnBarUpdate.

I would start with something like that:
 
Code
protected override void OnBarUpdate()
{ 
	int c = a.Orders.Count;
	Order order = a.Orders[c-1];
	if (order.OrderState == OrderState.Filled)
	{
		// Place your code for the "filled event" here.
 
		// And think about what will happen when the stops and targets are in the order state "filled".
		// You have my code to analyse....
	}
}
Don't know whether it will work or not, as I don't know how you did code the whole thing (maybe you have to replace the "a" with your "accnt" or "b").

Good luck
terratec

Reply With Quote
 
  #9 (permalink)
Trading Apprentice
Rome, Italy
 
Futures Experience: Advanced
Platform: NinjaTrader
Favorite Futures: Equity Index Futures
 
Posts: 17 since Jul 2010
Thanks: 2 given, 0 received

Thanks.

I will look over it more deeply.

Reply With Quote
 
  #10 (permalink)
Trading Apprentice
Rome, Italy
 
Futures Experience: Advanced
Platform: NinjaTrader
Favorite Futures: Equity Index Futures
 
Posts: 17 since Jul 2010
Thanks: 2 given, 0 received


Thanks to your sugestions, I've been able to insert order and manage target/stop orders as well.

The only thing I couldn't do is to manage partial fill.

Is there a way to let the code find out how much of the entry order has been really filled?

Using "order.Quantity" it always counts the original quantity but not the filled one.

Have you ever faced this matter using this class?

Thanks.

Reply With Quote

Reply



futures io > > > > > Using Account Object in NinjaTrader

Thread Tools Search this Thread
Search this Thread:

Advanced Search



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

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Error: Object reference not set to an instance of an object. gomad NinjaTrader Programming 11 December 22nd, 2014 09:09 AM
Ninjatrader sim account license that never expires calvinmr NinjaTrader 5 March 3rd, 2011 01:51 AM
need help :: cant fix :: Object reference not set to an instance of an object Trader.Jon NinjaTrader Programming 9 November 3rd, 2010 11:55 AM
Object-oriented design for complex NinjaTrader strategies shodson NinjaTrader Programming 5 June 5th, 2010 04:36 PM
NinjaTrader Account Performance Tabissues Gabe2004 NinjaTrader 1 December 2nd, 2009 08:27 AM


All times are GMT -4. The time now is 09:14 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-16 in 0.12 seconds with 19 queries on phoenix via your IP 54.83.122.227