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

how to use variable

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

    how to use variable

    Hi,

    I am trying to learn Ninja script.
    I need some help with this simple strategy I did in Strategy Builder.

    It is just a simple strategy that I want to have a variable control how many consecutive Renko bars in the same direction appear before I enter a trade.

    All the bars have to be in the same direction. up or down.

    how do I replace the '15' with a variable from 1 to 15?


    // Condition set 1
    if (DM(DMperiod).DiMinus[0] < 1
    && DM(DMperiod).DiMinus[15] < 1)
    {
    EnterLong(Contracts, "Long 1");
    }

    Thanks, n1144n

    #2
    Hello n1144n

    Thanks for your post.

    I may be misunderstanding your question, if so, please ask in another way.

    I think you are asking how, directly in Ninjascript, to replace 15 with a variable that you can set from the user panel when applying the strategy.

    You could need to create a public variable, call, for example, "Lookback" in the region properties. Here is an example:

    [Range(1, int.MaxValue), NinjaScriptProperty]
    [Display(ResourceType = typeof(Custom.Resource), Name = "Lookback", GroupName = "NinjaScriptParameters", Order = 1)]
    public int Lookback
    { get; set; }


    In State.SetDefaults you would need to set the default for the property, for example: Lookback = 5; // default to 5 bars lookback.

    Then in OnBarUpdate() you would replace 15 with Lookback, for example:

    && DM(DMperiod).DiMinus[Lookback] < 1)
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thank you Paul. I will give it a try.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by helpwanted, Today, 03:06 AM
      1 response
      12 views
      0 likes
      Last Post sarafuenonly123  
      Started by Brevo, Today, 01:45 AM
      0 responses
      9 views
      0 likes
      Last Post Brevo
      by Brevo
       
      Started by aussugardefender, Today, 01:07 AM
      0 responses
      5 views
      0 likes
      Last Post aussugardefender  
      Started by pvincent, 06-23-2022, 12:53 PM
      14 responses
      242 views
      0 likes
      Last Post Nyman
      by Nyman
       
      Started by TraderG23, 12-08-2023, 07:56 AM
      9 responses
      387 views
      1 like
      Last Post Gavini
      by Gavini
       
      Working...
      X