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

Newbie programming question

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

    Newbie programming question

    Hello,
    It seems to me at first like a mountain to climb to learn how to write code to backtest in Ninja. Is there a good manual of the language with examples? If someone has time, what is the complete code to backtest a very simple system like:

    -----
    condition: close of this bar > close of previous bar
    If condition then buy the open of next bar
    limit order at entry price + 10 pips
    stoploss order at entry price - 10 pips
    -----

    Thanks

    #2
    jimthetrader,

    The best place to start would be the Strategy Wizard tutorials. From there you can use the wizard and then press View Code to get a feel for the syntax. After that you can move on to trying your own code. The Help Guide is the best place for resources as well as the support forums. There is a section here called Reference Samples which has a lot of code examples too.

    Good luck.

    Wizard tutorials: http://www.ninjatrader-support.com/H...tml?Overview34
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Learning Ninjascript

      I think it is very worthwhile to make an effort to understand at least the basics of C#. The various posts on this site shows how much can be done with Ninja.

      I would recommend the Visual C# Videos on the MSDN site and the Sams book Teach Yourself the C# language in 21 days. LearnVisualStudio.Net also has some excellent videos as well.

      For the Forum moderators:- I have noticed this question comes up frequently. How can I learn NinjaScript? I think it would help your business model greatly if some effort was put into producing webinars/seminars on learning C# with reference to programming in Ninja. I cannot believe it would cost a lot of money to produce two or three hours videos for example which would cover the basics etc. These could be available online freely and if allowed to be downloaded and copied freely, would they not also serve as very effective advertising for your product?

      You will be aware that one of your competitors have produced various detailed manuals on the language involved and another has produced about ten hours on video instruction on using their scripting language all free.

      Comment


        #4
        Thank you for the suggestion. We are always continually improving our educational resources. We will add this to the list of future considerations.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Josh View Post
          jimthetrader,

          The best place to start would be the Strategy Wizard tutorials. From there you can use the wizard and then press View Code to get a feel for the syntax. After that you can move on to trying your own code. The Help Guide is the best place for resources as well as the support forums. There is a section here called Reference Samples which has a lot of code examples too.

          Good luck.

          Wizard tutorials: http://www.ninjatrader-support.com/H...tml?Overview34
          I'm new to automated programming and I'm currently trying to choose between 4 candidate platforms. Before I start investing time in reading books and manuals, I'd like to see how complicated is to write code. One of the companies responded same day with the complete code for the example I presented. I work in marketing and I don't think it's a good idea to tell to a prospective customer to go read the manual or find himself the answers to his questions.

          Jim

          Comment


            #6
            Jim,

            If you just want to see what code looks like there are many examples in the file sharing section you can download and examine. You can also check out the reference samples section of the forums to see how different types of strategies can be created too. Unfortunately we do not offer custom programming services.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Do you think that by asking you for the full code of a trivial system I am asking you for custom programming services? This is for laughs. My customers are very sophisticated traders but they are not programmers.
              Your platform was just rejected as a potential solution for the business I consult due to an unwillingness to provide basic support to a prospective buyer.
              If you do not care about getting any new customers, that's good for you, it means you are doing very well.
              If this trivial system could be easily programmed in your platform it would take you less time to do it than to respond as you did.
              Which is an indication that you tried to avoid it.
              Bye

              Comment


                #8
                Originally posted by jimthetrader View Post
                Do you think that by asking you for the full code of a trivial system I am asking you for custom programming services? This is for laughs. My customers are very sophisticated traders but they are not programmers.
                Your platform was just rejected as a potential solution for the business I consult due to an unwillingness to provide basic support to a prospective buyer.
                If you do not care about getting any new customers, that's good for you, it means you are doing very well.
                If this trivial system could be easily programmed in your platform it would take you less time to do it than to respond as you did.
                Which is an indication that you tried to avoid it.
                Bye
                It is pretty simple to do. I'm not surprised that NT don't maintain programming resource to code up simple strategies for any prospective buyer who asks. You can see easily from any of the examples how easy things are. I was new to automated trading when I first looked at Ninja script. It took ten mins of looking through the list of library routines to realise what the capabilties are.

                I mean, are these names not pretty clear?

                EnterLong
                ExitShort
                SetStopLoss
                OnBarUpdate
                Rising
                CrossAbove
                High
                Open
                Close
                etc

                Comment


                  #9
                  A good place to start would be this link - http://www.ninjatrader-support.com/H...verview39.html
                  One basic strategy tutorial for the wizard, and a slightly more advanced one using the full NinjaScript editor with custom coding.
                  BertrandNinjaTrader Customer Service

                  Comment


                    #10
                    Jim.
                    Hmm.. This is something I hear frequently from sales and marketing guys in my line of business.

                    "Can you write this for us for free before we buy your product then we'll decide if we should buy your product, it won't take you long. Oh yeh and can you make sure that this can be done for our customers for free cos they just trade and don't want to learn how anything works, they just hit the go button."

                    Come off it. If you were serious about finding platforms for your "sophisticated" investors then you would be sending someone with an existing knowledge of coding to do the research for you for any of the platforms you say you are investigating.

                    I'm reasonably new to Ninja Trader but have developed in C# for a number of years and can safely say that because NT is using C# and not it's own "secret coding language", that it therefore has endless possibilities when it comes to developing Automated trading and other extraneous apps.

                    So my advice is either make an effort to learn something or don't. Seems you'll be the loser if you don't.




                    Originally posted by jimthetrader View Post
                    Do you think that by asking you for the full code of a trivial system I am asking you for custom programming services? This is for laughs. My customers are very sophisticated traders but they are not programmers.
                    Your platform was just rejected as a potential solution for the business I consult due to an unwillingness to provide basic support to a prospective buyer.
                    If you do not care about getting any new customers, that's good for you, it means you are doing very well.
                    If this trivial system could be easily programmed in your platform it would take you less time to do it than to respond as you did.
                    Which is an indication that you tried to avoid it.
                    Bye

                    Comment


                      #11
                      Capabilities of Ninja

                      As is often said Ninja, since it is written in C# can be made to do allmost anything. So where should the line be drawn on answering some quite complicated C# questions at times?

                      It shouldn't be forgotten that Ninja is provided free for development purposes etc unlike many platforms. I wonder how many people on this forum asking questions of the Ninja people have actually paid Ninja for the use of their system? Obviously they can only spend so much resources answering questions etc.

                      Unlike some forums, Ninja do not lock people out that do not buy their product. They even actually answer questions, in a very short time as well.

                      However as stated below I do think the information provided on Ninja could be improved at both a basic and advanced level.

                      Comment


                        #12
                        Originally posted by MicroAl View Post

                        I have noticed this question comes up frequently. How can I learn NinjaScript? I think it would help your business model greatly if some effort was put into producing webinars/seminars on learning C# with reference to programming in Ninja. I cannot believe it would cost a lot of money to produce two or three hours videos for example which would cover the basics etc. These could be available online freely and if allowed to be downloaded and copied freely, would they not also serve as very effective advertising for your product?

                        You will be aware that one of your competitors have produced various detailed manuals on the language involved and another has produced about ten hours on video instruction on using their scripting language all free.
                        hear , hear.
                        And don't just stop at the basics.
                        My experience with Tradestation (5 yrs) is that as the forum members skill level goes up the calls on the administrators/moderators goes down as most people are willing to assist newbies with the fairly basic stuff.

                        Why not have dual levels of forum membership - paid and unpaid?

                        Comment


                          #13
                          I absolutely agree with you here..
                          2 of my colleagues merely use NT free for charting purposes and are complete ludites when it comes to programming, however they are learning to use NT and learning how to use the wizards as we are co developing auto strategies as a group and even they see the benefit in learning at least the basics of what they call NinjaScript and I call C# (It makes it easier for them to digest if they call it NinjaScript instead of C# for some reason )
                          I myself used it free for a while, while I was learning to trade and am now a fully paid up owner and do believe that it is not only the best dollar value trading/charting s/w on the market but also the most versatile and because of it's no fuss approach to using C# as it's "Ninja Script" the one with the most readily available tutorials either in their library or thousands of other C# repositories.
                          About support too.. I do not know of any other company that I have sent a programming support request on Easter sunday and had a reply in an hour or so from actual staff not just other forum members. This question was of a programming structure nature not a direct NT library nature and the examples I was directed to helped me out no end. All I can say to this is good on you guys and keep up the good work.

                          Cheers

                          Chris



                          Originally posted by MicroAl View Post
                          As is often said Ninja, since it is written in C# can be made to do allmost anything. So where should the line be drawn on answering some quite complicated C# questions at times?

                          It shouldn't be forgotten that Ninja is provided free for development purposes etc unlike many platforms. I wonder how many people on this forum asking questions of the Ninja people have actually paid Ninja for the use of their system? Obviously they can only spend so much resources answering questions etc.

                          Unlike some forums, Ninja do not lock people out that do not buy their product. They even actually answer questions, in a very short time as well.

                          However as stated below I do think the information provided on Ninja could be improved at both a basic and advanced level.

                          Comment


                            #14
                            wizard simples

                            Ok just cos no one else has, I did it. This is wizard 101 stuff. This was totally created in the wizard.

                            BTW this literally took me 2 mins to write in the wizard, view the code to copy and then paste it in here.

                            It would have taken you about 5 mins to learn this and not forget it.

                            Cheers
                            Chris

                            Code:
                            {
                                /// <summary>
                                /// condition: close of this bar > close of previous bar
                            If condition then buy the open of next bar
                            limit order at entry price + 10 pips
                            stoploss order at entry price - 10 pips
                                /// </summary>
                                [Description("condition: close of this bar > close of previous bar
                            If condition then buy the open of next bar
                            limit order at entry price + 10 pips
                            stoploss order at entry price - 10 pips")]
                                public class JimTheTrader : Strategy
                                {
                                    #region Variables
                                    // Wizard generated variables
                                    private int profitTarget = 8; // Default setting for ProfitTarget
                                    private int stopLoss = 4; // Default setting for StopLoss
                                    // User defined variables (add any user defined variables below)
                                    #endregion
                            
                                    /// <summary>
                                    /// This method is used to configure the strategy and is called once before any strategy method is called.
                                    /// </summary>
                                    protected override void Initialize()
                                    {
                                        SetProfitTarget("", CalculationMode.Ticks, ProfitTarget);
                                        SetStopLoss("", CalculationMode.Ticks, StopLoss, false);
                            
                                        CalculateOnBarClose = true;
                                    }
                            
                                    /// <summary>
                                    /// Called on each bar update event (incoming tick)
                                    /// </summary>
                                    protected override void OnBarUpdate()
                                    {
                                        // Condition set 1
                                        if (Close[0] > Close[1])
                                        {
                                            EnterLong(DefaultQuantity, "");
                                        }
                                    }
                            
                                    #region Properties
                                    [Description("Limit")]
                                    [Category("Parameters")]
                                    public int ProfitTarget
                                    {
                                        get { return profitTarget; }
                                        set { profitTarget = Math.Max(1, value); }
                                    }
                            
                                    [Description("Stoploss")]
                                    [Category("Parameters")]
                                    public int StopLoss
                                    {
                                        get { return stopLoss; }
                                        set { stopLoss = Math.Max(1, value); }
                                    }
                                    #endregion
                                }
                            }
                            Originally posted by jimthetrader View Post
                            Hello,
                            It seems to me at first like a mountain to climb to learn how to write code to backtest in Ninja. Is there a good manual of the language with examples? If someone has time, what is the complete code to backtest a very simple system like:

                            -----
                            condition: close of this bar > close of previous bar
                            If condition then buy the open of next bar
                            limit order at entry price + 10 pips
                            stoploss order at entry price - 10 pips
                            -----

                            Thanks

                            Comment


                              #15
                              Thanks for posting this Chris!
                              BertrandNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Felix Reichert, 04-26-2024, 02:12 PM
                              9 responses
                              50 views
                              0 likes
                              Last Post Felix Reichert  
                              Started by AaronKoRn, 04-27-2024, 09:49 PM
                              3 responses
                              31 views
                              0 likes
                              Last Post AaronKoRn  
                              Started by f.saeidi, Today, 07:07 AM
                              6 responses
                              19 views
                              0 likes
                              Last Post f.saeidi  
                              Started by cmtjoancolmenero, Today, 02:31 PM
                              6 responses
                              15 views
                              0 likes
                              Last Post cmtjoancolmenero  
                              Started by Graci117, Yesterday, 11:40 PM
                              5 responses
                              27 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Working...
                              X