Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Plotting values on a strategy chart

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

    Plotting values on a strategy chart

    Hi, I'm having trouble figuring out how to plot values onto the strategy chart so I can see what is what/when for debugging my strategy.

    I have bars objects created and set equal to the Swing indicator high and low, so I've got swinghi[x] and swinglo[x] returning the right values.

    I've tried using Draw but realized that wasn't intended for this (I think) and tried adding a Plot, a Line, different things in Initialize and it won't let me.

    Am I missing something in the declarations perhaps? Here are mine:
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using System.Collections;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Indicator;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Strategy;

    Thanks!

    #2
    Hello entropy,

    There is a post here that can help with adding indicators to a strategy for plotting.


    From the strategy wizard, you can also select the PlotOnChart = true in your condition builder to easily add the correct syntax.

    One thing to note with Swing is that it's a repainting indicator, so accessing programatically will return different values than you see on a chart.
    Attached Files
    Last edited by NinjaTrader_RyanM1; 05-10-2011, 03:29 PM.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Thanks Josh ... could you also please tell me how to plot my own dataseries on the chart? Since that dataseries is the one my strategy uses, that's what I want to see.

      Comment


        #4
        This sample walks you through this.
        When running a strategy on a chart you may find the need to plot values onto a chart. If these values are internal strategy calculations that are difficult to migrate to an indicator, you can use the following technique to achieve a plot. NinjaTrader 8 With NinjaTrader 8 we introduced strategy plots which provide the ability


        You need a blank indicator, and can then set the value of this blank indicator within the strategy.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Hi Ryan,
          Thank you. These instructions say that "Note: This technique has limited functionality. It will NOT work for charts in the Strategy Analyzer during backtesting, but it will work on real-time charts."

          Is there any way to plot the values during a backtest?

          Comment


            #6
            You can display indicatots in a backtest that have been Added to the strategies Initialize() method. This is the technique shown in my first reply. This would then require you to move your strategies custom data series into an indicator that plots.
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              Okay, that sounds like a great solution to me. Thanks!

              Comment


                #8
                Hi Ryan

                I've done this now. And the indicator plots great on a chart. My indicator is a modification of the Swing indicator called SwingTwo.

                When I do this:

                Add(Swing(5)); the default Swing indicator paints just fine on the strategy chart

                But when I do this:

                Add(SwingTwo(5)); it compiles fine but the indicator does not appear on the strategy chart

                Do I need to "Add()" custom indicators in a special way to get them to display?

                Comment


                  #9
                  Custom indicators are added the same way. Are there any error messages noted in log tab of the control center?
                  Ryan M.NinjaTrader Customer Service

                  Comment


                    #10
                    Hi Ryan,
                    Yes there was an error it was the not enough bars in the DataSeries error. I was using Close[1] right away. I had BarsRequired = 10 in initialize though so I'm confused as to why I would need to do this as well: if (CurrentBar < 1) return; Is BarsRequired doing something different than I'm thinking?

                    To get around this I set another dataseries = Close[0] and was able to look back in that series without the error? Is Close a special more sensitive dataseries? Or did the other dataseries have values of default 0 instead of a null/no value so it did not error?
                    Thanks!

                    Comment


                      #11
                      Yes, minimum bars required should prevent it from processing the first x bars. What is the exact message you're getting?

                      Best is to simplify and isolate what line of code is causing an exception. If you're not able to track it with that approach, you can use Try- Catch blocks to capture more information about the exception.
                      Ryan M.NinjaTrader Customer Service

                      Comment


                        #12
                        5/12/2011 11:18:26 AM Default Error on calling 'OnBarUpdate' method for indicator 'SwingTwo' on bar 1: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

                        Adding BarsRequired didn't work but the currentbar > x check did work.

                        Thanks for the debugging tip!

                        Comment


                          #13
                          Yes it will plot the value but it we try access the plotted value using the indicator that is being used then no values came from that indicator meaning the value is not stored in the indicator dataseries.

                          Comment


                            #14
                            I'm not sure I follow your last comment luxurious_04 - which code structure do you use and what do you expect to be stored where? Where is the value you're trying to access calculated in the indicator?

                            Comment


                              #15
                              I have two strategies running. I already plotted the value of strategy A on the chart but my problem is I could not get the value of strategy A when I try to query it on Strategy B. So the value strategy A is just a value that you can see being plotted on the chart but you cannot access it. It says that the value is being passed to the blank indicator dataseries by adding this code startegyAindicator.value.set(High[0]) to strategy A but I could not access the value by using this code

                              double j = strategyAindicator.value[0];

                              Comment

                              Latest Posts

                              Collapse

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