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

Samples of building classes

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

    Samples of building classes

    Are there any sample scripts that build/initialise/discuss custom classes in NT8?

    just need something simple to help me get started e.g.

    myClass mc = new myClass();

    public class myClass
    {
    private int _capacity = 100;
    }

    and how it fits into the existing NT8 script?
    Last edited by dibDab; 09-26-2023, 01:20 PM.

    #2
    Hello dibDab,

    This is general C# education and is not necessary to learn to create NinjaScripts.

    I would recommend a C# tutorial on classes or formal C# class to learn the ins and outs of programming custom C#.

    I do have an example of partial classes you may find interesting.
    Explanation: I wrote a base class Indicator class that I'm using to inherit all my other indicators from. So this baseclass is defined as: namespace NinjaTrader.NinjaScript.Indicators.AssistedTrades { public class ATBaseIndicator: Indicator { ... } } And any other indicator is defined as: namespace NinjaTrader.NinjaScr
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Study the file @TrendLines.cs in the Indicators folder.

      Comment


        #4
        I understand I'm bordering on c# type questions but if possible can I ask where is the best place in ninjascript indicator code to

        1. create: private object[,] ctrl = new object[3,5]; (e.g. class member of public class myIndicator : Indicator)

        2, initialise ctrl (e.g. IsFirstTickOfBar and CurrentBar == 0)
        Last edited by dibDab; 09-27-2023, 07:25 AM.

        Comment


          #5
          Hello dibDab,

          Declare the variable in the scope of the class. (Between the curly braces of the class)
          Assign the variable an instantiated object in State.DataLoaded.

          In the scope of the class:
          private int[,] ctrl;

          In the scope of State.DataLoaded in OnStateChange():
          ctrl = new int[,] { {3,5} };
          Chelsea B.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by sofortune, Today, 10:05 AM
          3 responses
          15 views
          0 likes
          Last Post NinjaTrader_ChristopherJ  
          Started by ETFVoyageur, 05-07-2024, 07:05 PM
          23 responses
          184 views
          0 likes
          Last Post ETFVoyageur  
          Started by reynoldsn, 05-10-2024, 07:04 PM
          7 responses
          39 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by ETFVoyageur, Today, 02:15 AM
          5 responses
          31 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by drnoggin, Today, 12:19 PM
          1 response
          14 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X