Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator with SMA

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

    Indicator with SMA

    I want to make an indicator something like the Ninja MACrossBuilder indicator...but with 4 different moving averages (instead of 2) plotting.

    I don't need to have the period, et cetera, selectable in the parameters...they would be fixed in the code as they don't change.

    Any examples to look at?

    #2
    Turtle Trader, I think you can take the template from Ryan here - http://www.ninjatrader.com/support/f...h=cross&desc=1

    and then just dont expose the parameters as public properties, but instead hardcode their values into the method calls.

    Of course you then also need to add extra plots as per your needs.

    Comment


      #3
      reply

      hi Bertrand,

      That link does not go anywhere, can you repost it?

      Thank you.

      Comment


        #4
        The link goes to our sharing, which contains an MA cross builder shared by our RyanM, this could be a template for your works - http://www.ninjatrader.com/support/f...catid=4&id=426

        Comment


          #5
          reply

          Hi Bertrand,

          I clicked again and the link worked...search results. thank you.

          Though, I'm a newbie a Ninja coder....can you give me an example of how to assign attributes, like Period, MA Type, et cetera, to a Plot in the code? And assign a DataSeries to a Plot?

          I've read the MA Cross Builder and don't see where those are being applied...they are in the parameters but not assigned to the DataSeries in the code..?

          And, how is a DataSeries applied to a Plot?

          Is there a class I can take to know these things?

          Thank you.

          Comment


            #6
            If you're new to coding in NinjaScript, best would be checking through those tutorials for indicator coding we have prepared - http://www.ninjatrader.com/support/h.../tutorials.htm

            Those would cover the basics needed for custom work and modifications.

            The MA Builder code shared uses so called user defined inputs to set paramters - a tip in the education section explains those further - http://www.ninjatrader.com/support/f...ead.php?t=5782

            If you just want to hardcode a period in, then assign the parameter in your MA method call for example - double mySMA = SMA(Close, 10)[0]; >> here the period is hardcoded to 10, there be no exposed user input dictating what is used, it will always be the coded in 10.

            Comment


              #7
              thank you

              thank you Bertrand

              Comment


                #8
                You're welcome, if you run into any walls on this project please post and let us know.

                Comment


                  #9
                  unable to get attached code to plot....

                  four SMAs in one indicator....probably a simple error....or left something out???

                  thank you!
                  Attached Files

                  Comment


                    #10
                    Looks to be just a simple issue in your plot width assignments in the Initialize(), please try instead here -

                    Plots[0].Pen.Width = 2;
                    Plots[1].Pen.Width = 2;
                    Plots[2].Pen.Width = 2;
                    Plots[3].Pen.Width = 2;

                    Comment


                      #11
                      where?

                      Hi Bertrand,

                      Yes, it appears the Pen.Width assignment should not be in the Initialize...but your message didn't state where to put them...

                      :-)

                      thank you.

                      Comment


                        #12
                        That's not the point, they can either go to OnStartUp() or Initialize(), but you've had incorrect index values assigned - so your last one pointed to a Plot array of 4 which does not exist > hence your issue loading the indicator, there was a corresponding Log tab entry noted by NT as well on it. If you use my version posted, it would work.

                        Comment


                          #13
                          I am an idiot!

                          come from a programming background where 0 is not a valid index....my brain was in two places...thank you!!

                          :-)

                          Comment


                            #14
                            No worries, glad to assist.

                            Comment


                              #15
                              ....

                              Next time I'm in Berlin I will buy you a beer...

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              571 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              330 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              101 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              548 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              548 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X