Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How do I get IsRising / IsFalling from previous bars?

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

    How do I get IsRising / IsFalling from previous bars?


    Hi there, how can I get the IsRising Value, from previous bars? That is, I can do:

    Print("The val is " + SMA(20)[5]);
    Print("Is Rising is " + IsRising(SMA(20)));​

    But, when I attempt to combine both of these:

    Print("Is rising 5 bars ago is " + IsRising(SMA(20))[5]);

    Then I get an overloaded error. How can I perform IsRising, beyond the current bar?

    Thanks
    Last edited by timmbbo; 04-12-2023, 10:39 PM.

    #2
    I don't think you can.

    You could create a Series<bool> and keep track of the value of every
    IsRising result on every bar, but that seems like overkill.

    I suggest you roll your own IsRising method, something like this,

    Code:
    private bool IsRising(ISeries<double> ds, int startBarsAgo, int lookback)
    {
        if (lookback < 1)
            throw new ArgumentException("Lookback cannot be zero or negative");
    
        if (CurrentBar < startBarsAgo+lookback)
            return false;
    
        int nGood = 0;
        for (int barsAgo = startBarsAgo, cnt = 0; cnt < lookback; ++cnt, ++barsAgo)
            if (ds[barsAgo] > ds[barsAgo+1])
                ++nGood;
    
        return nGood == lookback;
    }
    ​
    [Because my method signature is different than the builtin signature (my 3 args
    to the builtin version's 1 arg), reusing the name 'IsRising' is a great example of
    'method overloading'. The point is: when a method name is perfect, why use a
    different name when you don't have to? That is, 'IsRising' is also a great name
    for my method, so by using method overloading, I can use the same name as
    the builtin method. The only caveat is that someday NT engineers may want to
    expose their own overloaded method using same signature as mine. No prob,
    if that were to happen, we'd get a compiler error, and then we'd be forced to
    change our method signature, or change our method name. So, until then ...]

    Using my overloaded method is pretty simple.

    The builtin IsRising(SMA(20)) is equivalent to IsRising(SMA(20), 0, 1).

    To get the 5th BarsAgo value of IsRising, you'd use IsRising(SMA(20), 5, 1).

    If you want to know if IsRising is true over the last 5 bars, use IsRising(SMA(20), 0, 5).

    Enjoy!

    Comment


      #3
      Hello timmbbo,

      Thanks for your notes.

      bltdavid is correct. Since IsRising() and IsFalling() do not have a barsAgo parameter available to pass into these methods, the value for previous bars is not accessible.

      IsRising(): https://ninjatrader.com/support/help...nt8/rising.htm
      IsFalling(): https://ninjatrader.com/support/help...t8/falling.htm

      You may consider using the workarounds that bltdavid shared to accomplish your goal.

      Please let me know if I may assist further.
      <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

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      70 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