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

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.

    JesseNinjaTrader Customer Service

    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 jaybedreamin, Today, 05:56 PM
      0 responses
      2 views
      0 likes
      Last Post jaybedreamin  
      Started by DJ888, 04-16-2024, 06:09 PM
      6 responses
      18 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by Jon17, Today, 04:33 PM
      0 responses
      1 view
      0 likes
      Last Post Jon17
      by Jon17
       
      Started by Javierw.ok, Today, 04:12 PM
      0 responses
      6 views
      0 likes
      Last Post Javierw.ok  
      Started by timmbbo, Today, 08:59 AM
      2 responses
      10 views
      0 likes
      Last Post bltdavid  
      Working...
      X