Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Array of trades

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Array of trades

    Hi.

    I know how to do it with doubles:

    Code:
    private double[] MyArray;
    protected override void Initialize()
    {
    	MyArray = new double[100];
    }
    
    //then I can access them using  MyArray[x]
    however, I want to store Orders, how to do that?

    Code:
    MyOrders["stop1"] = ExitLong(.....)
    MyOrders["stop2"] = ExitLong(.....)
    then I could access that later in Foreach, like:

    Code:
    foreach (string oName in MyOrders) {
      xyz= MyOrders[oName ].Quantity;  
      // etc..
    }
    Last edited by ttodua; 06-05-2017, 04:35 AM.

    #2
    Hello selnomeria,

    Thanks for opening the thread.

    You could use an array of Order objects, or you may wish to use a Dictionary if you would like to easily reference your collection of orders by name.

    You could reference the following syntax:

    Code:
    private Dictionary<string, Order>						myOrders;
    private Order[]											MyArrayOrders;
    Code:
    protected override void OnStateChange()
    {
    	...
    	else if (State == State.Configure)
    	{
    		myOrders = new Dictionary<string, Order>();
    		MyArrayOrders = new Order[10];
    	}
    Using a Dictionary:
    Code:
    protected override void OnBarUpdate()
    {
    	Order myTempOrder;
    	string myTempTag = "Tag";
    	myTempOrder = EnterLong(myTempTag);
    	
    	myOrders.Add(myTempTag, myTempOrder);
    	
    	foreach(KeyValuePair<string, Order> kvp in myOrders)
    	{
    		if( kvp.Key == "Tag" )
    			myTempOrder = kvp.Value;
    	}
    Using an Array:
    Code:
    protected override void OnBarUpdate()
    {
    			
    	MyArrayOrders[0] = EnterLong("MyTag");
    			
    	foreach( Order thisOrder in MyArrayOrders)
    	{
    		if( thisOrder.Name == "MyTag" )
    			Print(thisOrder.Name);
    	}
    Arrays and various types of Collections are extensively documented by Microsoft. You can reference their complete documentation for in depth explanations and examples below:

    Arrays: https://docs.microsoft.com/en-us/dot...e/arrays/index

    Dictionary's: https://docs.microsoft.com/en-us/dot...tframework-4.7

    Collections: https://docs.microsoft.com/en-us/dot...ts/collections

    Please let me know if I can be of further help.
    JimNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by DJ888, 04-16-2024, 06:09 PM
    6 responses
    18 views
    0 likes
    Last Post DJ888
    by DJ888
     
    Started by Jon17, Today, 04:33 PM
    0 responses
    1 view
    0 likes
    Last Post Jon17
    by Jon17
     
    Started by Javierw.ok, Today, 04:12 PM
    0 responses
    6 views
    0 likes
    Last Post Javierw.ok  
    Started by timmbbo, Today, 08:59 AM
    2 responses
    10 views
    0 likes
    Last Post bltdavid  
    Started by alifarahani, Today, 09:40 AM
    6 responses
    41 views
    0 likes
    Last Post alifarahani  
    Working...
    X