Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

create an object or class

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

    create an object or class

    I was wondering if there was a way to create an object (or class i guess in C#) that would allow me store variables. For example I have this code

    if (condtionA == true)
    {
    objectA = new objectA();
    objectA.time = current_time
    objectA.entry_price = close[0];
    objectA.MA_level = ma(20);

    etc
    }

    the reason I need an object is that I store the objectA in an array and create a new object everytime the condtion occurs so I can store local information and preform calculations on the objects data.

    Any ideas how to do this in Ninja (i was previously doing it in javascript which allows for simple object creation in the script, not as a class)

    #2
    eurostoxx trader, I'm not familiar with JavaScript unfortunately, but to store data we offer so called Series objects, for example for double values - http://www.ninjatrader.com/support/h...ries_class.htm

    There int, bool, long, float, string and datetime series though available as well.

    You could though use an Array / ArrayList from C# as well.

    Comment


      #3
      Thank bertrand

      Do you know if I use an array list (great suggestion I forgot about those) can I re-use the same variable ...

      for example going back to the example

      // in the bar update part

      if (condtion1 = true)
      {
      ArrayList object_holder new ArrayList() // can i declare the variable here?
      object_holder.Insert( numbers etc ) // or add
      object_holder.insert(string values)
      }

      if (condtion 2 = true)
      {
      object_holder = "finished"
      object_holder_array.Add(object_holder) // also another array list i guess
      }

      Comment


        #4
        You would declare the list for example in your Initialize() and then fill in the OnBarUpdate() on your condition. You can add to the list from two conditions or if you would like to separate them fill two lists, up to you. We can't really support working out the bits & pieces with those more general C# classes, but there are some good example also found here on the forums posted by other members.

        Comment


          #5
          Originally posted by eurostoxx trader View Post
          I was wondering if there was a way to create an object (or class i guess in C#) that would allow me store variables. For example I have this code

          if (condtionA == true)
          {
          objectA = new objectA();
          objectA.time = current_time
          objectA.entry_price = close[0];
          objectA.MA_level = ma(20);

          etc
          }

          the reason I need an object is that I store the objectA in an array and create a new object everytime the condtion occurs so I can store local information and preform calculations on the objects data.

          Any ideas how to do this in Ninja (i was previously doing it in javascript which allows for simple object creation in the script, not as a class)
          1. Create a new namespace
          2. Create a struct to define your primitives, in the namespace
          3. Use the namespace in the indicator
          4. Create and use struct variables for your data in the indicator

          Comment


            #6
            Originally posted by eurostoxx trader View Post
            I was wondering if there was a way to create an object (or class i guess in C#) that would allow me store variables. For example I have this code

            if (condtionA == true)
            {
            objectA = new objectA();
            objectA.time = current_time
            objectA.entry_price = close[0];
            objectA.MA_level = ma(20);

            etc
            }

            the reason I need an object is that I store the objectA in an array and create a new object everytime the condtion occurs so I can store local information and preform calculations on the objects data.

            Any ideas how to do this in Ninja (i was previously doing it in javascript which allows for simple object creation in the script, not as a class)
            ninjascript is all C# so you can do whatever you like. a private or internal class is most often used, but if you serialize the same (or the same is one of the properties) then you have to create a separate namespace as koganam said.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            580 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            336 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            103 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            554 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            552 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X