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

To save the CurrentBars[0] value to a variable when a crossover happens.

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

    To save the CurrentBars[0] value to a variable when a crossover happens.

    Precisely how would I write this out? To save CurrentBars[0] value to a variable. So, when a crossover happens lines update.


    // Calculate the startBarsAgo as CurrentBars[0] - savedCrossBelowBar.

    //Calling Draw.Line() with the same tag in OnBarUpdate() will update the object being drawn.

    I meant to put under strategy not indicators, sorry.
    Attached Files
    Last edited by trdninstyle; 12-30-2023, 11:58 AM.

    #2
    Hello trdninstyle,

    Thanks for your post.

    This error message means that the variable 'savedCrossBelowBar' does not exist at the time you are accessing it.

    You could create a variable in your script called 'savedCrossBelowBar'.

    Then assign the CurrentBar value to the variable within your CrossBelow() condition. After assigning the value to it you could use it later in your script.

    For example:

    //class level variable
    private int savedCrossBelowBar;

    //OnBarUpdate()
    if (CrossBelow condition)
    {
    savedCrossBelowBar = CurrentBar;
    }


    See the help guide documentation below for more information.

    CurrentBar: https://ninjatrader.com/support/help...sub=CurrentBar
    Basic Programming Concepts: https://ninjatrader.com/support/help...g_concepts.htm

    Below is a link to a forum post with helpful information about getting started with NinjaScript.
    https://ninjatrader.com/support/foru...040#post786040
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Thanks for this, I did see private int a few times the other day when I was searching things out.

      I'll get my head back into it, probably tomorrow. I'm content pretty much the way I have this indicator for now, I'm just trying to tweak it which requires more code.
      Thanks, Bill. Happy New Year

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Haiasi, 04-25-2024, 06:53 PM
      2 responses
      16 views
      0 likes
      Last Post Massinisa  
      Started by Creamers, Today, 05:32 AM
      0 responses
      4 views
      0 likes
      Last Post Creamers  
      Started by Segwin, 05-07-2018, 02:15 PM
      12 responses
      1,785 views
      0 likes
      Last Post Leafcutter  
      Started by poplagelu, Today, 05:00 AM
      0 responses
      3 views
      0 likes
      Last Post poplagelu  
      Started by fx.practic, 10-15-2013, 12:53 AM
      5 responses
      5,407 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Working...
      X