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 vvhg with 2 posts (1 thanks)
    3. looks_3 diagonAlley with 2 posts (0 thanks)
    4. looks_4 Jaba with 2 posts (4 thanks)
    1. trending_up 5,975 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?

  #11 (permalink)
 kelvin2088 
Los Angeles, CA, USA
 
Experience: Advanced
Platform: Interactive Brokers
Trading: YM
Posts: 7 since Dec 2012
Thanks Given: 2
Thanks Received: 0

haha drolles,
i guess we r targeting the same problem here.
i'll follow u here and in nt forum. good luck!




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


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
REcommedations for programming help
Sierra Chart
PowerLanguage & EasyLanguage. How to get the platfor …
EasyLanguage Programming
ZombieSqueeze
Platforms and Indicators
MC PL editor upgrade
MultiCharts
Exit Strategy
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
31 thanks
Spoo-nalysis ES e-mini futures S&P 500
29 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
20 thanks
GFIs1 1 DAX trade per day journal
17 thanks
  #12 (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've found a better solution for parsing the number from the order number string. I would recommend this method above the previous one posted. The previous isn't as robust.

 
Code
protected string GetOrderNumber(IOrder order)
        {

            string b = string.Empty;

            for (int i = 0; i < order.Name.Length; i++)
            {
                if (Char.IsDigit(order.Name[i]))
                    b += order.Name[i];
            }

            return b;

        }

Ref: .net - c# find and extract number from a string - Stack Overflow

Started this thread Reply With Quote
  #13 (permalink)
diagonAlley
Milan, Italy
 
Posts: 2 since Apr 2012
Thanks Given: 1
Thanks Received: 0


Hallo friends,

thank you for this interesting thread. How difficult it is to find the right indications sometimes...!

I posted a -still unanswered- thread on Ninja forum, (though my username there is different). I cannot paste links here because I am newbie, but it goes about "Managing multiple trades without string names".

From what I have read here, it seems that the only solution is parsing strings, is it correct?

Any further suggestions?

Bye

F

Reply With Quote
  #14 (permalink)
 Jaba 
Austin TX
 
Experience: Intermediate
Platform: SaintGobain Crystal Ball
Trading: 6E
Posts: 81 since Oct 2010
Thanks Given: 103
Thanks Received: 134

Not sure about backtesting but the following will work in a live scenario:

In OnStartUp() method subscribe to the Execution event

 
Code
acct.Execution += new Cbi.ExecutionUpdateEventHandler(ExecutionUpdateHandler);
Then watch for the events:
 
Code
        List<Order> orderList = new List<Order>();
        private void ExecutionUpdateHandler(object sender, ExecutionUpdateEventArgs e)
        {
            Print("Execution Event: " + e.ToString());
            bool orderExists = false;
            foreach(Order _ord in orderList)
            {
               if( _ord.OrderId == e.Execution.Order.OrderId)
               {
                   _ord.OrderState = e.Execution.Order.OrderState;
                   orderExists = true;
                   break;
               }
            }
            if (orderExists == false)
            {
                orderList.Add((Order)e.Execution.Order);
            }
                              
        }
finally, important, in OnTermination() unsubscribe:

 
Code
acct.Execution -= ExecutionUpdateHandler;
This should populate the list with new Orders and modify the existing ones. There might be some typos in the code, but that's the general idea. Use at your own risk.

Here are some others to play with:

 
Code
	a.OrderStatus += new Cbi.OrderStatusEventHandler(OrderStatusUpdateHandler);
	private void OrderStatusUpdateHandler(object sender, OrderStatusEventArgs e) 
	{
                 	 Print("Order Update event:  " +e.ToString());
	}

	a.PositionUpdate += new Cbi.PositionUpdateEventHandler(PositionUpdateHandler); 
	private void PositionUpdateHandler(object sender, PositionUpdateEventArgs e)
	{
		Print("Position Update event:  " +e.ToString());
	}

	a.AccountUpdate += new Cbi.AccountUpdateEventHandler(AccountUpdateHandler);
	private void AccountUpdateHandler(object sender, AccountUpdateEventArgs e)
	{
		Print("Account Update event:  " +e.ToString());
	}

	a.Connection.ConnectionStatus += new Cbi.ConnectionStatusEventHandler(ConnectionStatusHandler);
	private void ConnectionStatusHandler(object sender, ConnectionStatusEventArgs e) 
	{
		Print("Connection Status event:  " +e.ToString() +a.Connection.Accounts);
	}

	// don't forget to clean up:
	protected override void OnTermination()
	{
		Print("Removing event handlers from account " +a.Name);
		a.Execution -= ExecutionUpdateHandler;
		a.OrderStatus -=  OrderStatusUpdateHandler;
		a.PositionUpdate -= PositionUpdateHandler;  // AccountUpdate
		a.AccountUpdate -= AccountUpdateHandler;
		a.Connection.ConnectionStatus -= ConnectionStatusHandler;
	}
Good luck.
J

Reply With Quote
  #15 (permalink)
diagonAlley
Milan, Italy
 
Posts: 2 since Apr 2012
Thanks Given: 1
Thanks Received: 0

Thank you J,

I will try it!

Reply With Quote




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