Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Set Plotting Value in a Strategy

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

    Set Plotting Value in a Strategy

    Dear support team,

    I would like to include an indicator in my Strategy so that I can see it in the "Chart" tab when backtesting. However, I wish to make the indicator based on a custom DataSeries.

    So what I did was:
    1) Declare myDataSeries as DataSeries
    1) Put Add(SMA(myDataSeries, 14)) in the Initialize()
    2) Put myDataSeries.Set(CurrentBar) in OnBarUpdate()

    The output is quite strange to me (please see attachment for printscreen)
    1) As CurrentBar is always increasing, there is an unexpected and repeated drop in the indicator
    2) The indicator is wrapped by a ADX() for some reason. On the graph it shows SMA(ADX(SPY(Daily),14),14)

    Can you please let me know what is wrong with my way of adding a indicator with custom DataSeries? It would also be great if you can tell me if there is a way to plot a indicator directly in the OnBarUpdate() of a strategy.

    Thank you.
    Attached Files

    #2
    Hello usuallywin,

    Thank you for your post.

    This would not be the correct way to add an indicator based on a custom data series. You would need to develop a custom indicator that plotted the value of the SMA(myDAtaSeries, Period) and then call that indicator with Add().

    Comment


      #3
      Thank you for your reply.

      Can you be a bit more specific about your suggestion?

      I created an custom indicate myIndicator with one line in the OnBarUpdate():
      OnBarUpdate()
      {
      Value.Set(Input[0]);
      }

      And then I Add(myIndicator(myDataSeries)) in the Initialize() and myDataSeries.Set(CurrentBar) in the OnBarUpdate(). However, the result is the same.

      Thanks

      Comment


        #4
        Hello usuallywin,

        Thank you for your response.

        Please refer to the video at the following link detailing this item, if you need the source files they are attached to this response: http://screencast.com/t/GV7unoDw
        Attached Files

        Comment


          #5
          Thank you for the video.

          In your example, it works because the strategy and the added indicator shared the same CurrentBar value.

          However, what I really want to do is to pass a value from a strategy to an indicator so that it can be plotted on the "Chart" tab when backtesting. The indicator will not know the value to be plotted in advance.

          I tried to create an object that contains a DataSeries and passed it to the indicator, like Add(myIndicator(myObject)) in a strategy but there was an "Cannot be deserialized" error. Is there an alternative way to do that?

          Thanks.

          Comment


            #6
            Hello usuallywin,

            Thank you for your response.

            That will not work, is this a custom DataSeries or a bar series you have added to the strategy code? Either way, you need to create an indicator and call it from your strategy.

            Comment


              #7
              Hi Patrick,

              It does not have to be a DataSeries, as long as I can control what I am plotting in the Chart tab.

              For example I have a fancy way of calculating a moving average and create a strategy based on that.
              I want to see these lines shown in the "Chart" tab in backtesting.
              I could create a new indicator based on the exact same logic and attach to the strategy.
              But it would be very convenient to just create a dummy indicator that will take values from the strategy directly, and add that dummy indicator to the strategy.

              Is there a way to achieve that? Thanks.

              Comment


                #8
                Hi usuallywin,

                The issue with this, is the strategy is unable to add an indicator with any dataseries other than the primary dataseries.

                An added dataseries or custom dataseries will not work for you to pass values from the strategy to the indicator.

                Due to this limitation, my suggestion would be to move all logic of the code to the indicator, and have the strategy check the indicator for signals to trade.

                This will allow the indicator to create the custom series, and get SMA values from it, and allow this to plot on the chart.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hi Chelsea

                  If it is impossible to pass non-primary dataseries from a strategy to an indicator, what about passing a dataseries from an indicator to another indicator? Is that achievable?

                  Thanks

                  Comment


                    #10
                    Hi usuallywin,

                    I think I should clarify a bit.

                    From a strategy, it is possible to pass a secondary series to an indicator call and return a value using that dataseries.

                    However, the Add() call (which automatically draws the indicator on the chart when the strategy is added) does not allow the added indicator to use a secondary dataseries.

                    This is because indicators must be added in Initialize and additional bar array indexes are not available in Initialize as they are also added in Initialize..

                    Indicators are not able to add another indicator using the Add() function.

                    Both indicators and strategies can use a secondary series to supply an indicator and return values calculated from that supplied dataseries.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by usuallywin View Post
                      Hi Chelsea

                      If it is impossible to pass non-primary dataseries from a strategy to an indicator, what about passing a dataseries from an indicator to another indicator? Is that achievable?

                      Thanks
                      There is a sample showing how to Plot values from a strategy using a dummy indicator.

                      ref: http://www.ninjatrader.com/support/f...ead.php?t=6651

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      648 views
                      0 likes
                      Last Post Geovanny Suaza  
                      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                      0 responses
                      369 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by Mindset, 02-09-2026, 11:44 AM
                      0 responses
                      108 views
                      0 likes
                      Last Post Mindset
                      by Mindset
                       
                      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                      0 responses
                      572 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