PDA

View Full Version : How can access a variable defined in other section


jrbolsa
04-06-2009, 12:02 PM
Hello again,

If I define a variable in the Initialize() section, like
string path = @"c:\jrbolsa\xxx.txt"

How can I use it in the OnBarUpdate() section?

Do you have any simple sample ? :-)

regards,
jr.

NinjaTrader_Josh
04-06-2009, 12:14 PM
jrbolsa,

You should not define it in the Initialize(). Do it in the Variables region of your code.

jrbolsa
04-06-2009, 12:19 PM
I can't. Because the real variable is:
string path = @"c:\jrbolsa\ntcot\"+spliti[0]+".txt";
I must obtain that "spliti[0]" string from another variable (a txt file) and I must read that file (all the file) in order to obtain the first part of the line.

NinjaTrader_Josh
04-06-2009, 12:21 PM
Do it in OnBarUpdate() then. You should not do anything like this in Initialize().

jrbolsa
04-06-2009, 12:23 PM
I'll try that but in that case it will be done for each bar. Am i right?

NinjaTrader_Josh
04-06-2009, 12:39 PM
You can filter it if you don't want it to do it every bar.

if (CurrentBar == 0)
// do something

jrbolsa
04-06-2009, 12:42 PM
Resolved although it does what i thought. And it lasts too long.
But great idea!!. Thanks a lot.