• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnStateChange

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

    OnStateChange

    I would like to be able to change the values below dynamically.

    I want to change the dataseries minutes based on the timeframe of the chart.
    I want to change the profit target and stop loss based on values passed it.

    Can I do this and when should I do this, since configure probably only fires once when a strategy starts.

    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Minute, 240);
    SetProfitTarget("", CalculationMode.Pips, 250);
    SetStopLoss("", CalculationMode.Pips, 50, false);
    }

    Thanks!!

    #2
    Hello,

    Thank you for the post.

    While techically in some cases you can use variables to make adding a series dynamic, it is not suggested. We have a note about this in the helpguide here:
    http://ninjatrader.com/support/helpG...=adddataseries

    Arguments supplied to AddDataSeries() should be hardcoded and NOT dependent on run-time variables which cannot be reliably obtained during State.Configure (e.g., Instrument, Bars, or user input). Attempting to add a data series dynamically is NOT guaranteed and therefore should be avoided. Trying to load bars dynamically may result into an error similar to: Unable to load bars series. Your NinjaScript may be trying to use an additional data series dynamically in an unsupported manner.


    I will add a feature request for this item as well.

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

    Comment


      #3
      This is what I did. Thoughts?

      if (State == State.Configure)

      if (BarsPeriod.Value == 60)
      {
      AddDataSeries(Data.BarsPeriodType.Minute, 240);
      }

      if (BarsPeriod.Value == 15)
      {
      AddDataSeries(Data.BarsPeriodType.Minute, 60);
      }

      Comment


        #4
        Hello RiversideDude,

        Thanks for writing back to us.

        What you have outlined still constitutes as dynamically adding a data series. You are adding your additional data series, depending on if the primary data series has a certain period value. I would suggest to add both additional data series and use logic within your strategy to calculate for one data series or the other depending on the BarsPeriod.Value your primary data series specifies.

        Please let me know if I may be of further assistance.
        JimNinjaTrader Customer Service

        Comment


          #5
          Good idea.

          Thanks!!

          Comment


            #6
            I added an additional dataseries using the strategy builder, is that dataseries accessible in Ninjascript?

            Also, it possible to name a dataseries so that I can refer to it by name?

            Thanks!!

            Comment


              #7
              Hello RiversideDude,

              Thanks for the reply.

              The Strategy Builder is the NinjaScript code generator for NinjaTrader 8. The code that it generates is NinjaScript and can be referenced by clicking "View Code"or "Unlock Code." Any code that gets generated by the Strategy Builder is usable in NinjaScript.

              Data Series are referenced by BarsInProgress or using the plural form of the common price objects. (Close[barsAgo]] -> Closes[dataSeries][barsAgo]) There is not an applicable way that I am aware of to use names for additional data series.

              Please refer to this documentation for referencing data in a multi series strategy:
              http://ninjatrader.com/support/helpG...nstruments.htm

              You may also wish to view the reference sample here:
              http://ninjatrader.com/support/forum...ead.php?t=6652

              Please let me know if you have any further questions.
              JimNinjaTrader Customer Service

              Comment


                #8
                Thanks Jim!

                Comment


                  #9
                  Situation:
                  I'm building a multiple timeframe strategy. Sometimes it will run with H4 and H1 other times it will run with H1 and M15. I only want to have one version of my strategy.

                  Problem:
                  How can I manually add a dataseries without having a duplicate dataseries when I apply the strategy to a chart?

                  Example: When I run it with H4 and H1. The H4 dataseries is added manually and the primary dataseries will be added based on the timeframe of the chart the strategy is added to. How do I reuse this strategy when I run it with H1 and M15?

                  If I add an H1 dataseries manually, I’ll have two H1 dataseries when I run it with H4 and H1.

                  Thanks in advance!!

                  Comment


                    #10
                    Hello RiversideDude,

                    Thanks for the reply.

                    Additional data series must be hardcoded to the strategy and cannot be added dynamically, or based off of logic.

                    Because of this, you will have to create multiple instances of your strategy so they can be used to match the primary data series that you wish to attach a trade on.

                    For example you can have own strategy that is designed to be added to a 5 minute ES 06-17 chart that adds a 1 hour data series for calculations. Another strategy could be designed to to be used on a 10 minute CL 04-17 chart that adds a 4 hour data series for calculations.

                    Since these data series are added in OnStateChange() under State == State.Configure, they must be hardcoded to the strategy. The only solution is to create multiple strategies that target each instrument and profit-taking goal.

                    Please let me know if you have any further questions.
                    JimNinjaTrader Customer Service

                    Comment


                      #11
                      Is there an issue with having multiple version of the same dataseries in a strategy? I could just add both dataseries and refer to the correct one based on the timeframe of the chart, right?

                      Thanks!!

                      Comment


                        #12
                        Hello RiversideDude,

                        Thanks for writing back.

                        Yes, you can add the same data series as the primary series as a secondary series within a strategy.

                        If you have any further questions, please don't hesitate to ask.
                        JimNinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by corman, Today, 06:04 AM
                        0 responses
                        3 views
                        0 likes
                        Last Post corman
                        by corman
                         
                        Started by brunoviveiros, Today, 06:00 AM
                        0 responses
                        1 view
                        0 likes
                        Last Post brunoviveiros  
                        Started by JAtrades, Today, 05:20 AM
                        4 responses
                        7 views
                        0 likes
                        Last Post JAtrades  
                        Started by riuhdfjkbh, Today, 05:40 AM
                        0 responses
                        2 views
                        0 likes
                        Last Post riuhdfjkbh  
                        Started by pol133, Today, 02:35 AM
                        1 response
                        8 views
                        0 likes
                        Last Post NinjaTrader_Marco  
                        Working...
                        X