PDA

View Full Version : Accessing chart name via NT scipt


funk101
03-27-2007, 09:04 AM
This must be simple, but can't find, a method for return the name of the chart that a strategy is being run on?

NinjaTrader_Ray
03-27-2007, 09:13 AM
Charts do not have names. Do you mean the instrument?

Ray

funk101
03-27-2007, 09:38 AM
Yes, sorry. Any way to identify the chart/instrument when outputting to output window

NinjaTrader_Ray
03-27-2007, 09:46 AM
Please see this post - http://ninjatrader.mywowbb.com/forum20/1554.html

It will provide you with the answer you seek.

Ray

funk101
03-27-2007, 09:50 AM
Yes, that's it. So, where do *I* find these types of things out? It's not in the online help. I hate to keep asking these lame questions.

NinjaTrader_Ray
03-27-2007, 09:58 AM
This was not documented yet. It is in my current working DOC that will be published with the next update. The complete DOC will be done by production release around the second week of April.

Ray

funk101
03-27-2007, 10:03 AM
Cool, thanks...I don't feel like a "lame-o" now :)

funk101
03-27-2007, 11:32 AM
Can you explain why this code doesn't execute?



This is set -> Initialize();

instrumentName = Instrument.FullName;

----

This is run -> OnBarUpdate();

if (Position.MarketPosition != MarketPosition.Flat){

Print (instrumentName+" PnL "+Position.GetProfitLoss(Close[0], PerformanceUnit.Points));

if (Position.GetProfitLoss(Close[0],PerformanceUnit.Points) >= 9){

Print (instrumentName+" trail stop set to 6");

SetTrailStop(CalculationMode.Ticks, 6);

}

}

NinjaTrader_Ray
03-27-2007, 11:36 AM
Check the log tab, I suspect you get a null reference exception in which case NT stops processing the strategy. Instrument may not yet be set in Initialize().

Alternatively, you can just access in OnBarUpdate()

Instrument.FullName

or

if (instrumentName.Length == 0)
instrumentName = Instrument.FullName;


Ray

funk101
03-27-2007, 11:51 AM
No, intrumentName is set, I can see in output window. The strategy runs.

Just trying to reset TrailStop if profit is >= 9 PerformanceUnit.Points...hmm

ThePatientOne
03-28-2007, 06:25 PM
I am attempting to use Instrument.FullName inside of the OnBarUpdate method of a custom indicator but am receiving a compile time error stating:'

An object reference is required for the nonstatic field, method, or property ...

I was assuming that this object was part of the core NinjaTrader dll. Is this so? Is there something I am missing regarding syntax? My exact code line is:

symbolName = Instrument.FullName;

funk101
03-28-2007, 06:36 PM
I'm assuming you need to initialize in "#region Variables"

private string symbolName = "";

ThePatientOne
03-28-2007, 07:04 PM
Already thought of that one. I only need the variable in the OnBarUpdate so I initially declared it as local to that method. Then, after getting the error, I put it in the classes global variable declaration and initialized it to no success.

Thanks for the response though.

NinjaTrader_Ray
03-29-2007, 02:01 AM
Please use

symbolName = Bars.Instrument.FullName;

for now.

Ray

NinjaTrader_Ray
03-29-2007, 02:16 AM
The current documentation is not reflective of actual usage. The next release will allow you to accesss "Instrument" within an indicator without having to go through the "Bars" object.

Ray