Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to Start

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

    How to Start

    So this is a more general questions and I would like those who have gone down the path I'm about to go to share their experiences and insights.

    I have a little background in programming Java (no C# or Visual Basic experience at all) and I have been playing around C# using VB to get myself familiar with the language. Turns out that C# is pretty similar to Java and in some cases easier as well (properties in C# are super handy when writing getters and setters). And I will continue to do that for some additional time. I will list some of the topics that I have working knowledge in Java and are now basically "transferring" them to C# syntax

    1. Decision Structures such as if /if-else, nested if, switch
    2. loops (while, do-while, for)
    3. Methods and classes and inheritance (superclass, interface, override, overload, etc)
    4. Arrays
    5. Exception handling

    I have been watching some videos and been on some webinars that involve Ninjascript and it looks like (correct me if I'm wrong), that with the working knowledge that I have, I might as well just dive in and get started to write some code for strategy ideas that I have. What do you guys think? I guess I just need some opinion on next steps.

    By the way, using VB is great as it has an output console you can see if what you coded is what you expect. In NT, when you write your own code outside of strategy builder, what do you guys to check the work? Do you just write the code and see the print outs in the output window?

    Do any of you guys use VB environment to code(I'd like to know how since I'm already a little familiar with VB)? What is the process of hooking up NT to VB and how to get the code back to NT?

    Also, for those experience coders, what are some of the common methods that you see yourself keep using or have to use?

    Thanks for the input! Excited to get started very soon.

    #2
    Hello Boonfly8,

    This thread will remain open for any community members that would like to provide input.

    Below I am linking a forum post with helpful tips about getting started with NinjaScript.
    http://ninjatrader.com/support/forum...609#post503609
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello Boonfly8,

      This thread will remain open for any community members that would like to provide input.

      Below I am linking a forum post with helpful tips about getting started with NinjaScript.
      http://ninjatrader.com/support/forum...609#post503609
      Hi Chelsea thx for the note, what are your thoughts on those topics / questions

      Comment


        #4
        Hello Boonfly8,

        I cannot comment on Java or Visual Basic.

        For branching commands, loops, arrays, method, classes, and try and catches (which are not recommended in a NinjaScript Strategy as this prevents the information from going to the log) I would recommend using the dot net pearls resource I have linked in the post.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ChelseaB View Post
          ... try and catches (which are not recommended in a NinjaScript Strategy as this prevents the information from going to the log) I would recommend using the dot net pearls resource I have linked in the post.
          Strange statement, as the following pages, among others, from the official NT documentation would appear to contradict that statement.

          ref: https://ninjatrader.com/support/help...tch_blocks.htm
          https://ninjatrader.com/support/help..._practices.htm

          Comment


            #6
            Hello koganam,

            I think of using try and catches as advanced programming.
            You can use any code you want really.

            But, anything in a try that errors, will not be logged. When sending log and trace information, those try and catches are almost never used with log calls or prints the error information in a way our support can figure out what is going on and requires much more in-depth assistance.

            Yes, you are free to use these. But allowing the script to error and log the information is much more helpful to our support staff.

            So in general, we try and have coders below expert level avoid them.

            Also, take a look at the heading 'Properly implementing try/catch blocks' in the help guide page you have linked. The code block is labelled 'Practice to avoid' and there is a note 'Larger try-catch blocks can not only be harder to debug, but can introduce performance issues at run-time'.
            Last edited by NinjaTrader_ChelseaB; 07-05-2018, 07:59 AM.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by Boonfly8 View Post
              By the way, using VB is great as it has an output console you can see if what you coded is what you expect. In NT, when you write your own code outside of strategy builder, what do you guys to check the work? Do you just write the code and see the print outs in the output window?
              You can go a long way just using the output window. However, you can also attach the Visual Studio debugger to NinjaTrader and step through a strategy's execution line-by-line.

              Here's a video that shows how to get started: https://www.youtube.com/watch?v=olIwH8XtKJs

              Originally posted by Boonfly8 View Post
              Do any of you guys use VB environment to code(I'd like to know how since I'm already a little familiar with VB)? What is the process of hooking up NT to VB and how to get the code back to NT?
              By "VB environment", do you mean Visual Studio? If not, then I highly recommend using Visual Studio to edit your strategies. The code navigation tools are lot better than NinjaTrader's built in Strategy Editor. It may be a little overwhelming because it has a lot of bells and whistles. But I think it's worth the learning curve.

              Originally posted by Boonfly8 View Post
              Also, for those experience coders, what are some of the common methods that you see yourself keep using or have to use?
              Hmm, here's a pattern that I use often is to extract the logic to manage orders into a helper method. Here's what that looks like:

              Code:
              protected override void OnBarUpdate()
              {
                  if (BarsInProgress != 0)
                      return;
              
                  if (CurrentBars[0] < DMLength)
                      return;
              
                  ManageOrders();
              
                  if (IsRising(Close)
                      && DMI.DiPlus[0] > DMI.DiMinus[0] 
                      && IsRising(DMI.ADXPlot))
                  {
                      EnterLong();
                  }
              
                  if (IsFalling(Close)
                      && DMI.DiPlus[0] < DMI.DiMinus[0]
                      && IsRising(DMI.ADXPlot))
                  {
                      EnterShort();
                  }
              }
              
              private void ManageOrders()
              {
                  if (Position.MarketPosition == MarketPosition.Long && IsFalling(Close) == true)
                  {
                      ExitLong();
                  }
              
                  if (Position.MarketPosition == MarketPosition.Short && IsRising(Close) == true)
                  {
                      ExitShort();
                  }
              }

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by demarcog, Today, 05:40 PM
              5 responses
              19 views
              0 likes
              Last Post demarcog  
              Started by cincai, Today, 08:16 PM
              0 responses
              6 views
              0 likes
              Last Post cincai
              by cincai
               
              Started by cincai, Today, 08:04 PM
              0 responses
              1 view
              0 likes
              Last Post cincai
              by cincai
               
              Started by demarcog, Today, 06:23 PM
              0 responses
              5 views
              0 likes
              Last Post demarcog  
              Started by canliyayin, Today, 05:56 PM
              0 responses
              4 views
              0 likes
              Last Post canliyayin  
              Working...
              X