Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

how to create an array of class objects - not synced to bars

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

    how to create an array of class objects - not synced to bars

    I am trying to set up a a short array of a few elements to hold objects that document events that I define and check for as they occur. I have tried a number of things but having no luck. I am new to C# and this platform.

    Is what I am trying to do possible in a Strategy? They don't seem to like my adding classes. Maybe they need to be "partial." I can get them to compile but then I have run time errors such as 'Can't put + sign in a name.' There is no plus signs anywhere.

    Any suggestions? Any sample code for doing this?

    Thank you.
    _________________________________________
    Thinking of something like this:

    IncidentID = IncidentArray[x].IncdID This to be accessible in places the body such as OnBarUpdate where I can use logic as part of trade decision.

    Where IncdID would be a property in the Class Incidents.

    public class Incidents
    {
    public int IncdID //these should be read only once populted in the class. Don't know if the {get; set;} is the approach to use.
    {get; set;}

    public string IncdKind
    {get; set;}

    // as many and needed

    public Incidents()
    {
    IncdID = 12;
    IncdKind = Std.dev(something) > Threshold;
    .
    .
    }

    I have not found a construction to seems to work in a Strategy that I could put into an array. I have looked at Struct for the object and Stack or List instead of Array. Not sure what kind of constructor to use for the Class.

    I discovered that when adding a class to a Strategy, additional instances of the Strategy show up in the chart's Strategy chooser. This does not appear to be something that users are expected to be doing.

    #2
    Hello JGRtrader,

    Thank you for the post.

    This question is more of a general C# question so you will find more help by searching online with google etc, for example "C# list of class". Here is one public tutorial: https://www.c-sharpcorner.com/Upload...ts-in-C-Sharp/

    There is a sample you can refer to as well, the sample level 2 order book which uses a class and list: https://ninjatrader.com/support/help...vel_ii_dat.htm

    You dont need to use a constructor at all if your use case does not require it.

    I discovered that when adding a class to a Strategy, additional instances of the Strategy show up in the chart's Strategy chooser. This does not appear to be something that users are expected to be doing.
    If you are appending : Strategy to your class it would show up in the UI, I would suggest to take a look at how the class is defined in the sample level 2 linked above and how it is private and also how it does not inherit from any other class.

    You can also use other types like an Array, here is a public sample of creating an array "c# array of class objects": http://www.functionx.com/csharp40/arrays/Lesson03.htm

    Please let me know if I may be of further assistance.

    Comment


      #3
      Thank you, this helped me a lot. In particular the NT indicator script "SampleLevel2Book" which uses on internal class and list. Right away, by seeing how that was done, I could see what some of my problem were. The other two sources were great too.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Today, 05:17 AM
      0 responses
      50 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      126 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      69 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      42 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      46 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X