NexusFi: Find Your Edge


Home Menu

 





List.RemoveAt


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one SerCava with 2 posts (0 thanks)
    2. looks_two Quick Summary with 1 posts (0 thanks)
    3. looks_3 Fat Tails with 1 posts (0 thanks)
    4. looks_4 futuretrader with 1 posts (1 thanks)
    1. trending_up 4,266 views
    2. thumb_up 1 thanks given
    3. group 3 followers
    1. forum 5 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
 SerCava 
Madrid + Spain
 
Experience: Intermediate
Platform: NinjaTrader
Broker: CMC/Kinetick
Trading: Forex
Posts: 5 since May 2012
Thanks Given: 8
Thanks Received: 1

Hi all!

Anyone know how to use List.RemoveAt(index)?

I'm using:

 
Code
list.RemoveAt(Count-1);
but putting the indicator in the chart the log says...

 
Code
Error on calling 'OnBarUpdate' method for indicator 'SercavaEnvelope4' on bar 86: 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'm confused: If you have a list, you always have list[Count-1]

Commenting that line gives no error. Perhaps is a method too new? (is new for 2.0 .NET Framework)

Thanks in advance,

Sergio


Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Iran Update May 8: Still Reviewing MOU, Demands Reparati …
Traders Hideout
The Backwardation Signal: How the CL Futures Curve Tells …
Commodities
Six Days to Kickoff: World Cup Prediction Markets Hit $1 …
Prediction Markets & Event Contracts
Hormuz Completely Closed: US Strikes Day 2, Iran Shoots …
Traders Hideout
Iran Lebanon Problem Kills Switzerland Talks, Brent at $ …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
NexusFi site changelog and issues/problem reporting
10 thanks
Darmok and Jalad at Tanagra
3 thanks
Big Mike in Ecuador
1 thanks
30 Sessions
1 thanks
  #3 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Legendary Market Wizard
 
Experience: Advanced
Platform: NinjaTrader
Broker: Interactive Brokers
Trading: Futures & Stocks
Posts: 9,887 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,117


@SerCava:

It is difficult to find an error, if you just post one line. What is "list"? How many elements has "list"?

NinjaTrader uses 2 variables for the BarsArray[] object.

CurrentBar: The first bar has the index CurrentBar = 0. The last bar in the data base typically has the value CurrentBar = Count -1, if the indicator is set to CalculateOnBarClose = true, the indicator value for the last bar is not plotted, meaning that the last indicator value shown corresponds to CurrentBar = Count -2.

When OnBarUpdate() is executed it starts with CurrentBar = 0, and then makes one iteration for each historical bar. On real-time bars it will make one iteration, if the indicator is set to CalculateOnBarClose = true, otherwise it will make one iteration with every incoming tick.

Count - 1 usually holds the integer equal to the total number of bars of the BarsArray loaded, while CurrentBar steps up with each iteration until it reaches the value Count-2 (CalculateOnBarClose = true) or Count-1 (CalculateOnBarClose = false).


Reply With Quote
  #4 (permalink)
 
NJAMC's Avatar
 NJAMC 
Atkinson, NH USA
Legendary Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader 8/TensorFlow
Broker: NinjaTrader Brokerage
Trading: Futures, CL, ES, ZB
Posts: 1,951 since Dec 2010
Thanks Given: 3,042
Thanks Received: 2,397


SerCava View Post
I'm confused: If you have a list, you always have list[Count-1]

Commenting that line gives no error. Perhaps is a method too new? (is new for 2.0 .NET Framework)

Thanks in advance,

Sergio

@SerCava,

If I would guess, you need to check to see if "Count==0", this could create a negative index (which doesn't exist yet).


Nil per os
-NJAMC [Generic Programmer]

LOM WIKI: [wiki=NT-Local-Order-Manager-LOM-Guide][/wiki]
Artificial Bee Colony Optimization
Visit my NexusFi Trade Journal Reply With Quote
  #5 (permalink)
 futuretrader 
Como Italy
 
Experience: Intermediate
Platform: Ninjatrader, customized
Trading: ES
Posts: 525 since Feb 2010
Thanks Given: 471
Thanks Received: 643

As FatTails says, it's hard to tell from one line. But perhaps you mean to have:

List.RemoveAt(List.Count-1)

In NT, "Count", by itself, refers to the total # of bars.


Reply With Quote
Thanked by:
  #6 (permalink)
 SerCava 
Madrid + Spain
 
Experience: Intermediate
Platform: NinjaTrader
Broker: CMC/Kinetick
Trading: Forex
Posts: 5 since May 2012
Thanks Given: 8
Thanks Received: 1


futuretrader View Post
As FatTails says, it's hard to tell from one line. But perhaps you mean to have:

List.RemoveAt(List.Count-1)

In NT, "Count", by itself, refers to the total # of bars.

That was! Thanks. Sometimes you don't find the problem.... and I was using List.Count in other parts of the code, except in that line.

Thanks for all replies,

Sergio


Started this thread Reply With Quote




Last Updated on June 16, 2012


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts