NexusFi: Find Your Edge


Home Menu

 





Using Account Object in NinjaTrader


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one maxi with 8 posts (0 thanks)
    2. looks_two MWinfrey with 7 posts (1 thanks)
    3. looks_3 vvhg with 6 posts (3 thanks)
    4. looks_4 terratec with 5 posts (1 thanks)
    1. trending_up 10,807 views
    2. thumb_up 5 thanks given
    3. group 6 followers
    1. forum 26 posts
    2. attach_file 0 attachments




 
Search this Thread

Using Account Object in NinjaTrader

  #1 (permalink)
maxi
Rome, Italy
 
Posts: 17 since Jul 2010
Thanks Given: 2
Thanks Received: 1

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

Can you help answer these questions
from other members on NexusFi?
ZombieSqueeze
Platforms and Indicators
Trade idea based off three indicators.
Traders Hideout
Better Renko Gaps
The Elite Circle
Increase in trading performance by 75%
The Elite Circle
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
33 thanks
Tao te Trade: way of the WLD
24 thanks
My NQ Trading Journal
14 thanks
HumbleTraders next chapter
11 thanks
GFIs1 1 DAX trade per day journal
11 thanks
  #3 (permalink)
 terratec 
Zurich Switzerland
 
Experience: Intermediate
Platform: NinjaTrader
Broker: IB
Trading: ES, 6E, CL
Posts: 403 since Sep 2009
Thanks Given: 64
Thanks Received: 515


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)
maxi
Rome, Italy
 
Posts: 17 since Jul 2010
Thanks Given: 2
Thanks Received: 1

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)
 terratec 
Zurich Switzerland
 
Experience: Intermediate
Platform: NinjaTrader
Broker: IB
Trading: ES, 6E, CL
Posts: 403 since Sep 2009
Thanks Given: 64
Thanks Received: 515


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)
maxi
Rome, Italy
 
Posts: 17 since Jul 2010
Thanks Given: 2
Thanks Received: 1

Thanks very much also for PM!!

Reply With Quote
  #7 (permalink)
maxi
Rome, Italy
 
Posts: 17 since Jul 2010
Thanks Given: 2
Thanks Received: 1

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)
 terratec 
Zurich Switzerland
 
Experience: Intermediate
Platform: NinjaTrader
Broker: IB
Trading: ES, 6E, CL
Posts: 403 since Sep 2009
Thanks Given: 64
Thanks Received: 515

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)
maxi
Rome, Italy
 
Posts: 17 since Jul 2010
Thanks Given: 2
Thanks Received: 1

Thanks.

I will look over it more deeply.

Reply With Quote
  #10 (permalink)
maxi
Rome, Italy
 
Posts: 17 since Jul 2010
Thanks Given: 2
Thanks Received: 1


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




Last Updated on November 20, 2012


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
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.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts