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 f.saeidi, Today, 10:19 AM
    0 responses
    2 views
    0 likes
    Last Post f.saeidi  
    Started by kujista, Today, 06:23 AM
    4 responses
    15 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by traderqz, Yesterday, 09:06 AM
    2 responses
    16 views
    0 likes
    Last Post traderqz  
    Started by traderqz, Today, 12:06 AM
    3 responses
    6 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by RideMe, 04-07-2024, 04:54 PM
    5 responses
    28 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Working...
    X