• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Beginners programming in NinjaScript Editor enviroment

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

    Beginners programming in NinjaScript Editor enviroment

    I have a little bit of experience programming in Java and am making the transition to code in NinjaScript Editor and thus, in C#. I'm trying to make sense of it all from my Java background. If anyone wants to give any insights to the below questions/observations, please feel free as it would both help me clarify and give confidence to code in NS.

    1. It looks like all the code is done in the "parimary page" under namespace NinjaTrader.NinjaScript.Strategies. Can we safely say that this page is the executable page or the main method in Java where code is written?

    2. Speaking of main Methods, it looks like there are two primary methods, OnStateChange() and onBarUpdate(). It looks like onBarUpdate() is sort of like the Main Method where one would code what he/she wants the program to do in terms of implementing signals, and sending orders. This makes sense because on every update, new information is coming in which will be evaluated. Subsequently, if any are true, then orders would be sent out.


    It also looks like OnStateChange() is composed of 3 different main classes, SetDefaults, Configure, and DataLoaded. Furthermore...

    State.SetDefaults is where most default fields are set, and also variables you have initialized.

    (detour question: if I have Calculate set to "onEachTick", does the onBarUpdate mean that it will update as each new tick is seen? In this case, the "Bar" is each new price(or tick)

    State.DataLoaded looks to be drawings of indicators.

    State.Configure. I don't understand what this is for expect that's where stop loss and targets are set. What is this object? What does it do and why are stops and profit targets set here?

    I also don't understand the structure of if else-if statements these three objects are written here. It seems like the three objects are separate things and all of them can be true, not just one of them. Seems to me using three if statements would make more sense.

    3. Can you write separate classes in NinjaScript and use objects in the "primary page"? Or is it only limited to simple methods that one can write at the bottom and everything has to fit in one page - the "primary page"

    P.S. I was going to go with IB since they are Java based but their api is incredibly difficult for me to setup. In the end what I like about NT is that we only have to worry about writing the logic of the strategy and not have to worry about gateways, api, other technical necessities.

    Looking forward to everyone's thoughts

    #2
    Hello Boonfly8,
    Thanks for your post and welcome to the NinjaTrader forum.
    I will do my best to answer some of your questions below along with some links to our help guide documentation that will hopefully explain these items for you.

    1. It looks like all the code is done in the "primary page" under namespace NinjaTrader.NinjaScript.Strategies. Can we safely say that this page is the executable page or the main method in Java where code is written?
    Namespaces are more of a general C# item and I do not have any personal experience in Java. The main idea is that the Strategies namespace will be used for your strategies and the indicator namespace for indicators, and so on. I will ask my colleagues on how these two relate to one another and see if I can get a better explanation for you.
    2. Speaking of main Methods, it looks like there are two primary methods, OnStateChange() and onBarUpdate(). It looks like onBarUpdate() is sort of like the Main Method where one would code what he/she wants the program to do in terms of implementing signals, and sending orders. This makes sense because on every update, new information is coming in which will be evaluated. Subsequently, if any are true, then orders would be sent out. ......
    You are correct that OnBarUpdate() will be the main method you use to execute your logic, along with the other event driven methods. The best explanation will come for the help guide document that explains most of this.
    Help Guide - OnBarUpdate()
    Help Guide - OnStateChange()

    I am also linking you to the Educational Resources section of the Help Guide as it contains many useful topics to help you get started with NinjaScript: https://ninjatrader.com/support/help..._resources.htm

    As far as if else-if statements go, that would be more of a general c# topic. I suggest reading more about them at the following public link.
    https://docs.microsoft.com/en-us/dot...ywords/if-else
    3. Can you write separate classes in NinjaScript and use objects in the "primary page"? Or is it only limited to simple methods that one can write at the bottom and everything has to fit in one page - the "primary page"
    You are correct that you can write a new class in NinjaTrader. I am not familiar with the "Primary Page". Likely if what you are referring to can be done in C# it can also be done in NinjaScript.

    Please let me know if you have any questions or I left something out.
    Josh G.NinjaTrader Customer Service

    Comment


      #3
      OnBarUpdate is part of an eventloop call.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by sandman, Today, 02:32 PM
      0 responses
      1 view
      0 likes
      Last Post sandman
      by sandman
       
      Started by ksarin, Today, 12:39 PM
      3 responses
      12 views
      0 likes
      Last Post NinjaTrader_PatrickG  
      Started by ttodua, Today, 12:03 PM
      1 response
      6 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by tomtr27, Today, 11:35 AM
      1 response
      10 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by Uregon, Today, 07:30 AM
      2 responses
      13 views
      0 likes
      Last Post bltdavid  
      Working...
      X