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 3,700 views
    2. thumb_up 1 thanks given
    3. group 3 followers
    1. forum 5 posts
    2. attach_file 0 attachments




 
Search this Thread

List.RemoveAt

  #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?
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
About a successful futures trader who didnt know anythin …
Psychology and Money Management
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
REcommedations for programming help
Sierra Chart
Trade idea based off three indicators.
Traders Hideout
 
  #3 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,103


@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
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader 8/TensorFlow
Broker: NinjaTrader Brokerage
Trading: Futures, CL, ES, ZB
Posts: 1,970 since Dec 2010
Thanks Given: 3,037
Thanks Received: 2,395


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: NT-Local-Order-Manager-LOM-Guide
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


© 2024 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 - Privacy Policy - Downloads - Top
no new posts