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 f.saeidi, Today, 11:02 AM
      1 response
      1 view
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by geotrades1, Today, 10:02 AM
      4 responses
      11 views
      0 likes
      Last Post geotrades1  
      Started by rajendrasubedi2023, Today, 09:50 AM
      3 responses
      15 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by lorem, Today, 09:18 AM
      2 responses
      11 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by geddyisodin, Today, 05:20 AM
      4 responses
      30 views
      0 likes
      Last Post geddyisodin  
      Working...
      X