NexusFi: Find Your Edge


Home Menu

 





Solutions to managing multiple orders in NT?


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one drolles with 7 posts (1 thanks)
    2. looks_two Jaba with 2 posts (4 thanks)
    3. looks_3 vvhg with 2 posts (1 thanks)
    4. looks_4 diagonAlley with 2 posts (0 thanks)
    1. trending_up 5,890 views
    2. thumb_up 6 thanks given
    3. group 6 followers
    1. forum 14 posts
    2. attach_file 0 attachments




 
Search this Thread

Solutions to managing multiple orders in NT?

  #1 (permalink)
 drolles 
London, UK
 
Experience: Beginner
Platform: TradeLink, OpenQuant, considering anything that works...
Trading: if it trades...
Posts: 94 since Oct 2010
Thanks Given: 24
Thanks Received: 39

Hi,

I’m wondering if I could share some ideas on managing multiple orders in NT?

Given that you can’t create IOrder objects (as it is an interface) I’m wondering what is people usual approach to this?

I’ve been pursuing a possible approach around putting IOrder in a List (System.Collections.Generic) as they are created. Then you can search the list for the last order created to know which one was the last entry.

I see that NT is going to fix this in Version 8 access to the orders of open positions (thanks for Big Mike to organising the walk-through the other week).

Thanks and regards,

drolles

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
ZombieSqueeze
Platforms and Indicators
Exit Strategy
NinjaTrader
Are there any eval firms that allow you to sink to your …
Traders Hideout
Deepmoney LLM
Elite Quantitative GenAI/LLM
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
61 thanks
Funded Trader platforms
38 thanks
NexusFi site changelog and issues/problem reporting
26 thanks
The Program
18 thanks
Battlestations: Show us your trading desks!
18 thanks
  #2 (permalink)
 
vvhg's Avatar
 vvhg 
Northern Germany
 
Experience: Intermediate
Platform: NT
Trading: FDAX, CL
Posts: 1,583 since Mar 2011
Thanks Given: 1,016
Thanks Received: 2,824


drolles View Post
Hi,

I’m wondering if I could share some ideas on managing multiple orders in NT?

Given that you can’t create IOrder objects (as it is an interface) I’m wondering what is people usual approach to this?

I’ve been pursuing a possible approach around putting IOrder in a List (System.Collections.Generic) as they are created. Then you can search the list for the last order created to know which one was the last entry.

I see that NT is going to fix this in Version 8 access to the orders of open positions (thanks for Big Mike to organising the walk-through the other week).

Thanks and regards,

drolles

Account has a method called CreateOrder, that should do the trick, you can also modify existing ones...

vvhg

Hic Rhodos, hic salta.
Reply With Quote
Thanked by:
  #3 (permalink)
 drolles 
London, UK
 
Experience: Beginner
Platform: TradeLink, OpenQuant, considering anything that works...
Trading: if it trades...
Posts: 94 since Oct 2010
Thanks Given: 24
Thanks Received: 39


Thanks for the prompt reply.

I think you might mean something like this:
 
Code
                 foreach (Account acct in Cbi.Globals.Accounts)
                            {
                                // do some stuff with the orders

                                if (acct.Orders != null)
                                {
                                    foreach (Order x in acct.Orders)
                                    {

                                        Print(x.Name);

                                    }
                                }

                            }
NT forum ref here: Sync-ing an always in strategy across weekends - [AUTOLINK]NinjaTrader[/AUTOLINK] Support Forum


However, it doesn’t appear to work in backtest. I’m assuming the “Accounts” is for live accounts only? Though it is funny I would have through there is some sort of backtest account. Any suggestions for backtest?

Thanks and regards,

drolles

Started this thread Reply With Quote
  #4 (permalink)
 
vvhg's Avatar
 vvhg 
Northern Germany
 
Experience: Intermediate
Platform: NT
Trading: FDAX, CL
Posts: 1,583 since Mar 2011
Thanks Given: 1,016
Thanks Received: 2,824


drolles View Post
Thanks for the prompt reply.

I think you might mean something like this:
 
Code
                 foreach (Account acct in Cbi.Globals.Accounts)
                            {
                                // do some stuff with the orders

                                if (acct.Orders != null)
                                {
                                    foreach (Order x in acct.Orders)
                                    {

                                        Print(x.Name);

                                    }
                                }

                            }
NT forum ref here: Sync-ing an always in strategy across weekends - [AUTOLINK]NinjaTrader[/AUTOLINK] Support Forum


However, it doesn’t appear to work in backtest. I’m assuming the “Accounts” is for live accounts only? Though it is funny I would have through there is some sort of backtest account. Any suggestions for backtest?

Thanks and regards,

drolles

What do you need unmanaged orders for in a backtest? I don't know much about strategies and backtests... @NJAMC or @Xav1029 should be more proficient regarding strategies.

What I was referring to was sth. like this:
 
Code
myorder = acct.CreateOrder(.....);
myorder.Submit();
vvhg

Hic Rhodos, hic salta.
Reply With Quote
  #5 (permalink)
 drolles 
London, UK
 
Experience: Beginner
Platform: TradeLink, OpenQuant, considering anything that works...
Trading: if it trades...
Posts: 94 since Oct 2010
Thanks Given: 24
Thanks Received: 39

Thanks for the prompt reply.

I’m ok on using managed. I have a situation where I’m looking to do multiple entries (against the same instrument). I’m doing some testing on some ideas ( Nuclear Phynance).

I was thinking that I would create a list of entryOrders, targetOrders and stopOrders; using a number to signify the entry number (e.g. Long Entry 1).

I would then check if each entryOrder is filled to determine if there is a corresponding target and stop order for the position. Something like this:
 
Code
foreach (IOrder x in entryOrders)
                            {

                                if (x != null)
                                {

                                    if (x.OrderState == OrderState.Filled)
                                    {

                                        // check to see if a stop / target exists if it does check it state to make sure it isn't fulled

                                        int orderNumber = Int32.Parse(x.Name.Substring(x.Name.Length - 1));


                                    }


                                }


                            }
But then I realised before I headed too far down that path that a filled entry order may not necessary correspond to a “Position”. A relationship I tried to explain to NT Support previously (that they are now fixing in V8 – see post 17 - trade lifecycle analysis - log file - [AUTOLINK]NinjaTrader[/AUTOLINK] Support Forum)

I think your solution is a great one for live positions (live meaning connected to an account like IB).

Cheers,

drolles

Started this thread Reply With Quote
  #6 (permalink)
 
Xav1029's Avatar
 Xav1029 
Tampa, FL
 
Experience: Beginner
Platform: NinjaTrader, Sierra Chart
Broker: Mirus Futures/Zen-Fire
Trading: 6E, M6E, 6J
Posts: 1,375 since Dec 2011
Thanks Given: 1,452
Thanks Received: 3,377

I don't do strategies either...I love the chart trader, so I've just been tweaking it lately to do some extra tricks like dataseries trails. I really don't know much about backtesting except that I was always rich after optimization

London Calling
Visit my NexusFi Trade Journal Reply With Quote
  #7 (permalink)
 drolles 
London, UK
 
Experience: Beginner
Platform: TradeLink, OpenQuant, considering anything that works...
Trading: if it trades...
Posts: 94 since Oct 2010
Thanks Given: 24
Thanks Received: 39

Possibly may be onto something. I've found an Orders collection in StrategyBase. I'm just determining how to use it.

Cheers,

drolles

Started this thread Reply With Quote
  #8 (permalink)
 drolles 
London, UK
 
Experience: Beginner
Platform: TradeLink, OpenQuant, considering anything that works...
Trading: if it trades...
Posts: 94 since Oct 2010
Thanks Given: 24
Thanks Received: 39

Tried these, but none of them worked.
 
Code
                            foreach (Execution x in this.Executions)
                            {

                                if (x.Name.Contains("Short Entry")) {
                                    Print(x.Name);
                                }
                            }

                            foreach (Order x in this.Orders)
                            {

                                if (x != null)
                                {

                                    Print(x.Name);

                                }

                            }
They all remain null even through there are positions live and executions have occurred.

Anyone with any ideas? All help greatly appreciated if we can put a work around in place prior to NT 8 coming out.

Cheers,

drolles

Started this thread Reply With Quote
  #9 (permalink)
 
ratfink's Avatar
 ratfink 
Birmingham UK
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: TST/Rithmic
Trading: YM/Gold
Posts: 3,633 since Dec 2012
Thanks Given: 17,423
Thanks Received: 8,425


Xav1029 View Post
I really don't know much about backtesting except that I was always rich after optimization

Absolutely. Shame more folks can't see it out of the box. If a feature is worthwhile and means something in a generic context then it always will, anything else is just fly-by-night/fly-by-wire/fly-by-seat-of-pants conformed noise. On the other hand I guess some manage to use it profitably so yet another example of what makes a market. Me, strictly discretionary.

Travel Well
Visit my NexusFi Trade Journal Reply With Quote
  #10 (permalink)
 drolles 
London, UK
 
Experience: Beginner
Platform: TradeLink, OpenQuant, considering anything that works...
Trading: if it trades...
Posts: 94 since Oct 2010
Thanks Given: 24
Thanks Received: 39


One possible solution I think I’ve come to is keeping a list of open execution.

That is when OnExecution is called to open a solution position (“Long Entry 1”) add it to a list for Open Executions.
 
Code
openExecutions.Add(execution);
Also we need to remove it when the execution is closed
 
Code
else if (execution.Order.Name != "" && (execution.Order.Name.Contains("Long Target") || execution.Order.Name.Contains("Long Target")))
                {

                    string orderNumber = execution.Order.Name.Substring(execution.Order.Name.Length - 1);

                    int indexNum = 0;

                    foreach (IExecution y in openExecutions)
                    {

                        if (y.Order.Name.Contains(orderNumber))
                        {
                            indexNum++;
                            break;
                        }

                        indexNum++;

                    }

                    openExecutions.RemoveAt(indexNum);

                }

It relies on the fact that we are keeping a unique number to append to the back of the IOrder text. I do this by just having a method to increment it each time it is called (might better doing it via a Property?).
 
Code
protected string GetOrderNumber(IOrder order)
        {

            return order.Name.Substring(order.Name.Length - 1);

        }
I think someone mentioned IOrder Tokens, I thought that Tokens were not always unique?

Any thoughts greatly appreciated.

Cheers,

drolles

Started this thread Reply With Quote
Thanked by:




Last Updated on April 18, 2013


© 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