Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

input variable inside OnBarUpdate

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

    input variable inside OnBarUpdate

    Hi,
    Is there a way to place a user input inside of OnBarUpdate? I have some test code that I want to be able to insert into other strategies, and it has a value that i need available in settings so that it can be given an optimization range.
    thanks,
    David

    #2
    I'm not certain I understand what you are trying to do, but to matter-of-factly answer your question, if you were to put the property definition for the input parameter inside the scope of the OnBarUpdate method, it would no longer compile. That is not a valid syntax in C# to define properties within a method.

    Have you consider approaching this using a partial class or an abstract base class? In this way, you could define a "basic" stratregy extension that includes the optimizable parameter and whatever else is in common, and then your individual strategies could extend that functionality.
    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    Comment


      #3
      Hello trader3000a,

      A user input requires that you make a public property for that and apply the [NinjaScriptProperty] to it so its optimizable. A public property needs to be defined at class level outside of OnBarUpdate. You can use that input inside of OnBarUpdate by calling it by name. The actual property is defined outside OnBarUpdate.

      You can see the SampleMACrossOver for a simple example of a script that uses a user input that is optimizable inside OnBarUpdate.

      Another way to approach this is to use the strategy builder to define inputs and then click View Code, that will show the correct placement for user inputs and also shows how give a default value and how to limit the to a range of values for the optimizer.

      Comment

      Latest Posts

      Collapse

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