NexusFi: Find Your Edge


Home Menu

 





List<>, convert/change method property into string


Discussion in NinjaTrader

Updated
    1. trending_up 563 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 3 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
Amedeus
Montpellier France
 
Posts: 4 since Jul 2021
Thanks Given: 4
Thanks Received: 0

hello everyone,

working on flags.

I have a List<Flag> myList.
The method of the Class Flag is : Flag(string name, int barNb, DateTime barTime)

the question about it is in the createFlag(List<Flag> flagListName) method.
ultimately, we try to fill the myList.Name accordingly and
the expected output is : myList.Last().Name is : myList, how to get there ?

 
Code
protected override void OnBarUpdate()	
{		
	if (CrossAbove(Close[1], someDouble, 1) == true)	
	{
		createFlag(myList);
		if (myList.Count() > 0 )
		{
			Print("myList.Last().Name is : "+ myList.Last().Name);
		}
	}
}
private void createFlag(List<Flag> flagListName)	
{	
	// is it possible to convert the property name/code into a string here ?
	// flagListName	.Add(new Flag( somesyntax(flagListName), CurrentBar-1, Time[1])); 
	
	flagListName	.Add(new Flag( "flagListName", CurrentBar-1, Time[1])); 
	// output : myList.Last().Name is : flagListName
	flagListName	.Add(new Flag( flagListName.ToSting(),  CurrentBar-1, Time[1]));
	// output : myList.Last().Name is : System.Collections.Generic.List`1[NinjaTrader.NinjaScript.Indicators.myIndicator+Flag]
	flagListName	.Add(new Flag( nameof(flagListName), CurrentBar-1, Time[1])); 
	// output : myList.Last().Name is : flagListName
	
}
Thank you.


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Friday Update: Markets Now Pricing Fed Rate HIKES as Sta …
Traders Hideout
Prediction Markets Expiry Day: Trump Eyes War Exit, $230 …
Prediction Markets & Event Contracts
Irans Answer Due Today: Peace Surges to 33.5%, Invasion …
Prediction Markets & Event Contracts
Kalshi Rockets to $22B, Passes Polymarket in Volume -- B …
Prediction Markets & Event Contracts
Q1 2026 Shatters All Derivatives Volume Records -- CME H …
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
22 thanks
2026 Jlab journal
10 thanks
Trying to learn Volume and price action correlation
8 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Lady Vols Primer: Trading Volatility Journal
5 thanks
  #2 (permalink)
 Eubie 
Prague, Czech republic
 
Experience: Beginner
Platform: NinjaTrader/ZF
Trading: ES, TF
Posts: 169 since Jul 2010
Thanks Given: 393
Thanks Received: 134


Amedeus View Post
hello everyone,

working on flags.

I have a List<Flag> myList.
The method of the Class Flag is : Flag(string name, int barNb, DateTime barTime)

the question about it is in the createFlag(List<Flag> flagListName) method.
ultimately, we try to fill the myList.Name accordingly and
the expected output is : myList.Last().Name is : myList, how to get there ?

 
Code
protected override void OnBarUpdate()	
{		
	if (CrossAbove(Close[1], someDouble, 1) == true)	
	{
		createFlag(myList);
		if (myList.Count() > 0 )
		{
			Print("myList.Last().Name is : "+ myList.Last().Name);
		}
	}
}
private void createFlag(List<Flag> flagListName)	
{	
	// is it possible to convert the property name/code into a string here ?
	// flagListName	.Add(new Flag( somesyntax(flagListName), CurrentBar-1, Time[1])); 
	
	flagListName	.Add(new Flag( "flagListName", CurrentBar-1, Time[1])); 
	// output : myList.Last().Name is : flagListName
	flagListName	.Add(new Flag( flagListName.ToSting(),  CurrentBar-1, Time[1]));
	// output : myList.Last().Name is : System.Collections.Generic.List`1[NinjaTrader.NinjaScript.Indicators.myIndicator+Flag]
	flagListName	.Add(new Flag( nameof(flagListName), CurrentBar-1, Time[1])); 
	// output : myList.Last().Name is : flagListName
	
}
Thank you.

Hey,

I think you should rephrase your question. I tried to read it three times and didn't get what you want / what the problem is.

Cheers,
D.


Reply With Quote
Thanked by:
  #3 (permalink)
Amedeus
Montpellier France
 
Posts: 4 since Jul 2021
Thanks Given: 4
Thanks Received: 0



Eubie View Post
Hey,

I think you should rephrase your question. I tried to read it three times and didn't get what you want / what the problem is.

Cheers,
D.

Hey, Thanks Eubie,

Wow I am so sorry for the lack of clarity, and the wrong choice of words, here is how I would rephrase it :

Is it possible to convert the method parameter (flagListName) into a string, inside the createFlag() method ? In order to make it a string that will be added to myList as the name of the flag.

something that may look like this :
flagListName .Add(new Flag( somesyntax(flagListName), CurrentBar-1, Time[1]));

 
Code
protected override void OnBarUpdate()
{
   if (CrossAbove(Close[1], someDouble, 1) == true)
   {
      createFlag(myList);
      Print(myList.Last().Name);
   }
}
private void createFlag(List<Flag> flagListName)
{
   flagListName .Add(new Flag( somesyntax(flagListName), CurrentBar-1, Time[1]));
}
ultimately, the output for this print would be :
myList


Reply With Quote
  #4 (permalink)
Amedeus
Montpellier France
 
Posts: 4 since Jul 2021
Thanks Given: 4
Thanks Received: 0

One way to go around this could be to add a string parameter as follow.
I just wondered if the conversion could be done inside the method. And evaluate if it would be worth it.
 
Code
protected override void OnBarUpdate()
{
    if (CrossAbove(Close[1], someDouble, 1) == true)
    {
        createFlag(myList, "myList");
        Print(myList.Last().Name);
    }
}

private void createFlag(List<Flag> flagList, string flagListName)
{
    flagList.Add(new Flag(flagListName, CurrentBar - 1, Time[1]));
}


Reply With Quote




Last Updated on August 31, 2024


© 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