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 01-07-2013, 06:01 AM   #46
NinjaTrader_PatrickH
NinjaTrader Customer Service
 
NinjaTrader_PatrickH's Avatar
 
Join Date: Jul 2011
Location: Denver, CO, USA
Posts: 1,647
Thanks: 111
Thanked 185 times in 180 posts
Default

Hello sandman,

Thank you for your update on this matter.

Is CalculateOnBarClose set to True or False? If set to True, please set to False and test again.

For information on CalculateOnBarClose please visit the following link: http://www.ninjatrader.com/support/h...onbarclose.htm

Please let me know if you have any questions or if CalculateOnBarClose is already set to False.
NinjaTrader_PatrickH is offline  
Reply With Quote
Old 01-07-2013, 07:26 AM   #47
sandman
Senior Member
 
Join Date: Jun 2010
Posts: 222
Thanks: 14
Thanked 4 times in 4 posts
Default

Thanks for checking Patrick.

I do have this in the code already:

protected override void Initialize()
{
CalculateOnBarClose = false;
}

Anything else I could check?

sandman
sandman is offline  
Reply With Quote
Old 01-07-2013, 08:20 AM   #48
NinjaTrader_PatrickH
NinjaTrader Customer Service
 
NinjaTrader_PatrickH's Avatar
 
Join Date: Jul 2011
Location: Denver, CO, USA
Posts: 1,647
Thanks: 111
Thanked 185 times in 180 posts
Default

Hello sandman,

Thank you for your response.

Try using Print() statements for each condition that would change the color. Then open up your Output Window (Tools > Output Window) and check to see if you get prints when the conditions should return true.

For information on Print() please visit the following link: http://www.ninjatrader.com/support/h.../nt7/print.htm
For information on debugging your NinjaScript code please visit the following link: http://www.ninjatrader.com/support/f...ead.php?t=3418

Please let me know if you have any questions.
NinjaTrader_PatrickH is offline  
Reply With Quote
Old 01-08-2013, 04:27 AM   #49
sandman
Senior Member
 
Join Date: Jun 2010
Posts: 222
Thanks: 14
Thanked 4 times in 4 posts
Default

Hi Patrick, thank you. I don't know yet how to use that print command. But

I worked out a colored LinReg with the color changing depending on whether it is rising or falling. In the code for that is something "if rising" then color it green "else falling" then color it red. In other words "if" and "else".

For the colored candles which I am trying to code now I only have an "if", i.e. if all my conditions for rising are met then color the candle green. But I have no "else" statement.

// Condition set 1
if (Close[0] > Opens[0][0]
&& LinReg(BarsArray[0],4)[0] > LinReg(BarsArray[0],4)[1]
&& LinReg(BarsArray[0],9)[0] > LinReg(BarsArray[0],9)[1]
&& LinReg(BarsArray[1],4)[0] > LinReg(BarsArray[1],4)[1]
&& LinReg(BarsArray[1],9)[0] > LinReg(BarsArray[1],9)[1] )
{
BarColor = upCandle_Color;
}

Could adding this do the trick like this:

else
{
BarColor = Color.Empty;
}

And then do the same for the falling condition:

// Condition set 2
if (Close[0] < Opens[0][0]
&& LinReg(BarsArray[0],4)[0] < LinReg(BarsArray[0],4)[1]
&& LinReg(BarsArray[0],9)[0] < LinReg(BarsArray[0],9)[1]
&& LinReg(BarsArray[1],4)[0] < LinReg(BarsArray[1],4)[1]
&& LinReg(BarsArray[1],9)[0] < LinReg(BarsArray[1],9)[1])
{
BarColor = downCandle_Color;
}
else
{
BarColor = Color.Empty;
}

or am I overlooking something?

sandman
sandman is offline  
Reply With Quote
Old 01-08-2013, 08:14 AM   #50
NinjaTrader_PatrickH
NinjaTrader Customer Service
 
NinjaTrader_PatrickH's Avatar
 
Join Date: Jul 2011
Location: Denver, CO, USA
Posts: 1,647
Thanks: 111
Thanked 185 times in 180 posts
Default

Hello sandman,

Thank you for your update on this matter.

I would test each possibility to understand how the if and else conditions work with one another. For information on if and else please visit the following link: http://msdn.microsoft.com/en-us/libr...(v=vs.71).aspx

From what you have detailed the else statement appears to be the missing element here. Please try this on your end and advise if this corrects the matter.
NinjaTrader_PatrickH is offline  
Reply With Quote
Old 01-08-2013, 12:44 PM   #51
sandman
Senior Member
 
Join Date: Jun 2010
Posts: 222
Thanks: 14
Thanked 4 times in 4 posts
Default

Thanks Patrick.

I tried out using an "else" statement but that did not work, so I added an
"else if" statement and included in that just one of the conditions. Like this:

if (Close[0] > Opens[0][0]

&& LinReg(BarsArray[0],4)[0] > LinReg(BarsArray[0],4)[1]
&& LinReg(BarsArray[0],9)[0] > LinReg(BarsArray[0],9)[1]
&& LinReg(BarsArray[1],4)[0] > LinReg(BarsArray[1],4)[1]
&& LinReg(BarsArray[1],9)[0] > LinReg(BarsArray[1],9)[1] )
{
BarColor = upCandle_Color;
}

else if (Close[0] > Opens[0][0])
{
BarColor = Color.Empty;
}

That seems to work out fine because when the conditions are met the bar is colored and it correctly "loses" the coloration when the conditions change while the bar is in progress. That is what I had wanted.

Sofar so good. See the attached image. The bars which I encircled were actually colored dark red when they were being created. But when I re-applied the same indicator they disappeared. What makes them disappear in historic mode?

sandman
Attached Images
File Type: jpg Image1.jpg (54.5 KB, 3 views)
sandman is offline  
Reply With Quote
Old 01-08-2013, 01:14 PM   #52
sandman
Senior Member
 
Join Date: Jun 2010
Posts: 222
Thanks: 14
Thanked 4 times in 4 posts
Default

Quote:
Originally Posted by sandman View Post
Sofar so good. See the attached image. The bars which I encircled were actually colored dark red when they were being created. But when I re-applied the same indicator they disappeared. What makes them disappear in historic mode?
sandman
Additional image 2 attached. Here I applied the same indicator but not with colored bars but a colored background stripe. While the indicator draws the background color and it stays, the colored bars "disappeared". Is there an explanation for that?

sandman
Attached Images
File Type: jpg Image2.jpg (58.9 KB, 6 views)
sandman is offline  
Reply With Quote
Old 01-08-2013, 01:22 PM   #53
NinjaTrader_PatrickH
NinjaTrader Customer Service
 
NinjaTrader_PatrickH's Avatar
 
Join Date: Jul 2011
Location: Denver, CO, USA
Posts: 1,647
Thanks: 111
Thanked 185 times in 180 posts
Default

Hello sandman,

Thank you for your response.

May I take a look at this code on my end? You can send a 'toy' version if you wish as long as it has the code used for the bars.

If you prefer you can send your NinjaScript file to support[at]ninjatrader[dot]com with 'ATTN: Patrick' in the subject line and a reference to this thread in the body of the e-mail: http://www.ninjatrader.com/support/f...ad.php?t=51627

I look forward to your response.
NinjaTrader_PatrickH is offline  
Reply With Quote
Old 01-19-2013, 05:07 PM   #54
sandman
Senior Member
 
Join Date: Jun 2010
Posts: 222
Thanks: 14
Thanked 4 times in 4 posts
Default

When I use this line of code for a secondary bars object it works okay but is not perfect yet for my taste.

LinReg(BarsArray[1],4)[0] > LinReg(BarsArray[1],4)[1]

Now I want to see if when I use "Rising" I could get different and better results. I tried this but it is not being accepted ("cannot convert from double to NT.Data.IDataSeries-whatever that means"):

Rising(LinReg(BarsArray[1],4)[0]))

Any tip of what I have to correct here?

sandman
sandman is offline  
Reply With Quote
Old 01-19-2013, 05:11 PM   #55
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
Default

sandman, you would need to pass a series to Rising(), not a double value so please try -

Rising(LinReg(BarsArray[1],4)))
NinjaTrader_Bertrand is offline  
Reply With Quote
The following user says thank you to NinjaTrader_Bertrand for this post:
Old 01-22-2013, 01:19 PM   #56
sandman
Senior Member
 
Join Date: Jun 2010
Posts: 222
Thanks: 14
Thanked 4 times in 4 posts
Default

Bertrand. That worked fine and now it does exactly what it is supposed to when it is supposed to do it. Thanks, also for your patience

sandman
sandman is offline  
Reply With Quote
Old 01-31-2013, 09:25 PM   #57
sandman
Senior Member
 
Join Date: Jun 2010
Posts: 222
Thanks: 14
Thanked 4 times in 4 posts
Default

I have this in my code to color a 1Minute candle when that candle starts below or on the SMA and closes above it.

Close[0] > Opens[0][0]
&& Close[0] > SMA(BarsArray[0],20)[0]
&& Low[0] <= SMA(BarsArray[0],20)[0]

However, I would like to be more generous with where the low is in relation to that SMA and tell it that I am also okay even if the low is within 3 ticks above that SMA (of course maintaining that the Close has to be larger than the Open).

To do that I believe I can use the offset function.

Questions:
1. Do I have to express the offset on the Low side or on the SMA side, or does it even matter e.g.:
(Low[0]) 3 * TickSize
or is it:
(SMA(BarsArray[0],20)[0]) 3 * TickSize

2. If I would use not ticks as offset but percentage
(SMA(20)[0]) * (1 + 23))

- what is the 23 a percentage of?

sandman
sandman is offline  
Reply With Quote
Old 01-31-2013, 10:11 PM   #58
pmaglio
Senior Member
 
Join Date: Oct 2007
Location: Argentina
Posts: 175
Thanks: 2
Thanked 19 times in 14 posts
Send a message via Yahoo to pmaglio Send a message via Skype™ to pmaglio
Default

Sandman,

1) it doesnt matters ; (Low[0]) +/- 3 * TickSize will work fine
....or (SMA(BarsArray[0],20)[0]) -/+ 3 * TickSize
2) using percentage would be ;
(SMA(20)[0]) * (1 + 23/100)) and it would be a 23% of the SMA(20) Price Value

Regards,
Pablo Maglio
The Indicator Store
pmaglio is offline  
Reply With Quote
The following user says thank you to pmaglio for this post:
Old 02-06-2013, 04:09 AM   #59
sandman
Senior Member
 
Join Date: Jun 2010
Posts: 222
Thanks: 14
Thanked 4 times in 4 posts
Default

Got it Pablo. Thanks for your input. (As always, your instructions are easy to understand.)

sandman
sandman 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
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


All times are GMT -6. The time now is 02:00 PM.