• 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

Ninja Script with the built in Strategy Analyzer

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

    Ninja Script with the built in Strategy Analyzer

    How can I test with the strategy analyzer my new strategy, which I have written in Ninja Script. It is not showing up in the Strategy Analyzer under Strategy.
    Last edited by dpeter; 10-08-2018, 04:02 AM.

    #2
    Hello dpeter,

    Thanks for your post and welcome to the NinjaTrader forums!

    In order to test in the strategy analyzer, you would need to be able to select the strategy from the strategy list.

    To see the strategy name in the strategy analyzer list, the strategy must be compiled successfully.

    If the strategy has been successfully compiled and the name of the strategy is still not visible in the strategy analyzer strategy list then reopen the strategy code in the Ninjascript editor and check that in OnStateChange() method that in the State.SetDefaults that the line "Name = " contains the name of the strategy. In general, the strategy filename, strategy public class name, and the Name = field should all be the same to minimize confusion.


    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thanks, it was the name, since I used a snipplet published here. However, the snipplet seems not to work. I would like to find the highest high between eg. 8:00-9:00 and store it in a variable, which I can call later for comparison. I have tried in the strategy Builder and now directly with Ninja editor. I dont succeed.

      Comment


        #4
        Hello dpeter,

        Thanks for your reply.

        Glad you were able to solve the name issue.

        To assist with your next question, please post your section of code where you are trying to determine the highest high within a certain time period.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          The range will be always ignored, the following everything after the range definition works.

          Comment


            #6
            Hello dpeter,

            Thanks for your reply.

            To debug we recommend using print statement to understand the value of what is being saved, compared and set. For example:

            Print ("CB:"+CurrentBar+" High[0] "+High[0]+ " HH: "+HighestHigh+ " FirstIB: "+FirstIB);

            You can find our debug tips here: https://ninjatrader.com/support/help...script_cod.htm

            The line FirstIB = true; is not encapsulated with the if statement and would be set true on each OnBarUpdate(). If you mean to set it true when the if statement resolves true then you would need to add braces {} to contain all of the action statements related to the if statement, otherwise C# will only consider the first action statement with the if statement and as mentioned the FirstIB=true; will be executed on each OnBarUpdate() regardless of the if statement.
            For example:

            if (Bars.BarsSinceNewTradingDay > 60 && High[0] < High[1] && Low[0] > Low [1])
            {
            HighofFirstIB = High[0];
            FirstIB = true;
            }

            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Thank you. I tried the print statement. I added the line to the code and compiled, but it is not clear to me, where I can see the print output. When I print the output window it is empty.
              Last edited by dpeter; 10-08-2018, 09:35 AM.

              Comment


                #8
                Hello dpeter,

                Thanks for your reply.

                The Print statement will go to the output window, found in New>Ninjascript output.

                If you are not seeing any printed output, first please check the "log" tab of the control center for any runtime errors associated with the strategy.

                Please make sure that the print statement is contained within the OnBarUpdate() {}.

                If you are still unable to see any print values in the output window, please post your entire code.
                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  Okay, I have no comment in log tab, I am in OnBarUpdate and teh log file is still empty.

                  Comment


                    #10

                    Comment


                      #11
                      Hello dpeter,

                      Thanks for your reply.

                      What you have posted looks correct and you should be seeing print statements in the New>Ninjascript output.

                      If you are applying the strategy to a chart and you are connected to live data please note that you would need to "enable" the strategy when you apply it in order for the strategy to execute.


                      Paul H.NinjaTrader Customer Service

                      Comment


                        #12
                        It is empty. I click in the Ninja editor, in the window with my current open program on the top on the icon Ninja Script Editor. It looks to me logical and I have read all the materials. It can not be that a simple range break out code takes me 8h and it doesnt work. Can you tell me how to do it in the strategy builder, instead. There must be something wrong with the code. I simply need the highest high of a time period of eg. 60 min. or 60 bars in 1 min. chart. The highest high needs to be stored as a variable, which I can call later, when other statements are fullfilled to execute an order. Please make a small example, the manual doesnt help and the videos do not go over a simple crossing mechanism.

                        Comment


                          #13
                          Hello dpeter,

                          Thanks for your reply.

                          The strategy when run on a chart or in the strategy analyzer will output to the New>Ninjascript output. I've created a short video to demonstrate using as much of your code as you have shown: https://Paul-ninjaTrader.tinytake.co...U4OF84OTQyNzE4

                          In terms of looking for crossovers, once you have determined your upper and lower levels for the breakout, you could use the CrossAbove() or CrossBelow() methods, where one input would be the price series (such as High) and the other input, would be your HighestHigh. In the help guide links for the cross methods, there are several examples, the first shows the current value of the CCI over a defined numerical value, this would be similar to your needs in terms of CrossAbove(High, HighestHigh, 1)

                          References:
                          https://ninjatrader.com/support/help...crossabove.htm
                          https://ninjatrader.com/support/help...crossbelow.htm

                          Paul H.NinjaTrader Customer Service

                          Comment


                            #14
                            That is great, thanks! Yes, I didnt know about letting it run in the chart. So, the logic seems to work and my problem must be elsewhere, since the executed trades don't yet match with what I want to achieve. Then I have to dig deeper. Thanks.

                            Comment


                              #15
                              Hello dpeter,

                              Thanks for your reply.

                              Yes, always use a chart when debugging (or strategy analyzer chart) and the ninjascript output window. In general, you will find that besides print, drawing objects on the chart when conditions are true will also help.
                              Paul H.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Newtrader101, Today, 08:01 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post Newtrader101  
                              Started by Johnny Santiago, 10-11-2019, 08:21 AM
                              6 responses
                              101 views
                              0 likes
                              Last Post 4x777
                              by 4x777
                               
                              Started by pjsmith, Today, 02:42 AM
                              2 responses
                              16 views
                              0 likes
                              Last Post pjsmith
                              by pjsmith
                               
                              Started by moyerchopra, Yesterday, 11:43 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post moyerchopra  
                              Started by ttodua, Yesterday, 11:40 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post ttodua
                              by ttodua
                               
                              Working...
                              X