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, 05: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, 10: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:



                          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 Perr0Grande, Yesterday, 08:16 PM
                              1 response
                              7 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by f.saeidi, Yesterday, 08:12 AM
                              3 responses
                              24 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by algospoke, Yesterday, 06:40 PM
                              1 response
                              14 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by quantismo, Yesterday, 05:13 PM
                              1 response
                              13 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by The_Sec, 04-16-2024, 02:29 PM
                              3 responses
                              16 views
                              0 likes
                              Last Post NinjaTrader_ChristopherS  
                              Working...
                              X