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

Sharing data from an indicator

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

    Sharing data from an indicator

    Hello Jesse,

    How to share Dataserie using your sample (TestShareData.zip ).

    I add for example in your AddOn :

    public static Series<double> UpperBand1 { get; set; }

    In Indicator I put

    NinjaTrader.NinjaScript.AddOns.SharedData.UpperBan d1[0] = Band1[0]; // Band1 is a plot


    But I have errors in indicator now. (plot Band1 was removed) why.

    How to pass complete DataSerie to a Strategy (Band1 in my case and able to access bar ago also) ?

    thank you


    #2
    Hello oceanis400,

    This sample would not be useful for sharing series, you should instead use the correct approach at calling the indicator to retrieve its value. The sample in this thread does not have the ability to sync between two scripts so that would generally not be suggested for a series or any bar related data. This sample is really only intended to demonstrate one way which a static variable could be used to make an observable value, however we do not suggest this type design pattern in NinjaScript. There are existing ways to share data that should be followed instead such as calling the indicator by name:

    Code:
    Bollinger(2, 20).Upper[0]  //getting the upper plot from the bollinger indicator
    https://ninjatrader.com/support/helpGuides/nt8/en-us/bollinger_bands.htm?zoom_highlightsub=bollinger

    Custom indicators can be called in the same way from your strategy. You can also use AddChartIndicator() method to add the indicator visually if needed. There is no recommendation I can make for combining a manually added indicator and strategy, or separate charts data. A strategy should add all data it requires along with calling on indicators it needs to retain logic within the strategy its self.


    Please let me know if I may be of additional assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      hello,

      I try to add an indicator that use AddDataSeries in State.Configure. But I can't add it from a strategy even if I add same DataSeries. I have always same issue.
      "Indicator 'smaCDCycle': Error on calling 'OnStateChange' method: Object reference not set to an instance of an object."
      I would like get values used by this indicator.
      I can send you by private email or chat.

      thank you

      Comment


        #4
        Hello oceanis400,

        Thank you for the reply.

        If you would like to provide a sample you can attach it here or email platform support. We would not be able to work through private messages on the forum.

        If you have a large script which you don't want to provide publicly that is most likely not going to be a good sample to demonstrate the problem in a simple way. We do suggest trying to make a reduced sample that demonstrates the problem.

        If you are using an indicator which adds an additional series, you could try to recreate this situation in a new script without your other OnBarUpdate logic to check if it still happens. If so that would be an ideal sample as it omits your private logic and just displays a problem. The same goes for the indciator, trying to make a more simple test indicator that you can call to recreate the error will help.

        The error is happening from OnStateChange so you can ignore the other overrides for now. This error means that some object being used is null, so that can also be a clue.


        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Thank you Jesse,
          I joined indicator . (I remove lot of thing)
          So I would like get value of plots from strategy.
          I test Static variable, get same thing as Bollinger(2, 20).Upper[0] . But I can't get historical value from strategy even if I use : smaCDCycle(40,3,2.5, 2, false).Values[0][0];
          First how to use AddChartIndicator(smaCDCycle(200,3,2.5, 2, false); from strategy without errors.

          How I can do this ?
          Attached Files

          Comment


            #6
            Hello oceanis400,

            I took a look at the script and can see that you are dynamically adding data series so that specifically will prevent this from being used. The indicator needs to have hard coded AddDataSeries statements to be hosted because the strategy also requires the same AddDataSeries statements. There are no cases where AddDataSeries can be used dynamically to add variable secondary series.

            For example:
            Code:
            AddDataSeries(BarsPeriod.BarsPeriodType, 3);
            needs to be changed to hard coded:
            Code:
            AddDataSeries(BarsPeriodType.Minute, 3);
            Then for this to be called in a strategy the strategy would need to add the same set of AddDataSeries statements.

            Going beyond that, if you modify this to have hard coded series you may still need to debug the script in case it is not getting data. I see there is a lot going on in the indicator which could also affect the values from an outside source. It would be best to start more simple in an outside test to find where the problem begins. You can do this by creating a new indicator and hard coding the secondary series/setting it up with a strategy. Next confirm it works by plotting a single plot with the Close value. Once you have that working, you can pull in portions of your custom logic to test each part and confirm the strategy can read the value after modifications.

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Thank you Jesse,
              Yes I modified indicator and strategy with.
              I tried to add (AddDataSeries(BarsPeriodType.Minute, 3) and (AddDataSeries(BarsPeriodType.Minute, 9) in strategy at State == State.Configure but you can't add indicator there is always same issue.

              Is there a way to know when indicator as ended calculate. (actually 30s for 10 days loaded) . Then I can read Static variable put in indicator from Strategy.

              If I can't know when indicator as plot all value, It's easy to get value.

              But It's important that strategy don't start before ended indicator. (Which variable or state may force strategy to wait).


              sincerely,

              Comment


                #8
                It's possible to load all values of indicator in data serie and THEN start strategy , How to do this ?

                Comment


                  #9
                  Hello oceanis400,

                  It looks like this post has deviated pretty far from the topic you have posted in so I have created a new thread for your specific questions.

                  I tried to add (AddDataSeries(BarsPeriodType.Minute, 3) and (AddDataSeries(BarsPeriodType.Minute, 9) in strategy at State == State.Configure but you can't add indicator there is always same issue.
                  Yes as noted the indicator is very large, you will very likely need to reduce your code and debug the situation. The dynamic series is only going to be part of the problem, if you are still having errors you need to continue to reduce the code and locate what specifically is causing it.

                  Is there a way to know when indicator as ended calculate. (actually 30s for 10 days loaded) . Then I can read Static variable put in indicator from Strategy.
                  It is not suggested to use static in with indicators/strategies because that goes against how the framework works. In some very specific use cases it may be acceptable to use however your use case is not one of those situations. The sample you had taken this concept from was intended to display a way to replicate the OP's question from another language. This does not mean it would be a valid way to pass data from an indicator and a strategy, it would be best to ignore that sample all together as that sample does not apply to this situation. You will need to fix the indicator so that it can be called by the strategy and retrieve data, that is the only suggested way to have a strategy read an indicators data.

                  But It's important that strategy don't start before ended indicator. (Which variable or state may force strategy to wait).
                  Do you mean when you enter realtime start the strategy logic or after the indicator has a certain value?

                  Your strategy is calling the indicator and will also be calculating at that time. This happens for the historical bars and then for the realtime bars. If you call the indicator from OnBarUpdate, it will need to process. If you need your strategy to wait for a specific value from the indicator, you would need to form a condition to do that and just don't do the strategy logic until after that time. The script will need to continue processing though, you cannot load one first and then the other.




                  I look forward to being of further assistance.
                  JesseNinjaTrader Customer Service

                  Comment


                    #10
                    Hello Jesse,

                    So I tried to built strategy with this code. (Convert indicator to strategy)

                    at line 317 , I have issue with if (serFastCycle == null) serFastCycle = new Series(this);

                    why it's good in indicator and not in strategy ?


                    Attached Files

                    Comment


                      #11
                      Hello oceanis400,

                      It looks like you are using some items that I don't have so I cant import this to see the specific error. I can say that you do not need the checks that you are doing. Configure is only called for a specific reason so you can just assign to your variable here without any checks:
                      Code:
                      serFastCycle = new Series(this);
                      Looking at this syntax, this is likely the problem. You are using only "Series", what type did you want? Series is not just "Series" it is "Series<T>" where T represents your type like Series<double>. Was this intended to be a double? You need to correct the Series syntax to be Series<T>. As I cant compile I cant test this to tell you that is the only problem, if you see other problems after changing to Series<T>, can you include the indicators you used or change to stock indicators for testing?




                      I look forward to being of further assistance.
                      JesseNinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by helpwanted, Today, 03:06 AM
                      1 response
                      9 views
                      0 likes
                      Last Post sarafuenonly123  
                      Started by Brevo, Today, 01:45 AM
                      0 responses
                      7 views
                      0 likes
                      Last Post Brevo
                      by Brevo
                       
                      Started by aussugardefender, Today, 01:07 AM
                      0 responses
                      5 views
                      0 likes
                      Last Post aussugardefender  
                      Started by pvincent, 06-23-2022, 12:53 PM
                      14 responses
                      242 views
                      0 likes
                      Last Post Nyman
                      by Nyman
                       
                      Started by TraderG23, 12-08-2023, 07:56 AM
                      9 responses
                      385 views
                      1 like
                      Last Post Gavini
                      by Gavini
                       
                      Working...
                      X