NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Indicator Development

Indicator Development Support for the development of custom indicators using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 12-26-2011, 12:01 PM   #1
McClellan
Junior Member
 
Join Date: Dec 2011
Posts: 15
Thanks: 0
Thanked 0 times in 0 posts
Default Paintbar - Doji Star

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
McClellan is offline  
Reply With Quote
Old 12-27-2011, 06:57 AM   #2
NinjaTrader_PatrickH
NinjaTrader Customer Service
 
NinjaTrader_PatrickH's Avatar
 
Join Date: Jul 2011
Location: Denver, CO, USA
Posts: 1,651
Thanks: 111
Thanked 186 times in 181 posts
Default

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.
NinjaTrader_PatrickH is online now  
Reply With Quote
Old 12-27-2011, 03:54 PM   #3
McClellan
Junior Member
 
Join Date: Dec 2011
Posts: 15
Thanks: 0
Thanked 0 times in 0 posts
Default

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?
McClellan is offline  
Reply With Quote
Old 12-27-2011, 04:53 PM   #4
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

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;}
NinjaTrader_RyanM is offline  
Reply With Quote
Old 12-27-2011, 05:44 PM   #5
McClellan
Junior Member
 
Join Date: Dec 2011
Posts: 15
Thanks: 0
Thanked 0 times in 0 posts
Default

Thank you.

You are correct, but I felt I needed the booleans if am going to apply this to a system.
McClellan is offline  
Reply With Quote
Old 12-28-2011, 02:37 PM   #6
McClellan
Junior Member
 
Join Date: Dec 2011
Posts: 15
Thanks: 0
Thanked 0 times in 0 posts
Default

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, "");
McClellan is offline  
Reply With Quote
Old 12-28-2011, 03:09 PM   #7
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

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.
NinjaTrader_AdamP is offline  
Reply With Quote
Old 12-28-2011, 03:57 PM   #8
McClellan
Junior Member
 
Join Date: Dec 2011
Posts: 15
Thanks: 0
Thanked 0 times in 0 posts
Default

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;}
McClellan is offline  
Reply With Quote
Old 12-28-2011, 04:18 PM   #9
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

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.
NinjaTrader_RyanM is offline  
Reply With Quote
Old 12-29-2011, 11:51 AM   #10
McClellan
Junior Member
 
Join Date: Dec 2011
Posts: 15
Thanks: 0
Thanked 0 times in 0 posts
Default

It would be really nice if this forum was searchable. I did not see a search box anywhere to search the threads by subject.
McClellan is offline  
Reply With Quote
Old 12-29-2011, 11:57 AM   #11
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

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.
Attached Images
File Type: png searchForum.png (53.2 KB, 6 views)
Last edited by NinjaTrader_RyanM; 12-29-2011 at 12:03 PM.
NinjaTrader_RyanM is offline  
Reply With Quote
Old 12-30-2011, 05:22 PM   #12
McClellan
Junior Member
 
Join Date: Dec 2011
Posts: 15
Thanks: 0
Thanked 0 times in 0 posts
Default

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?
McClellan is offline  
Reply With Quote
Old 12-30-2011, 05:25 PM   #13
McClellan
Junior Member
 
Join Date: Dec 2011
Posts: 15
Thanks: 0
Thanked 0 times in 0 posts
Default

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?
McClellan is offline  
Reply With Quote
Old 12-30-2011, 05:39 PM   #14
koganam
Senior Member
 
Join Date: Feb 2008
Location: Durham, North Carolina, USA
Posts: 3,199
Thanks: 24
Thanked 1,225 times in 996 posts
Send a message via Skype™ to koganam
Default

Quote:
Originally Posted by McClellan View Post
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?
You must specify all the input parameters when you call an indicator. Intellisense can help, but you may have to look at the code in the indicator. You must specify everything the is in a GridCategory or a Parameters Category.

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.
koganam is offline  
Reply With Quote
Old 12-30-2011, 05:59 PM   #15
McClellan
Junior Member
 
Join Date: Dec 2011
Posts: 15
Thanks: 0
Thanked 0 times in 0 posts
Default

That makes sense, but there are no inputs. The code for the indicator is attached.



Attached Files
File Type: doc CandleStickPatternAll.doc (31.5 KB, 9 views)
McClellan 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
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


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