![]() |
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#46 |
|
NinjaTrader Customer Service
Join Date: Jul 2011
Location: Denver, CO, USA
Posts: 1,647
Thanks: 111
Thanked 185 times in 180 posts
|
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.
Patrick H.
NinjaTrader Customer Service |
|
|
|
|
|
#47 |
|
Senior Member
Join Date: Jun 2010
Posts: 222
Thanks: 14
Thanked 4 times in 4 posts
|
Thanks for checking Patrick.
I do have this in the code already: protected override void Initialize() { CalculateOnBarClose = false; } Anything else I could check? sandman |
|
|
|
|
|
#48 |
|
NinjaTrader Customer Service
Join Date: Jul 2011
Location: Denver, CO, USA
Posts: 1,647
Thanks: 111
Thanked 185 times in 180 posts
|
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.
Patrick H.
NinjaTrader Customer Service |
|
|
|
|
|
#49 |
|
Senior Member
Join Date: Jun 2010
Posts: 222
Thanks: 14
Thanked 4 times in 4 posts
|
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 |
|
|
|
|
|
#50 |
|
NinjaTrader Customer Service
Join Date: Jul 2011
Location: Denver, CO, USA
Posts: 1,647
Thanks: 111
Thanked 185 times in 180 posts
|
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.
Patrick H.
NinjaTrader Customer Service |
|
|
|
|
|
#51 |
|
Senior Member
Join Date: Jun 2010
Posts: 222
Thanks: 14
Thanked 4 times in 4 posts
|
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 |
|
|
|
|
|
#52 | |
|
Senior Member
Join Date: Jun 2010
Posts: 222
Thanks: 14
Thanked 4 times in 4 posts
|
Quote:
sandman |
|
|
|
|
|
|
#53 |
|
NinjaTrader Customer Service
Join Date: Jul 2011
Location: Denver, CO, USA
Posts: 1,647
Thanks: 111
Thanked 185 times in 180 posts
|
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.
Patrick H.
NinjaTrader Customer Service |
|
|
|
|
|
#54 |
|
Senior Member
Join Date: Jun 2010
Posts: 222
Thanks: 14
Thanked 4 times in 4 posts
|
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 |
|
|
|
|
|
#55 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
|
sandman, you would need to pass a series to Rising(), not a double value so please try -
Rising(LinReg(BarsArray[1],4)))
Bertrand
NinjaTrader Customer Service |
|
|
|
|
The following user says thank you to NinjaTrader_Bertrand for this post: |
|
|
|
#56 |
|
Senior Member
Join Date: Jun 2010
Posts: 222
Thanks: 14
Thanked 4 times in 4 posts
|
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 |
|
|
|
|
|
#57 |
|
Senior Member
Join Date: Jun 2010
Posts: 222
Thanks: 14
Thanked 4 times in 4 posts
|
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 |
|
|
|
|
|
#58 |
|
Senior Member
|
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 |
|
|
|
|
The following user says thank you to pmaglio for this post: |
|
|
|
#59 |
|
Senior Member
Join Date: Jun 2010
Posts: 222
Thanks: 14
Thanked 4 times in 4 posts
|
Got it Pablo. Thanks for your input. (As always, your instructions are easy to understand.)
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 |