NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 08-07-2012, 03:26 AM   #1
DerkWehler
Junior Member
 
Join Date: Aug 2012
Posts: 10
Thanks: 0
Thanked 0 times in 0 posts
Default MT Programmer new to NT, tips please?

Hi, I am an experienced programmer, having done MT4 for several years (and C++ a long time ago).

I have a NT indicator I am trying to convert to MT, and wondered if someone would be willing to give me a couple tips on some base class members I do not understand.

Hoping in the affirmative, I'll start with this:

Inside the class are some member functions that look like this:

[Browsable(false)]
[XmlIgnore]
public DataSeries aboveR1
{
get
{
return base.Values[1];
}
}

[Browsable(false)]
[XmlIgnore]
public DataSeries aboveS1
{
get
{
return base.Values[5];
}
}

[Browsable(false)]
[XmlIgnore]
public DataSeries belowR1
{
get
{
return base.Values[2];
}
}

[Browsable(false)]
[XmlIgnore]
public DataSeries belowS1
{
get
{
return base.Values[6];
}
}

[Browsable(false)]
[XmlIgnore]
public DataSeries midLOW
{
get
{
return base.Values[4];
}
}

[Browsable(false)]
[XmlIgnore]
public DataSeries midUP
{
get
{
return base.Values[3];
}
}

[Browsable(false)]
[XmlIgnore]
public DataSeries r2
{
get
{
return base.Values[0];
}
}

[Browsable(false)]
[XmlIgnore]
public DataSeries s2
{
get
{
return base.Values[7];
}
}


First off, I do not know what the "DataSeries" type returns exactly, and secondly what all the indexed "base.Values[]" mean.

Could someone explain this to me please, or maybe if you can send me the definition of the base class I could figure it out (?)

Thank you in advance!

PS: If there is a link to a tutorial / manual that explains all this well, please don't hesitate to send :-)
DerkWehler is offline  
Reply With Quote
Old 08-07-2012, 03:38 AM   #2
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,555
Thanks: 261
Thanked 1,013 times in 994 posts
Default

Welcome to our forums here - for getting starting coding in the C# based NinjaScript, please consider reviewing those tutorials -

http://www.ninjatrader.com/support/h.../tutorials.htm

Our DataSeries class is explained here - http://www.ninjatrader.com/support/h...ries_class.htm

The Values one here - http://www.ninjatrader.com/support/h...nt7/values.htm

For more advanced references samples and tips, please check into -

http://www.ninjatrader.com/support/f...splay.php?f=29
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 08-07-2012, 05:20 AM   #3
DerkWehler
Junior Member
 
Join Date: Aug 2012
Posts: 10
Thanks: 0
Thanked 0 times in 0 posts
Default Values[] followup

Thank you for the links.

Have read over them a bit, especially the Values array / objects.

Understand DataSeries now well enough... but when it references base.Values[?], still not sure what that would be referencing.

Of course my mind is still trying to do a MT4 conversion :-)
DerkWehler is offline  
Reply With Quote
Old 08-07-2012, 05:40 AM   #4
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,555
Thanks: 261
Thanked 1,013 times in 994 posts
Default

The Values array is a collection holding the values calculated for the indicators, the plots added in the Initialize only determine how those should be visualized - this is basically the 'link' from the plot characteristics to the actual values plotted then.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 08-07-2012, 05:42 AM   #5
DerkWehler
Junior Member
 
Join Date: Aug 2012
Posts: 10
Thanks: 0
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by NinjaTrader_Bertrand View Post
The Values array is a collection holding the values calculated for the indicators, the plots added in the Initialize only determine how those should be visualized - this is basically the 'link' from the plot characteristics to the actual values plotted then.
Ok, I think I get that. But then the code I listed, calling base.Values[1].... The base class is "indicator". Aren't there some rules for what Values[] holds for that base class?

Or am I not quite getting it?
DerkWehler is offline  
Reply With Quote
Old 08-07-2012, 05:50 AM   #6
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,555
Thanks: 261
Thanked 1,013 times in 994 posts
Default

Those objects would hold double values.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 08-07-2012, 06:08 AM   #7
DerkWehler
Junior Member
 
Join Date: Aug 2012
Posts: 10
Thanks: 0
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by NinjaTrader_Bertrand View Post
Those objects would hold double values.
Yes, I know, but WHAT values?

Ah... or is base.Values[1] just referring to the inherited class (my ind) Values array?
DerkWehler is offline  
Reply With Quote
Old 08-07-2012, 06:30 AM   #8
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,555
Thanks: 261
Thanked 1,013 times in 994 posts
Default

That's correct DerkWehler.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 08-07-2012, 06:36 AM   #9
DerkWehler
Junior Member
 
Join Date: Aug 2012
Posts: 10
Thanks: 0
Thanked 0 times in 0 posts
Default

muy gracias senior

Will see how far I can get on that. Appreciate the help.
DerkWehler is offline  
Reply With Quote
Old 08-08-2012, 02:49 AM   #10
DerkWehler
Junior Member
 
Join Date: Aug 2012
Posts: 10
Thanks: 0
Thanked 0 times in 0 posts
Default So far so good

Hello any readers:

Things are coming along. I think I am understanding much of the coding.

But a brief question on this code snippet:

protected override void OnBarUpdate()
{
double item;
double num;
double num1;
if (base.CurrentBar == 0)
{
item = base.Close[0];
}
else
{
item = base.Close[0] * 0.2 + 0.8 * base.Close[1];
}
...

Unlike MT, which runs through a loop for each bar, I am assuming OnBarUpdate gets called for each bar on the chart..(?)

So when it says:

if (base.CurrentBar == 0)
{
item = base.Close[0];
}
else
{
item = base.Close[0] * 0.2 + 0.8 * base.Close[1];
}

Is that saying "if the bar we are working on is the open candle ("base.CurrentBar == 0" means the right-most open candle I assume, or is it the one that just closed?), then set:

item = Close price of open (or most recently closed) candle

else set

item = Close price of right-most candle * 20% + Close price of previous candle * 80%

--OR--

Does base.Close[0] here refer to the close of whatever candle we are working on?

In other words, if OnBarUpdate is called for each candle, and the one it's currently working on is the 10th candle from the right, then does base.Close[0] refer to THAT candle, and base.Close[1] refer to the 11th candle from the right?

PS: I am not sure how to get this editor to respect the tabs in my code when I paste it. Is there a trick?
DerkWehler is offline  
Reply With Quote
Old 08-08-2012, 03:23 AM   #11
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,555
Thanks: 261
Thanked 1,013 times in 994 posts
Default

DerkWehler, glad to hear you're moving along nicely - OnBarUpdate() is called for each bar on the chart from left to right, so CurrentBar = 0 is the first bar on the left and not the rightmost one.

What Close[0] is depends on your CalculateOnBarClose setting for the script (for realtime processing) -

http://www.ninjatrader.com/support/h...onbarclose.htm

With this setting to 'true' you're processing the currently last closed candle, and not the developing right most one - this can only be accessed with 'false' and the [0] index. In this scenario then an index of [1] would mean the last completed candle.

In backtesting / historical data this would always be 'true'.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 08-08-2012, 03:38 AM   #12
DerkWehler
Junior Member
 
Join Date: Aug 2012
Posts: 10
Thanks: 0
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by NinjaTrader_Bertrand View Post
DerkWehler, glad to hear you're moving along nicely - OnBarUpdate() is called for each bar on the chart from left to right, so CurrentBar = 0 is the first bar on the left and not the rightmost one.

What Close[0] is depends on your CalculateOnBarClose setting for the script (for realtime processing) -

http://www.ninjatrader.com/support/h...onbarclose.htm

With this setting to 'true' you're processing the currently last closed candle, and not the developing right most one - this can only be accessed with 'false' and the [0] index. In this scenario then an index of [1] would mean the last completed candle.

In backtesting / historical data this would always be 'true'.
Ok, I understand that, and have this setting:

base.set_CalculateOnBarClose(true);

So, calculating from the left, and it is on the 5th bar from the left at the moment, base.Close[0] refers to the close price of the current (5th from left) bar then?

And base.Typical[1] refers to the previous (4th bar from left) bar's typical price, (high + low + close) / 3 ? Or does it refer to the 6th bar from the left?
DerkWehler is offline  
Reply With Quote
Old 08-08-2012, 03:56 AM   #13
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,555
Thanks: 261
Thanked 1,013 times in 994 posts
Default

You are correct in understanding, and index of 1 would mean one bar back. We would not supporting looking into the 'future' with indexing.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 08-08-2012, 04:10 AM   #14
DerkWehler
Junior Member
 
Join Date: Aug 2012
Posts: 10
Thanks: 0
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by NinjaTrader_Bertrand View Post
You are correct in understanding, and index of 1 would mean one bar back. We would not supporting looking into the 'future' with indexing.
Makes sense!

Thanks again Bertrand!

Probably will yet have a couple more questions, but that should get me translating most of it. :-)
DerkWehler is offline  
Reply With Quote
Old 08-08-2012, 04:30 AM   #15
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,555
Thanks: 261
Thanked 1,013 times in 994 posts
Default

You're welcome, best of luck on the conversions.
NinjaTrader_Bertrand is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Performance tips? trader2be General Programming 3 10-19-2010 06:21 AM
MT Predictor indicators JOHNF1 NinjaScript File Sharing Discussion 20 07-19-2010 07:11 PM
Need tips for a strategy barrosco Miscellaneous Support 2 02-20-2009 01:01 PM
some tips when using vista qwert12 Installation and Licensing 1 06-30-2008 11:29 PM
A simple question from a new NT programmer elemento-portador Indicator Development 1 11-05-2007 08:00 AM


All times are GMT -6. The time now is 04:52 PM.