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

Your preferred coding practice

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

    Your preferred coding practice

    I'm curious how people write their NinjaScript code. Specifically, wrt balancing all the List<T>, Series<T> etc with a well encapsulated script.

    I didn't realize how little I've actually worked with arrays within classes. I like how a List will persist inside a class, protected from the calling method, but it seems to me the performance hit will be huge when having to iteratively access and maintain that encapsulated list through the class' methods to add, move, delete, read etc all the elements in the List. It just feels wrong doing it this way.

    On the other hand, instantiating the List within the main class scope (Strategy) and constantly including that same List as a parameter when calling some class method seems redundant when the sole purpose for that class is to evaluate that List (and potentially altering it) for use in the Strategy class.

    Neither way seems appropriate for robust coding.

    Basically, I am writing a class that needs direct access to read all data in the Price, Time and Volume Series. From that data, the class will then create and maintain a much smaller List of values calculated from the Price, Time and Volume data. That class List will then need to be available for the calling (Strategy) class to iterate through.

    I know there are many ways to implement this. I am certain that there are others who have done similar things in their own code and just hoping for some other ideas since none of the implementations I've imagined are ideal.

    I don't really have any code to post as I'm still not sure which method to pursue.


    #2
    Can you provide links to any existing codes that demonstrate
    the different methods you're deciding upon?

    I would suggest:
    Study lots of C# source codes provided by reputable sources,
    look at how their code is organized -- follow their lead, adjusted
    for your own tastes. Wherever you deviate, make sure you have
    good reasons -- many professional software organizations have
    spent lots of money to develop their coding practices, you would
    be wise to ride their coat tails as much as possible. Regardless
    of whom you follow, consistency in your own code should be your
    number one rule.

    [I highly recommend that you find other C# resources and web
    sites, esp large C# code projects -- sounds like you need to be
    exposed to a lot more C# code examples. Seriously, you need
    to read a lot more code. You don't necessarily need to read and
    study the code for a deep understanding. I'm saying do that lazy
    'fast scan' kind of reading, just enough to decipher and under
    stand the code design and code organization. Find large open
    source projects written in C#
    and make a point to 'fast scan' them
    quickly, noting code readability choices that you like and dislike.
    Soon, patterns should emerge. Pay attention to those patterns.]

    -=o=-

    Btw, about your comment,

    "it seems to me the performance hit will be huge"

    I would caution you to remove such ideas from your
    thinking until you have done some profile testing or some
    performance timings to prove such allegations.

    Of course, code needs to run fast, but in most instances,
    software engineering would suggest that you should focus
    on correctness and readability, and other rules of thumb.

    One of the biggest rules of thumb I use is 'the future me'.
    I imagine myself having to come back to this code 3 or 5 or
    even 10 years from now. Will I quickly be able to read and
    understand it, does it need a comment (hmm, if so, maybe
    the variables need better names), is it well organized and
    nicely formatted, is it consistent? Am I proud of it? In other
    words, will the 'future me' enjoy reading it and much as the
    'present me' enjoyed writing it?

    Just my 2˘.

    Comment


      #3
      Hello Chippy,

      This would fall under general C# and not specific to NinjaScript. This thread will remain open for the community to answer.

      As a suggestion, you may want a partial class to share methods with multiple scripts.
      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

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by DJ888, 04-16-2024, 06:09 PM
      6 responses
      18 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by Jon17, Today, 04:33 PM
      0 responses
      1 view
      0 likes
      Last Post Jon17
      by Jon17
       
      Started by Javierw.ok, Today, 04:12 PM
      0 responses
      6 views
      0 likes
      Last Post Javierw.ok  
      Started by timmbbo, Today, 08:59 AM
      2 responses
      10 views
      0 likes
      Last Post bltdavid  
      Started by alifarahani, Today, 09:40 AM
      6 responses
      41 views
      0 likes
      Last Post alifarahani  
      Working...
      X