Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Does NT have function like valuewhen and barssince ?

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

    Does NT have function like valuewhen and barssince ?

    I want to know which function of NT or Method like MetaStock function below:

    1) valuewhen ( Nth, EXPRESSION, DATA ARRAY )
    2) barssince( DATA ARRAY )



    valuewhen ( Nth, EXPRESSION, DATA ARRAY )

    FUNCTION

    Returns the value of the DATA ARRAY when the EXPRESSION was true on the Nth most recent occurrence. This includes all data loaded in the chart.

    EXAMPLE

    The formula "valuewhen( 2, cross(c,mov(c,10,s), rsi(20) )" returns the value of the RSI on the 2nd most recent occurrence of the closing price crossing above its 10-day moving average.





    barssince( DATA ARRAY )

    FUNCTION

    Calculates the number of bars (time periods) that have passed since DATA ARRAY was true.

    Important: When using the barssince() function in an exploration, you must click the "Load ___ Records" button in the Exploration Options dialog and specify a value equal to the number of bars loaded in your chart; otherwise, the exploration results may not be accurate.

    EXAMPLE

    barssince( macd() < 0 )


    THX ~

    #2
    You can use the NinjaScript method MRO(Condition condition, int instance, int lookBackPeriod), where MRO stands for "Most Recent Occurence".

    "condition" would be any logical expression such as a moving average cross.
    "instance" points to the occurence to check for; a value of 3 would return the 3rd most recent occurrence.
    "lookBackPeriod" refers to the number of bars that are searched. If you set this value to "CurrentBar" the search will go back over the entire chart.

    However, MRO returns an integer and is not comparable to "valuewhen".
    To obtain the value of a RSI(20) for the second most recent occurence you would need to reference the integer returned by MRO, for example:

    Code:
    valuewhen( 2, cross(c,mov(c,10,s), rsi(20) )
    would translate to

    Code:
    int lookback = MRO(delegate {return CrossAbove(Close, SMA(10), 0);} 2, CurrentBar);
    double value = RSI(20)[lookback];
    where "value" would hold the RSI(20) at the time of the second but the last crossover.

    Please look up the NinjaScript Language Reference for further details, or search for MRO via the NinjaTrader Control Center -> Help -> Help -> Search.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    595 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    343 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    103 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    556 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    554 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X