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

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 trilliantrader, 04-18-2024, 08:16 AM
    4 responses
    18 views
    0 likes
    Last Post trilliantrader  
    Started by mgco4you, Today, 09:46 PM
    1 response
    7 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by wzgy0920, Today, 09:53 PM
    0 responses
    9 views
    0 likes
    Last Post wzgy0920  
    Started by Rapine Heihei, Today, 08:19 PM
    1 response
    10 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by Rapine Heihei, Today, 08:25 PM
    0 responses
    10 views
    0 likes
    Last Post Rapine Heihei  
    Working...
    X