Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Accessing BarsPeriod params (Value, Value2...) during OnStateChange State.SetDefaults

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

    Accessing BarsPeriod params (Value, Value2...) during OnStateChange State.SetDefaults

    Hello,

    I would like to know the current chosen BarsPeriod params (Value, Value2...) during OnStateChange State.SetDefaults when setting properties' default values. I am aware that the BarsPeriod object doesn't formally exist in this state, but the Strategy Analyzer has the Data Series params in the UI, or when set on a chart, the chart already has a BarsPeriod. Is there a way to access that information?

    Here are some more details of what I am trying to achieve - In a strategy, I am calculating some properties' default values based on other properties by extending the { get; set; } to something like:

    Code:
    protected override void OnStateChange()
    {
        if (State==State.SetDefaults)
        {
            Description                                 = unitName+@" Better World For Us LLC - Auto Algo Box";
            Name                                         = externalUnitName;
            // ...
            SetPropertiesDefaults();
        }
        else if (State==State.Configure)
        {
            // ...
        }
    }
    
    
    private void SetPropertiesDefaults()
    {
        RE_NumTargets                    = 4;    
        RE_TargetValue0                    = 1;
        CalcDefaultRETargetSizes(RE_NumTargets);        
    }
    
    private void CalcDefaultRETargetSizes(int numTargets)
    {
        double enterPoint = 0.25;
        deltaTarget = (RE_TargetValue0-0.25)/(numTargets+1);
        if (numTargets>1)
            RE_TargetValue1 = RE_TargetValue0-deltaTarget*1;                
        // ...            
    }
    
    private int _RE_NumTargets;
    [NinjaScriptProperty]
    [Display(Name="# of Targets", Order=32, GroupName="ReEnters"),Range(1,10)]
    [RefreshProperties(RefreshProperties.All)] // Needed to refresh the property grid when the value changes
    public int RE_NumTargets
    {
        get {return _RE_NumTargets;}
        set
            {                    
                _RE_NumTargets = value;
                CalcDefaultRETargetSizes(_RE_NumTargets);
            }
    }            
    
    [NinjaScriptProperty]
    [Display(Name="Target Size 1", Order=40, GroupName="ReEnters"),Range(0,double.MaxValue)]
    public double RE_TargetValue0 { get; set; }
    
    [NinjaScriptProperty]
    [Display(Name="Target Size 2", Order=41, GroupName="ReEnters"),Range(0,double.MaxValue)]
    public double RE_TargetValue1 { get; set; }​
    The RefreshProperties is causing the screen to refresh and show the correct value.

    I would like to know the current chosen Data Series params

    #2
    Officially, I think the answer to this is no, because if I remember this correctly, when State.Configure is run the first time, before it is cloned for each instance, that information is not yet available, and further, you don't know that they didn't check the box to optimize the data series so it might be changing. NinjaTrader may be able to shed more light on the internals of this but BarsPeriod is a property of the Bars object, and the Bars object is explicitly not able to be relied on in State.Configure.

    That having been said, if you run this in a chart, it is usually populated. In Strategy Analzyer, no.

    What you may want to do is have a checkbox that says "automatic settings by period" and if it's checked, you set the values in State.DataLoaded when you DO have that information.

    Then, you can leave those parameters blank or hidden in the UI unless they uncheck the box and want to set them manually.
    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    Comment


      #3
      Hello Shai Samuel,

      Bruce is correct. The Bars are not ready until State.DataLoaded, and the checkbox for checking in State.DataLoaded is an elegant solution.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Originally posted by NinjaTrader_ChelseaB View Post
        Hello Shai Samuel,

        Bruce is correct. The Bars are not ready until State.DataLoaded, and the checkbox for checking in State.DataLoaded is an elegant solution.
        Thank you. You are too kind.
        Bruce DeVault
        QuantKey Trading Vendor Services
        NinjaTrader Ecosystem Vendor - QuantKey

        Comment


          #5
          Thank you both. This is the answer I knew, but i was hoping for a Behind the Scenes magic...

          Everything will work once I manually enter one property data (State.Configure), but I would like to have the correct property calculated and they are all somehow derived from the BarsPeriod params.

          I hope to add a function retrieving the current BarsPeriod input params will, be added to the wishlist, since a Strategy is always either attached to an existing Chart or is running in the Strategy Analyzer, which has Data Series BarsPeriod input params. If so, each of the BarsPeriod input properties (in Strategy Analyzer), must have [RefreshProperties(RefreshProperties.All)], so any change in them will refresh the properties.

          Comment


            #6
            Hello Shai Samuel,

            This is tracked with ID # SFT-3948. I will add your vote to this.

            Please note, we receive many requests and cannot reasonably implement all requested features or changes. Interest is tracked internally and if enough interest is tracked, it would be weighed against how feasible it would be to make those changes to consider implementing, so we cannot offer an ETA or promise of fulfillment.

            When new features are implemented, they will be listed in the Release Notes page of the Help Guide. The ID number may be different than the internal feature request tracking ID, but the description of the feature will let you know if that feature has been implemented.

            Release Notes - https://ninjatrader.com/support/help...ease_notes.htm
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Thank you Chelsea. Is there a link where we can see these ID # SFT list?

              Comment


                #8
                Hello Shai Samuel,

                Unfortunately, the feature request database is not made public.
                Chelsea B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Yesterday, 05:17 AM
                0 responses
                76 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                146 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                79 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                50 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                54 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X