![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Jun 2010
Posts: 222
Thanks: 14
Thanked 4 times in 4 posts
|
I have a few basic questions concerning code scripting. Please note that I am an almost total newbie, have read some of the NT Tutorials and am trying to get into this subject. I opened the code for NT's "SMA" indicator to formulate my questions:
Each indicator code script seems to have three basic sections. 1. The first section, when expanded, lists some declarations (like using System.Diagnostics; using System.Drawing;etc etc.) - I do not change these. Correct? 2. The second section contains - in this case for the SMA indicator - three sub sections: 2.0. First it states the name of the indicator with: "public class SMA : Indicator". This is where I give my indicator a name, correct? 2.1. It then has a sub-section "Variables" which begins with #region and ends with #endregion: private int period = 14; Once the indicator building is complete, this is what shows up as the default value. Correct? 2.2. Now come the sub-sections called "protected override void Initialize()" and "protected override void OnBarUpdate()". No question on these because I believe there is plenty of explanations in the NT Help section which I will study. 2.3. Now comes a sub-section called "#region Properties". Why is the earlier subsection "private int" but this one "public int"? Where can I read something about the difference between the two? 3. The third section is entitled NT generated code. Neither change nor remove. I take it to mean just that: I do not need to mess with it at all. It is created when I am done in Section 1 and 2 above and push the COMPILE button. Correct? Lastly, one probably more advanced question: I want to evenutally create a multi time frame script. In which of the above three section do I need to put the Syntax "BarsArray [int index]"? sandman |
|
|
|
|
|
#2 | |||||||
|
NinjaTrader Customer Service
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
|
sandman,
I am happy to assist. Quote:
Quote:
Quote:
Quote:
Quote:
http://en.wikipedia.org/wiki/Object-...ed_programming Quote:
Quote:
Please let me know if I may assist further.
Adam P.
NinjaTrader Customer Service |
|||||||
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Jun 2010
Posts: 222
Thanks: 14
Thanked 4 times in 4 posts
|
Thanks Adam, that helps in getting me oriented.
sandman |
|
|
|
|
|
#4 |
|
Senior Member
Join Date: Jun 2010
Posts: 222
Thanks: 14
Thanked 4 times in 4 posts
|
Adam.
I do have another immediate question. I am using one custom made multi time frame indicator already. It takes 1,2,3 and 5 minute inputs. When I now apply this indicator on a 4Range chart it still works/shows up. I wonder what it actually now works on, and I believe someone told me that NinjaTrader's program would in this case "replace" the "1-minute" condition with "4-range" while maintaining the 2,3 and 5-conditions. Is that correct? (I hope my question makes sense). sandman |
|
|
|
|
|
#5 |
|
NinjaTrader Customer Service
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
|
Sandman,
With multi-series code OnBarUpdate() is called for each separate series including the one on the chart. So your understanding is correct. The BarsInProgress can be used to check which series called the OnBarUpdate() method. If you shift the chart from 1 minute to 4-range for example, in either case BarsInProgress will be 0 when that series calls the OnBarUpdate() method.
Adam P.
NinjaTrader Customer Service |
|
|
|
|
The following user says thank you to NinjaTrader_AdamP for this post: |
|
|
|
#6 |
|
Senior Member
Join Date: Jun 2010
Posts: 222
Thanks: 14
Thanked 4 times in 4 posts
|
Thank you.
|
|
|
|
|
|
#7 |
|
Senior Member
Join Date: Jun 2010
Posts: 222
Thanks: 14
Thanked 4 times in 4 posts
|
Hi.
Here is my next question concerning multiple timeframes for an indicator. I used the strategy wizard to create certain conditions for one timeframe. One of these conditions is that the EMA13 needs to be larger than the EMA13 one bar ago and the LinReg4 needs to be larger than the LinReg4 one bar ago (rising). The code then looks like this: A. // Condition set 1 if (EMA(13)[0] + 1 > EMA(13)[1] && LinReg(4)[0] > LinReg(4)[1] Now if I want to add two more datseries (for example 3 and 5 minute) I put this into the code: a. Add(PeriodType.Minute, 3); b. Add(PeriodType.Minute, 5); From what I have seen in the code section these additional dataseries are referenced through the BarsArray in the code with [1] for the 3min and [2] for the 5min, with [0] being for the primary data series. But that meaning seems to collide with the [1] above under A. where it means 1 bar ago. My question is how does the line of code under A. above have to be written so it applies for the 3min and 5min inputs? sandman |
|
|
|
|
|
#8 |
|
NinjaTrader Customer Service
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,498
Thanks: 109
Thanked 291 times in 280 posts
|
Code:
if (EMA(BarsArray[1], 13)[0] + 1 > EMA(BarsArray[1], 13)[1]
&& LinReg(4)[0] > LinReg(4)[1]
Let me know if any questions.
Brett
NinjaTrader Customer Service |
|
|
|
|
|
#9 |
|
Senior Member
Join Date: Jun 2010
Posts: 222
Thanks: 14
Thanked 4 times in 4 posts
|
I see. So you actually write out "BarsArray[1]". Got it, I think
I will try it out now, and if I run into something, will get back to you. Meantime, thank you!sandman |
|
|
|
|
|
#10 |
|
NinjaTrader Customer Service
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,498
Thanks: 109
Thanked 291 times in 280 posts
|
My Pleasure.
Let me know if questions as you get into it. Remember, BarsArray[0] is the Primary and then you count up from there. Dont forget to use BarsInProgress to specify where your code is being run. -Brett
Brett
NinjaTrader Customer Service |
|
|
|
|
|
#11 |
|
Senior Member
Join Date: Jun 2010
Posts: 222
Thanks: 14
Thanked 4 times in 4 posts
|
I see. So you actually write out "BarsArray[1]". Got it, I think
I will try it out now, and if I run into something, will get back to you. Meantime, thank you!sandman |
|
|
|
|
|
#12 |
|
Senior Member
Join Date: Jun 2010
Posts: 222
Thanks: 14
Thanked 4 times in 4 posts
|
Brett.
Thank you! I tried it out with various indicators and time frames. Works like a charm. I think I am getting the hang of it. Now, the next thing I ran into is this. I already used in the conditions this one: && Close[0] < SMA(20)[0], meaning Closing Price of the Primary must be smaller than the SMA20 of the Primary. That worked quite fine. What I want to express now is that the Closing Price of the Primary must be smaller than the Opening Price of the secondary and tertiary. I tried this && Close[0] < Open(BarsArray[1]) && Close[0] < Open(BarsArray[2]) but it ain't working. What am I doing wrong? Please correct me. sandman |
|
|
|
|
|
#13 |
|
NinjaTrader Customer Service
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,498
Thanks: 109
Thanked 291 times in 280 posts
|
Hello,
Open/Close/High/Low uses a slightly different way to access its values. For Example: Opens[1][0]; This would return the open for the secondary data series for the current bar. It does this due to the 's' and the additoinal [1]. Accessing the Price Data in a Multi-Bars NinjaScript Much more detail at the following link in the category above: http://www.ninjatrader.com/support/h...nstruments.htm -Brett
Brett
NinjaTrader Customer Service |
|
|
|
|
|
#14 |
|
Senior Member
Join Date: Jun 2010
Posts: 222
Thanks: 14
Thanked 4 times in 4 posts
|
Got it, thank you very much. Already put it to use and it works nicely!
sandman |
|
|
|
|
|
#15 |
|
Senior Member
Join Date: Jun 2010
Posts: 222
Thanks: 14
Thanked 4 times in 4 posts
|
A moving average can also be expressed in degrees of its slope, like for example +45 or -2. Does NinjaTrader provide an indicator for this (if so which one is it?), or are these only available through 3rd Party Vendors?
sandman |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| 2 questions about Ninjascript coding.. | sev888 | Strategy Development | 4 | 06-12-2010 08:20 AM |
| 3 coding questions | grahamwillsher | Indicator Development | 4 | 09-28-2009 03:28 PM |
| Coding structure questions | dirtybrown | Indicator Development | 2 | 05-26-2009 06:35 AM |
| Coding Questions | ninjanewb | General Programming | 3 | 06-27-2008 12:16 PM |
| Basic questions | z32000 | Strategy Development | 1 | 11-24-2007 09:43 AM |