Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Can't access 1 bar ago in custom indicator

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

    Can't access 1 bar ago in custom indicator

    In a custom indicator, I cannot access a value 1 bar ago. For example EMA(13)[1] will not print to the output window and causes the indicator not to work at all.

    I thought maybe you couldn't refer to bars ago on indicators, so I set up a DataSeries to keep the values and that doesn't work either.

    In both cases, if you refer to a value 1 bar ago, the value will not print and causes the indicator to totally fail (i.e. nothing printed to output window, doesn't plot on chart, and doesn't show up in databox). As soon as you take the reference to 1 bar ago out, it works perfectly.

    I created a simple test program that shows the behaviour and is basically the same as the one shown in documenation on DataSeries. The program is attached. I can send you screen shots as well if needed.

    Building this indicator is critical to a strategy I'm developing, so I'd appreciate any possible escalation on either fixing this if it's a bug or letting me know what I'm doing wrong.

    Best regards,

    Bob
    Attached Files

    #2
    imported post

    Hi Bob,

    Problem is a simple one. You will get indexout of range exceptions (in the Control Center Log tab) when you attempt to access a value that does not exist.

    Change your code to the following:
    myDataSeries.Set(Close[0]);

    // Make sure thereare more than 1 value in myDataSeries before printing
    if (CurrentBar > 0)
    Print("The values are" + myDataSeries[0] + " " + myDataSeries[1]);
    RayNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by fscabrera03, Today, 01:18 PM
    1 response
    11 views
    0 likes
    Last Post fscabrera03  
    Started by BottomShark77, Today, 12:20 PM
    1 response
    10 views
    0 likes
    Last Post NinjaTrader_ShawnB  
    Started by bowling, Today, 06:16 AM
    3 responses
    29 views
    0 likes
    Last Post NinjaTrader_ShawnB  
    Started by systemtrader4, Today, 01:54 AM
    2 responses
    87 views
    0 likes
    Last Post systemtrader4  
    Started by Futurestrader00, Today, 01:54 AM
    1 response
    36 views
    0 likes
    Last Post NinjaTrader_ShawnB  
    Working...
    X