Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Adding parameters in custom strategy

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

    Adding parameters in custom strategy

    When I add parameters in a custom strategy with the builder they are available on the strategy analyzer. When I add them on directly to the code they are not available. What am I missing?

    Code:

    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "Craig4";
    Calculate = Calculate.OnBarClose;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.AllEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 1500;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 0;
    StartBehavior = StartBehavior.WaitUntilFlat;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = false;
    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 20;
    // Disable this property for performance gains in Strategy Analyzer optimizations
    // See the Help Guide for additional information
    IsInstantiatedOnEachOptimizationIteration = True;
    Time = 28;
    Atr =.12;
    }

    The time variable was added with the builder it shows up in the Analyzer.
    The Atr variable I added directly into the code it does not.

    Thanks!

    #2
    Hello cmassey4032,

    Welcome to the NinjaTrader support forum.

    The part of your code you have shown would not be important toward how the analyzer picks up the properties, it is instead where you define the property and the syntax used for the property that matters.

    The easiest way to see what is required would be to create a new strategy and generate 1 new property then view its code. The part you provided will be there however near the bottom you will also see a public property that was generated similar to the following:

    Code:
    #region Properties
            [Range(1, int.MaxValue), NinjaScriptProperty]
            [Display(Name = "Period", GroupName = "NinjaScriptParameters", Order = 0)]
            public int Period
            { get; set; }
    #endregion
    The important part here is the [NinjaScriptProperty] attribute, this is combined with the Range attribute in the above example however you can use just [NinjaScriptProperty] on a property as well.



    This will control if this public property is used in the optimizer for a range of values or not, omitting NinjaScriptProperty will allow it to still be used as an input just not with optimizable values.


    I look forward to being of further assistance.

    Comment


      #3
      Perfect! I knew I was missing something because I could not find where Time was defined from the builder code. hidden at the bottom. Many Thanks!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      30 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, Yesterday, 02:41 AM
      0 responses
      13 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      22 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      39 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      34 views
      0 likes
      Last Post CarlTrading  
      Working...
      X