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

How to use Market Analyzer as a scanner - 2

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

    How to use Market Analyzer as a scanner - 2

    Hi there,

    I am writing a custom indicator to be used in Market Analyzer. But I can't get any data other than [0]. Here is an example code:

    if ( SMA(50)[0] > SMA(50)[20] )
    {
    Plot0.Set(1);
    } else {
    Plot0.Set(0);
    }

    In code above, SMA(50)[0] work fine, but SMA(50)[20] is causing the following error:
    "Error on calling 'OnBarUpdate' method for indicator 'TrendDetector' on bar 0: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart."

    I added :

    if (CurrentBar < 50); return;

    at the beginning of the code, but then code exits right there and never processes the rest.

    What I need is very simple as the code implies: I want indicator to plot 1, if SMA(50) value of today is larger than SMA(50) value 20 days ago.

    This is on a daily stock data.

    Any help is appreciated.

    Nick.

    #2
    Hi 10percent,

    First, your CurrentBar check has an extra semi-colon, should read as...

    Code:
    if (CurrentBar < 20) return;
    Also, you will only need to check this on 20 bars, as above.

    Try this on a chart first, make sure you have plenty of bars on the chart loaded (more than 50).
    TimNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by wzgy0920, 04-20-2024, 06:09 PM
    2 responses
    26 views
    0 likes
    Last Post wzgy0920  
    Started by wzgy0920, 02-22-2024, 01:11 AM
    5 responses
    32 views
    0 likes
    Last Post wzgy0920  
    Started by wzgy0920, Yesterday, 09:53 PM
    2 responses
    49 views
    0 likes
    Last Post wzgy0920  
    Started by Kensonprib, 04-28-2021, 10:11 AM
    5 responses
    191 views
    0 likes
    Last Post Hasadafa  
    Started by GussJ, 03-04-2020, 03:11 PM
    11 responses
    3,230 views
    0 likes
    Last Post xiinteractive  
    Working...
    X