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

Overriding the Strategy Analyzer settings within State.Configure

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

    Overriding the Strategy Analyzer settings within State.Configure

    Hi,

    Within the guide for OnStateChange (https://ninjatrader.com/support/help...tatechange.htm), within Configure it says "This state is where you should... Override and configure values set by the UI".

    Within the Strategy Analyzer UI, under Data Series there is the option to specify Type and Value. Is it possible to override the 'Value' setting from the UI, and if so, what code should be used please as I can't find this in the support guides? Can this be done within State.Configure?

    FYI, When I select an instrument list to backtest a list that has say 100 instruments within it, I'd prefer to configure/hardcode 'Value' settings per instrument rather than adopting the single one size fits all Value setting from the UI. These would be held constant per instrument, and not change as the strategy runs. E.g. looking for something like:

    Code:
    else if (State == State.Configure)
    {
    if (this == ABC) period = 1000;
    if (this == DEF) period = 2000;
    if (this == GHI) period = 500;
    ... and so forth
    
    }
    Many thanks in advance

    ChainsawDR

    #2
    Hello ChainsawDR,

    Thanks for your post.

    The strategy would be applied to the data series set in the UI and it cannot be overridden within the strategy code.

    It is possible to add additional data to the strategy in State.Configure but this is not fully supported to dynamically add additional data based on UI selections. Dynamically adding data series can specifically cause issues with Optimization backtests. Please see notes in AddDataSeries documentation.

    AddDataSeries - https://ninjatrader.com/support/help...dataseries.htm

    However, you could consider calling AddDataSeries(BarsPeriodType.Minute, 1); in State.Configure to hard code a 1 minute series in the strategy, and then if you skip processing the primary data series with if (BarsInProgress == 0) return; , you can force using the added 1 minute data series instead of the primary data series.

    Let us know if you have any additional questions.
    JimNinjaTrader Customer Service

    Comment


      #3
      Thanks Jim that is really helpful. Sorry one quick follow up please, is there a method for referencing the Size or 'Value' that was specified within the UI from the code. E.g. Print("This is the size selected via the UI: " + something); as I can't find it in the guides anywhere.

      Thanks again

      ChainsawDR

      Comment


        #4
        Sorry, got it, Bars.BarsPeriod, thanks again!

        Comment


          #5
          Sorry I spoke too soon. I'm having difficulty using Bars.BarsPeriod within a calculation. I'm trying to pull the BarsPeriod value (in this instance its 1000), and then multiply it by the Close price (Close[0]). I can't use it as-is because "Operator '*' cannot be applied to operands of type 'NinjaTrader.Data.BarsPeriod' and 'double'"

          When I try to store it as a double variable and try to convert it (System.Convert.ToDouble(Bars.BarsPeriod) or convert to string then to double (System.Convert.ToDouble(Bars.BarsPeriod.ToString( ))), I get a different error: "Error on calling 'OnBarUpdate' method on bar -1: Unable to cast object of type 'NinjaTrader.Data.BarsPeriod' to type 'System.IConvertible'." - Please let me know if you have any advice for this

          Thanks again

          ChainsawDR

          Comment


            #6
            Hello ChainsawDR,

            Please keep in mind the note from AddDataSeries documentation regarding the use of UI elements to add additional data series:

            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 in 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.
            This does work in many cases, and you are welcome to try what works for you, but please keep in mind that it is not fully supported.

            As for using the BarsPeriod Value property, this would be written as BarsPeriod.Value.
            JimNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by cre8able, Today, 01:16 PM
            1 response
            3 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by chbruno, 04-24-2024, 04:10 PM
            3 responses
            47 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by samish18, Today, 01:01 PM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_LuisH  
            Started by WHICKED, Today, 12:56 PM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by WHICKED, Today, 12:45 PM
            1 response
            11 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Working...
            X