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 NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      53 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      130 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      70 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      44 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      49 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X