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 07-13-2007, 02:35 PM   #1
grd974
Senior Member
 
Join Date: Apr 2007
Location: , ,
Posts: 124
Thanks: 0
Thanked 0 times in 0 posts
Default Fibonacci Retracements

Could any of the seasoned NT programers tell me why the code listed below does not draw any object on my chart ?

namespace NinjaTrader.Indicator
{
/// <summary>
/// Fib Retracements
/// </summary>
[Description("Fib Retracements")]
[Gui.Design.DisplayName("Fib2")]
public class Fib2 : Indicator
{
#region Variables
// Wizard generated variables
private int myInput0 = 1; // Default setting for MyInput0
// User defined variables (add any user defined variables below)
#endregion

/// <summary>
/// This method is used to configure the indicator and is called once before any bar data is loaded.
/// </summary>
protected override void Initialize()
{
Add(new Plot(Color.Orange, PlotStyle.Line, "Plot0"));
CalculateOnBarClose = true;
Overlay = false;
PriceTypeSupported = false;
}

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (Close[0] > Close[1])
DrawFibonacciRetracements("Lines" + CurrentBar, 1, High[0], 0, Low[0]);
else if (Close[0] <= Close[1])
DrawFibonacciRetracements("Lines" + CurrentBar, 1, Low[0], 0, High[0]);
}

Thanks.
grd974 is offline  
Reply With Quote
Old 07-13-2007, 03:00 PM   #2
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

Any error messages in your log tab?

Do you want a lot of fib objects on your chart? The way you wrote it is what you will get, or do you only every want one to be visible? If the latter, use the same "tag" value insread of making it unique by adding the CurrentBar to the tag name.
NinjaTrader_Ray is offline  
Reply With Quote
Old 07-13-2007, 03:04 PM   #3
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

Actually, I see the issue which will be displayed in the Log Tab.

Add:

if (CurrentBar < 1)
return;

Your are accessing Close[1] on the 1st bar of the chart where 1 bar ago does not yet exist.
NinjaTrader_Ray is offline  
Reply With Quote
Old 07-13-2007, 06:16 PM   #4
grd974
Senior Member
 
Join Date: Apr 2007
Location: , ,
Posts: 124
Thanks: 0
Thanked 0 times in 0 posts
Default

Now it works great, thanks.
grd974 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
Fibonacci Trader Doc Automated Trading 3 02-21-2007 01:47 AM
Suggestions for the Fibonacci Tool Antraman Suggestions And Feedback 1 04-26-2006 02:06 AM
Suggestions for the Fibonacci Tool Antraman Charting 1 12-31-1969 06:00 PM


All times are GMT -6. The time now is 04:00 AM.