![]() |
|
|||||||
| Indicator Development Support for the development of custom indicators using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Junior Member
Join Date: Dec 2011
Posts: 15
Thanks: 0
Thanked 0 times in 0 posts
|
Hi there:
This is my first post to this forum. I am a previous TradeStation user and am now looking to get back into trading. I just want to write a very simple script that will turn the bar a different color if it is a Doji Star, which is where the open is equal to the close. I am a bit unfamilar with the programming language of this program, so could someone assist in getting me started? Thank you in advance, and Merry Christmas to everyone. Michael |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Jul 2011
Location: Denver, CO, USA
Posts: 1,651
Thanks: 111
Thanked 186 times in 181 posts
|
Hello McClellan,
Thank you for your post and welcome to the NinjaTrader Support Forum. NinjaScript is based on the modern C# programming language. For information on programming in NinjaScript please visit the following link: http://www.ninjatrader.com/support/h..._resources.htm For getting started with NinjaScript I recommend our Tutorials available in our Help Guide: http://www.ninjatrader.com/support/h...?tutorials.htm For painting a bar if the open of the current bar is equal to the close of the current bar you could use the following code: if (Close[0] == Open[0]) { BarColor = Color.Blue; } Please let me know if I may be of further assistance.
Patrick H.
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Dec 2011
Posts: 15
Thanks: 0
Thanked 0 times in 0 posts
|
I used this code:
if (Close[0] == Open[0]) {ISDojiStar = true;} else {ISDojiStar = false;} if (ISDojiStar == true); {BarColor = Color.Blue;} And unforunately it is turning ALL bars blue. Any idea why? |
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
Hi McClellan,
You terminated the second if statement with a semi colon ; which means the next statement is not connected to it. The bools aren't needed here, and you could use the snippet from Patrick's last post as a simpler way to do this. if (Close[0] == Open[0]) {ISDojiStar = true;} else {ISDojiStar = false;} if (ISDojiStar == true); {BarColor = Color.Blue;}
Ryan M
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Junior Member
Join Date: Dec 2011
Posts: 15
Thanks: 0
Thanked 0 times in 0 posts
|
Thank you.
You are correct, but I felt I needed the booleans if am going to apply this to a system. |
|
|
|
|
|
#6 |
|
Junior Member
Join Date: Dec 2011
Posts: 15
Thanks: 0
Thanked 0 times in 0 posts
|
Hi there. I am having trouble again.
I am trying to write a system that goes something like this: If DojiStar == true AND stochastics > 80 then enter long If DojiStar == true AND stochastics < 20 then enter short Can you assist? I tried to put this into the builder and it is not working at all. No trades exist. Here is some code I ATTEMPTED: // Condition set 1 if (DojiStar() = true && Stochastics(7, 14, 3).D[0] >= 80) { EnterLong(DefaultQuantity, ""); } // Condition set 2 if (DojiStar() = true && Stochastics(7, 14, 3).D[0] <= 20) { EnterShort(DefaultQuantity, ""); |
|
|
|
|
|
#7 |
|
NinjaTrader Customer Service
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
|
Code:
// Condition set 1
if (DojiStar() = true
&& Stochastics(7, 14, 3).D[0] >= 80)
{
EnterLong(DefaultQuantity, "");
}
// Condition set 2
if (DojiStar() = true
&& Stochastics(7, 14, 3).D[0] <= 20)
{
EnterShort(DefaultQuantity, "");
Please ensure you have DojiStart==true, not DojiStar=true; Also, you could simply just put DojiStar() there. When its true the statement will be true. Does this DojiStar() function return a true when a doji star is present? Have you tested its working correctly? Please let me know if I may assist further.
Adam P.
NinjaTrader Customer Service |
|
|
|
|
|
#8 |
|
Junior Member
Join Date: Dec 2011
Posts: 15
Thanks: 0
Thanked 0 times in 0 posts
|
Here is some code for the DojiStar indicator:
protected override void OnBarUpdate() { // Use this method for calculating your indicator values. Assign a value to each // plot below by replacing 'Close[0]' with your own formula. ISDojiStar = false; if (Close[0] == Open[0] || (Close[0] >= Open[0] && Close[0] <= Open[0] + TickSize) || (Close[0] <= Open[0] && Close[0] >= Open[0] - TickSize))///(Close[0] == Open[0]) {ISDojiStar = true;} else {ISDojiStar = false;} if (ISDojiStar == true) {BarColor = Color.Blue;} |
|
|
|
|
|
#9 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
The default value of an indicator would always be a number(a plot), and not a bool true/false expression like it looks like you're trying to expose from it.
If you want to expose the value of a bool flag from one script to another, there needs to be additional code and structure added. The technique for this is shown in this sample: http://www.ninjatrader.com/support/f...ead.php?t=4991 I don't recommend that you follow this sample yet. As you're just getting started, it's best to keep things simple and get things working within only one script. Once you get more familiar with the basics, then start working on the more advance concepts like exposing non plot values.
Ryan M
NinjaTrader Customer Service |
|
|
|
|
|
#10 |
|
Junior Member
Join Date: Dec 2011
Posts: 15
Thanks: 0
Thanked 0 times in 0 posts
|
It would be really nice if this forum was searchable. I did not see a search box anywhere to search the threads by subject.
|
|
|
|
|
|
#11 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
There is search available. You can use the Search button on the forum toolbar. It is hard to beat google search though.
http://www.google.com/search?q=Searc...injatrader.com How to search a site with google.
Ryan M
NinjaTrader Customer Service
Last edited by NinjaTrader_RyanM; 12-29-2011 at 12:03 PM.
|
|
|
|
|
|
#12 |
|
Junior Member
Join Date: Dec 2011
Posts: 15
Thanks: 0
Thanked 0 times in 0 posts
|
Great. Thank you.
So I am having trouble with the following code in a SYSTEM: protectedoverridevoid Initialize() { Add(CandleStickPatternAll()); SetProfitTarget("", CalculationMode.Percent, 500); SetStopLoss("", CalculationMode.Percent, 100, false); SetTrailStop("", CalculationMode.Percent, 0, false); CalculateOnBarClose = true; } ///<summary> /// Called on each bar update event (incoming tick) ///</summary> protectedoverridevoid OnBarUpdate() { if (CandleStickPatternAll().BullishEngulfingFound[0]) EnterLong(); if (CandleStickPatternAll().BearishEngulfingFound[0]) EnterShort(); Print(CandleStickPatternAll().ExposedVariable); } #region Properties #endregion } } I have compile errors at the red lines. It says "The name CandlestickPatternAll is not valid in this context." Any idea what could be going on? |
|
|
|
|
|
#13 |
|
Junior Member
Join Date: Dec 2011
Posts: 15
Thanks: 0
Thanked 0 times in 0 posts
|
Hmm. I saved my work, then exited the NinjaScript. Then restarted it and now I only have 4 errors. They all say "No overload method for 'CandleStickPatternAll' takes '0' arguments."
Any clue? |
|
|
|
|
|
#14 | |
|
Senior Member
|
Quote:
If you really just want to use the defaults, you can always create a named instance of the indicator using the new keyword and then call/query the named instance. Creating an instance with the new keyword, you should not have to specify any parameters. This has the considerable side benefit of bypassing all the NT magic code that is used to iterate through all running instances to determine the correct one to call on each event. It becomes especially useful if you are processing every tick with COBC = false. |
|
|
|
|
|
|
#15 |
|
Junior Member
Join Date: Dec 2011
Posts: 15
Thanks: 0
Thanked 0 times in 0 posts
|
That makes sense, but there are no inputs. The code for the indicator is attached.
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| stochastic paintbar | pimind | Indicator Development | 3 | 04-07-2011 09:43 AM |
| Outside bar paintbar | barenakedtrader | Indicator Development | 2 | 10-29-2010 08:33 AM |
| Doji bars with NT | Risk Manager | Charting | 11 | 02-25-2010 12:22 PM |
| contruction of his own shooting star | Thomas79 | General Programming | 23 | 04-30-2009 07:20 AM |
| PaintBar Question | beeker | Indicator Development | 2 | 06-10-2008 04:49 PM |