• 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

SMA code

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

    SMA code

    Ninja comes with an SMA indicator which uses sum and prior sum etc. When I look in the support guide/system indicator methods/moving average simple, I see code in the style
    SMA(int period).
    I am trying to learn to code ninja script and started with just an SMA using the wizard I added 1 line, then entered the following custom logic
    double GregSMALine = SMA(Close, 14)[0];
    This compiles okay, but nothing shows on the chart. Can someone please tell me what else needs to be done to get this to plot. I have attached an exported indicator file for anyone that can help . I appreciate all the help I can get. Thanks.
    Attached Files

    #2
    Hello, thanks for your post.

    You must set up a plot with AddPlot and then fill in the Value[] array. Study the source code for the SMA indicator. In State.SetDefaults a plot is added with AddPlot, then the Value[0] array section is filled for every bar.

    Please let me know if I can assist any further.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Thanks Chris.
      First of all I notice the Ninja supplied source code doesn't have the line
      LineName = SMA(Close, 14)[0];
      appearing in it.
      The wizard already added the line
      AddPlot(Brushes.Yellow, "GregSMALine");
      to my code.

      I studied the section for AddPlot but still don't understand the Value[0] array. I'm coming from easylanguage where Average(Price, Length); calls a function and the only other thing to do is to define the Input 'length', initialize the variable to (0), and set a plot statement. I was hoping to be able to define the SMA with just the line
      double GregSMALine = SMA(Close, 14)[0];
      and the AddPlot line would produce a plot of that formula.

      I tried adding
      Values[0][0] = GregSMALine[0];
      as that is the example for an Indicator which adds three value series - but that didn't work.

      Are you saying I have to ALL the code from your standard SMA indicator. That would be the CurrentBar == 0, If currentBar
      >= Period, AND the (IsFirsttickOfBar) section? If so, then why do I need double GregSMALine = SMA(Close, 14)[0];

      By the way, Is there some tutorial that will get me through this learning curve without bothering you guys a thousand times?
      Thanks.


      Comment


        #4
        Hello Woomera,

        Thanks for your reply.

        With reference to the code you post, You only need to change this line: double GregSMALine = SMA(Close, 14)[0];
        to look like this: GregSMALine[0] = SMA(Close, 14)[0];

        When you create a plot, the plot will have as many bars/slots as the data series so you need to tell the plot on each new bar, what value to plot the line at. What the new line is saying is
        Plot the current bar [0] of the plot named GregSMALine with the current bar value[0] of the 14 period SMA of the close data series.

        NinjaScripts are built on C#. While we do not provide programming education services in the Support Department, there are a vast number of educational C# resources external to NinjaTrader and we do have some tutorials and tools that can assist in the learning process.

        Many users report that a good way to start before fully learning C# is to go through the NinjaTrader 7 NinjaScript tutorials in the help documentation to get a fundamental grasp on .NET framework and how it is used in NinjaScript. From there I suggest looking at the Code Breaking changes for NinjaTrader 8 to understand the differences between NinjaTrader 7 and NinjaTrader 8. You can view the tutorials for NinjaTrader 7 here: https://ninjatrader.com/support/help...?tutorials.htm

        Although we do not currently provide NinjaScript tutorials like in NinjaTrader 7, we do provide in-depth help documentation on developing NinjaScripts for NinjaTrader 8. We also provide samples and a complete reference of the language. More in depth educational resources can be found elsewhere throughout the internet. You can find the educational resources here: http://ninjatrader.com/support/helpG..._resources.htm

        Once you have a basic understanding of C#, I suggest following the documented Code Breaking changes between NinjaTrader 7 and NinjaTrader 8. This page also gives an overview for NinjaScripts in NinjaTrader 8. You can find the Code Breaking changes here: http://ninjatrader.com/support/helpG...ng_changes.htm

        Other users have wrote in about this information in our support forums here: https://ninjatrader.com/support/foru...d.php?p=488807

        Also available are webinars on the NinjaScript editor and the Strategy Builder. The Strategy Builder can be used to generate NinjaScript syntax for NinjaScript strategies. You may wish to create a strategy and clicking View Code after each piece of logic created in the Builder to observe the generated syntax.
        Strategy Builder 301: https://www.youtube.com/watch?v=HCyt90GAs9k
        NinjaScript Editor 401: https://www.youtube.com/watch?v=K8v_2ONBbqI
        You can register for live webinars here: https://ninjatrader.com/PlatformTraining

        Our documentation will be your best friend while developing, and the complete supported NinjaScript interface can be referenced here: http://ninjatrader.com/support/helpGuides/nt8/en-us/
        The information above is publicly available.

        Finally, we also have a vast EcoSystem of NinjaScript Consultants that would be happy to write or modify any NinjaScript at your request. If those services interest you, we can have a representative of our EcoSystem reach out with more information.

        Please let us know if we can be of further assistance.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Thanks Paul H. Changing that one line to the version you suggested worked fine. I did not think to go to the version 7 help info to read tutorials there as I see all the code breaking changes listed in the version 8 help, and I am using version 8. I will go away and study it all now you have shown me where to look.
          Thanks again.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by gbulle, Today, 01:17 PM
          4 responses
          13 views
          0 likes
          Last Post gbulle
          by gbulle
           
          Started by CougarMountain, Today, 03:55 PM
          0 responses
          4 views
          0 likes
          Last Post CougarMountain  
          Started by syxforex, Today, 01:13 PM
          3 responses
          12 views
          0 likes
          Last Post NinjaTrader_PaulH  
          Started by pjsmith, Today, 01:17 PM
          2 responses
          6 views
          0 likes
          Last Post pjsmith
          by pjsmith
           
          Started by syxforex, Today, 01:17 PM
          2 responses
          6 views
          0 likes
          Last Post syxforex  
          Working...
          X