Announcement

Collapse
No announcement yet.

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
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    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 Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      649 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      370 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      109 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      573 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      576 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X