• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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 TazoTodua; 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 fredfred, Today, 03:41 AM
    0 responses
    1 view
    0 likes
    Last Post fredfred  
    Started by TraderYoda, Today, 03:33 AM
    0 responses
    0 views
    0 likes
    Last Post TraderYoda  
    Started by pjsmith, Today, 02:56 AM
    0 responses
    2 views
    0 likes
    Last Post pjsmith
    by pjsmith
     
    Started by ntbone, Yesterday, 08:10 PM
    0 responses
    9 views
    0 likes
    Last Post ntbone
    by ntbone
     
    Started by chrislou, 08-28-2015, 03:27 AM
    14 responses
    2,882 views
    0 likes
    Last Post nkhoi
    by nkhoi
     
    Working...
    X