NexusFi: Find Your Edge


Home Menu

 





I'm trying to print the values from an ArrayList


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one kaywai with 8 posts (0 thanks)
    2. looks_two NinjaTrader with 3 posts (1 thanks)
    3. looks_3 traderwerks with 1 posts (0 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 6,811 views
    2. thumb_up 2 thanks given
    3. group 2 followers
    1. forum 13 posts
    2. attach_file 1 attachments




 
Search this Thread

I'm trying to print the values from an ArrayList

  #1 (permalink)
kaywai
singapore
 
Posts: 131 since Nov 2009
Thanks Given: 11
Thanks Received: 7

This is part of the debugging process. Could someone please tell me how I can do that?

Regards

Kay Wai

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
REcommedations for programming help
Sierra Chart
What broker to use for trading palladium futures
Commodities
Strategy stop orders partially filled
EasyLanguage Programming
Quantum physics & Trading dynamics
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Funded Trader platforms
54 thanks
Just another trading journal: PA, Wyckoff & Trends
19 thanks
Self sabotage reframed
15 thanks
Trading with Intuition
14 thanks
GFIs1 1 DAX trade per day journal
9 thanks
  #3 (permalink)
 traderwerks   is a Vendor
 
Posts: 692 since Jun 2009
Thanks Given: 436
Thanks Received: 465



kaywai View Post
This is part of the debugging process. Could someone please tell me how I can do that?

Regards

Kay Wai

 
Code
   public static void PrintValues( IEnumerable myList )  {
      foreach ( Object obj in myList )
         Console.Write( "   {0}", obj );
      Console.WriteLine();
   }
谷歌是我們的朋友

Math. A gateway drug to reality.
Reply With Quote
  #4 (permalink)
kaywai
singapore
 
Posts: 131 since Nov 2009
Thanks Given: 11
Thanks Received: 7

Will try it. Thx!

Reply With Quote
  #5 (permalink)
kaywai
singapore
 
Posts: 131 since Nov 2009
Thanks Given: 11
Thanks Received: 7

I'm probably doing something wrong here. I can't seem to Add and Remove values from the ArrayList. The prints are not going to the output window. Could someone please help? I've attached the code. TIA! Kay Wai

P/S It's the first file in the zipfile.

Attached Files
Elite Membership required to download: ky.zip
Reply With Quote
  #6 (permalink)
 
NinjaTrader's Avatar
 NinjaTrader  NinjaTrader is an official Site Sponsor
Site Sponsor

Web: NinjaTrader
AMA: Ask Me Anything
Webinars: NinjaTrader Webinars
Elite offer: Click here
 
Posts: 1,714 since May 2010
Thanks Given: 203
Thanks Received: 2,686


kaywai View Post
I'm probably doing something wrong here. I can't seem to Add and Remove values from the ArrayList. The prints are not going to the output window. Could someone please help? I've attached the code. TIA! Kay Wai

P/S It's the first file in the zipfile.


Your problem is that your .Add() call will never be reached since you have a check in place on the list.Count property being greater than 2.

Follow me on Twitter Reply With Quote
  #7 (permalink)
kaywai
singapore
 
Posts: 131 since Nov 2009
Thanks Given: 11
Thanks Received: 7

May I know why that is the case? I only want to store the 2 most recent observations and discard the older observations.

Perhaps you could suggest a better way of doing this.

These observations only come about when a bool is true and I want to use the 2 most recent observations to draw horizontal lines which updates as new bars are created and stops when either 1) another bool becomes true or 2) the observation is "old". However, I would like to keep the old line on the chart, if possible.

I thought about using the DataSeries but I understand that when there is "no" data for it to add, it defaults to zero. trying to avoid that problem.

Reply With Quote
  #8 (permalink)
 
NinjaTrader's Avatar
 NinjaTrader  NinjaTrader is an official Site Sponsor
Site Sponsor

Web: NinjaTrader
AMA: Ask Me Anything
Webinars: NinjaTrader Webinars
Elite offer: Click here
 
Posts: 1,714 since May 2010
Thanks Given: 203
Thanks Received: 2,686


kaywai View Post
May I know why that is the case? I only want to store the 2 most recent observations and discard the older observations.

Perhaps you could suggest a better way of doing this.

These observations only come about when a bool is true and I want to use the 2 most recent observations to draw horizontal lines which updates as new bars are created and stops when either 1) another bool becomes true or 2) the observation is "old". However, I would like to keep the old line on the chart, if possible.

I thought about using the DataSeries but I understand that when there is "no" data for it to add, it defaults to zero. trying to avoid that problem.

Sure, you have a logic flaw in your code. Your code says only add to the arraylist if the arraylist has more than 2 items in it. Since the arraylist starts with a count of zero, it will never be greater than 2 since it can only ever be added to once the count is greater than 2. In other words, the greater than 2 condition can never be true.

This condition will never be executed since .Count > 2 will never be true. Your need to move the .Add() call outside of this if branch.

 
Code
if (TDSTBuy.Count > 2)
{ 
   TDSTBuy.RemoveAt(0); //if TDSTBuy is filled, drop the oldest value
   TDSTBuy.Add(setuphigh);
   Print(Time[0]);
 
}


Follow me on Twitter Reply With Quote
Thanked by:
  #9 (permalink)
kaywai
singapore
 
Posts: 131 since Nov 2009
Thanks Given: 11
Thanks Received: 7

HAHAHAHA! Thx much!

Reply With Quote
  #10 (permalink)
kaywai
singapore
 
Posts: 131 since Nov 2009
Thanks Given: 11
Thanks Received: 7


I change it like below, and I still don't know whether I'm getting anything into the ArrayList. Would you mind please helping?

 
Code

if (TDBuyExtendedSetupFX().buysetupmoveiscompleted)
{

drawtdstbuyline = true;
setuphigh = TDBuyExtendedSetupFX().hhbs;
TDSTBuy.Add(setuphigh);
if (TDSTBuy.Count > 2)
{
TDSTBuy.RemoveAt(0); //if TDSTBuy is filled, drop the oldest value
}
Console.WriteLine( "TDSTBuy" );
Console.WriteLine( " Count: {0}", TDSTBuy.Count );
Console.WriteLine( " Capacity: {0}", TDSTBuy.Capacity );
Console.Write( " Values:");
PrintValues(TDSTBuy);
}
}
publicstaticvoid PrintValues( IEnumerable TDSTBuy)
{
foreach (Object obj in TDSTBuy ) 
Console.Write(" {0}", obj);
Console.WriteLine();
}

Reply With Quote




Last Updated on May 13, 2011


© 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