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

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.
    JesseNinjaTrader Customer Service

    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 cmtjoancolmenero, Yesterday, 03:58 PM
      1 response
      17 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by benmarkal, Yesterday, 12:52 PM
      3 responses
      23 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by helpwanted, Today, 03:06 AM
      1 response
      20 views
      0 likes
      Last Post sarafuenonly123  
      Started by Brevo, Today, 01:45 AM
      0 responses
      12 views
      0 likes
      Last Post Brevo
      by Brevo
       
      Started by pvincent, 06-23-2022, 12:53 PM
      14 responses
      244 views
      0 likes
      Last Post Nyman
      by Nyman
       
      Working...
      X