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

plot in strategy

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

    plot in strategy

    If I want my strategy to plot something other than an indicator, how can I do that?

    Using the Strategy Wizard, if I add a plot called "StrategyPlot", I get
    AddPlot(Brushes.Orange, "StrategyPlot") put into the SetDefaults block of code.

    So how do I assign values to this plot? In indicators it was easy since anything in Values[0] would be automatically get plotted to the first plot. I want something like that for strategies.

    #2
    Hello YD777, and thank you for your question. Plots can be assigned to in exactly the same way. The attached indicator, for instance, assigns the closing price to the Values[0][0] member on each bar. Please let us know if there are any other ways we can help.
    Attached Files
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      There is another thread in the NT7 area regarding the same question and discussing in fact NT8's solution.

      I just wonder if there is a way to combine all the code (strategy and indy) in one file. I tried to do that but with no success.

      Edit:
      Sorry, the thread I referenced is discussing plotting in a separate panel. I was confused with 'StrategyPlot' mentioned in the first post. Anyway, I'd like to know the answer to my question. Thanks in advance.
      Last edited by quicktrick; 04-05-2017, 09:02 PM.

      Comment


        #4
        Thank you for your question quicktrick. While it is true NT7 has fewer options as far as plotting from a Strategy, there are two approaches that may work for you.

        First, you can use methods such as DrawLine from your strategy.

        Second, you can make a very basic indicator, such as the one attached. You can then set up a strategy such as the attached strategy. This will let you handle all your logic from your strategy.
        Attached Files
        Jessica P.NinjaTrader Customer Service

        Comment


          #5
          Thank you, Jessica! And now, please, tell me if there is a way to combine your two code files in just one strategy code file. To add there namespace NinjaTrader.Indicator and the indicator's code and so on?

          Comment


            #6
            Provided you are comfortable doing without any postprocessor extras for indicators, you can create instances of an indicator with the New keyword, and can then use code such as that attached. Code samples we provide are for educational purposes, and are not intended for live trading, and are not guaranteed to accomplish any user goal or to be maintained.
            Attached Files
            Jessica P.NinjaTrader Customer Service

            Comment


              #7
              Hi Jessica! Thanks a lot for your example! But it's for NT7. Could you please do the same for NT8? I tried to do it myself, but I had runtime errors. Thank you in advance!

              Comment


                #8
                For NT8, you can simply call AddPlot and assign directly to your Values array, as YD777 and I were discussing in the first 2 posts. Please let us know if any specific questions come up when acting on this advice. There is a code example in post #2 in this thread which accomplishes this goal. For convenience,

                Jessica P.NinjaTrader Customer Service

                Comment


                  #9
                  Thank you, Jessica! But I'd like to have plot on a separate panel and to have all the code (strategy and indicator) in one file. Is it possible? Now I have working code for a strategy and a separate panel plot in two files, but I'd like to have them in one file. Could you help in that, please?

                  Comment


                    #10
                    While I am happy to answer questions about the operation of NinjaTrader, fully developing a working user solution is beyond the scope of the support we may provide. The information you are requesting can be found elsewhere in this thread, with the exception of one new item you brought up.

                    One Indicator or Strategy plotting to multiple panels is not possible in NT7 or NT8. Please review this archived beta thread for more information.



                    In lieu of this, you can use the DrawOnPricePanel property to draw on the Price panel while plotting Indicator data to a panel owned by your NinjaScript.
                    Jessica P.NinjaTrader Customer Service

                    Comment


                      #11
                      Hi Jessica! Thank you for your reply. I don't mean to ask you to develop any specific user solution. Rather I'd like to know if NinjaScript allows to do some things common to any solution.

                      I don't mean to plot on two separate panels from one strategy or indicator. I have working solution where I use a strategy and an embedded separate indicator that plots on a separate panel. And I have my indicator in a separate file located in the 'Indicators' folder.

                      My question is: Is it possible to combine my strategy code and my indicator code in one file? That is to add 'namespace NinjaTrader.Indicator' and the indicator's code to my strategy file and make it work as if they were in two different files?

                      Comment


                        #12
                        While it is possible to do something similar to what you are doing, as I had done with the NT7 code, there are a few caveats

                        • The included indicator will no longer be able to plot in a separate panel from your strategy
                        • You will not be able to use the Indicator namespace, as there are symbol incompatibilities with the Strategy namespace
                        • You will need to make the Indicator a subclass to your Strategy; otherwise, the automated code generation will fail

                        I have attached an example for NT8 that works similarly to the example I posted for NT7.
                        Attached Files
                        Last edited by NinjaTrader_JessicaP; 04-10-2017, 08:03 AM.
                        Jessica P.NinjaTrader Customer Service

                        Comment


                          #13
                          Thanks a lot, Jessica! If combining strategy and indicator makes it impossible to plot on a separate panel, this solution isn't suitable for me. Thanks again for your efforts and for your code! I will use separate files for strategy and indicator. It was just a theoretical question.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by algospoke, Today, 06:40 PM
                          0 responses
                          9 views
                          0 likes
                          Last Post algospoke  
                          Started by maybeimnotrader, Today, 05:46 PM
                          0 responses
                          7 views
                          0 likes
                          Last Post maybeimnotrader  
                          Started by quantismo, Today, 05:13 PM
                          0 responses
                          7 views
                          0 likes
                          Last Post quantismo  
                          Started by AttiM, 02-14-2024, 05:20 PM
                          8 responses
                          168 views
                          0 likes
                          Last Post jeronymite  
                          Started by cre8able, Today, 04:22 PM
                          0 responses
                          10 views
                          0 likes
                          Last Post cre8able  
                          Working...
                          X