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 03-21-2007, 04:56 AM   #1
pijamatrader
 
Join Date: Mar 2007
Location: , ,
Posts: 1
Thanks: 0
Thanked 0 times in 0 posts
Post imported post

Hi, does anyone know where I can find, or how I can make an indicator that plots a line showing the 1st hour's High/Low of the session?

Thanks,

PijamaTrader


pijamatrader is offline  
Reply With Quote
Old 03-21-2007, 05:06 AM   #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
Post imported post

A system indicator does not exist but you can program one in NinjaScript. If you are new to programming, this will require a learning curve. If you have programming background, please see the Help Guide section for NinjaScript. There are some indicator development tutorials to get you started. You can also look at the code for the PriorDayOHLC to get an idea of how to go about programming the logic for such an indicator.

Ray
NinjaTrader_Ray is offline  
Reply With Quote
Old 04-04-2007, 01:30 AM   #3
qitrader
Member
 
Join Date: Oct 2006
Location: , ,
Posts: 55
Thanks: 0
Thanked 0 times in 0 posts
Post imported post

I am also interested in this indicator.

Is there a function that allows you to store values from a given time/date?

thanks
qitrader is offline  
Reply With Quote
Old 04-04-2007, 01:43 AM   #4
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
Post imported post

No there is not.

Ray
NinjaTrader_Ray is offline  
Reply With Quote
Old 04-04-2007, 01:43 AM   #5
qitrader
Member
 
Join Date: Oct 2006
Location: , ,
Posts: 55
Thanks: 0
Thanked 0 times in 0 posts
Post imported post

This is the logic I have but would like some help with the translation to get me started.

THanks

Qi

// New day settings
if ( DateTime[0]<>Date[1] )
DateInFromTo= (Date>=iFromYYYMMDD && Date<=iToYYYMMDD);
bool FirstTrade=true;
double RangeH=H;
double RangeL=L; // first bars High Low are Ranges h&l
TimeH=Time;
TimeL=Time;


// Range settings
If L<LowD(0)[1] then TimeL=Time; {if new H or L, remember the time of H or L}
If H>HighD(0)[1] then TimeH=Time;

If Time=OpenRangeTime then begin // if openning range is finished
RangeH=HighD(0); RangeL=LowD(0); RangeHtime=TimeH; RangeLtime=TimeL; end; // remember Range parameters
qitrader is offline  
Reply With Quote
Old 04-04-2007, 01:46 AM   #6
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
Post imported post

I suggest reviewing some of our system indicator source files. Check out the @PreviousDayOHL to get an idea of how this can be done.

Ray
NinjaTrader_Ray is offline  
Reply With Quote
Old 05-22-2007, 08:48 PM   #7
qitrader
Member
 
Join Date: Oct 2006
Location: , ,
Posts: 55
Thanks: 0
Thanked 0 times in 0 posts
Default

In NT, how do I recall the High or Low of a given time?

Can I declare a variable representing 930am EST and another as 1000a EST as below?

e.g.

private double start_time = 0930;
private double end_time = 1000;

thanks
qitrader is offline  
Reply With Quote
Old 05-22-2007, 09:28 PM   #8
qitrader
Member
 
Join Date: Oct 2006
Location: , ,
Posts: 55
Thanks: 0
Thanked 0 times in 0 posts
Default

There seems to be a few requests to the OR lines. So I will start providing my logic. Let me know if it needs to be corrected.

Thanks

#region Using declarations
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
#endregion

// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
[Description("Opening Range Breakout")]
[Gui.Design.DisplayName("OR Breakout")]
public class OpeningRange : Indicator
{
#region Variables

private DateTime currentDate = Cbi.Globals.MinDate;
private int start_time = 0930;
private int start_time = 1000;
private int PeriodHigh = 0;
private int PeriodLow = 9999;

#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, "PeriodHigh"));
Add(new Plot(Color.Orange, PlotStyle.Line, "PeriodLow"));

AutoScale = false;
CalculateOnBarClose = false; // Call 'OnBarUpdate' on every tick
Overlay = true; // Plots the indicator on top of price
}

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (currentDate != Time[0].Date)//if new day
{
PeriodHigh = 0; // re-initialize PeriodHigh,PeriodLow for the new day
PeriodLow = 9999;
}
if (StartTime <= Time[0] || Time[0] <= EndTime) {
if (High[0] > PeriodHigh) { PeriodHigh = High ; }
if (Low[0] < PeriodLow) { PeriodLow = Low ; }
PeriodLow = Low ;
}
}
#region Properties
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries Plot0
{
get { return Values[0]; }
}

#endregion
}
}
qitrader is offline  
Reply With Quote
Old 05-23-2007, 06:16 AM   #9
qitrader
Member
 
Join Date: Oct 2006
Location: , ,
Posts: 55
Thanks: 0
Thanked 0 times in 0 posts
Default

I have uploaded part of my code but still getting error messages.

The name 'StartTime' does not exist in the current context
" " 'EndTime' " " " " " " "

Any help in the code is appreciated

thanks
Attached Files
File Type: cs OpeningRange.cs (5.6 KB, 33 views)
qitrader is offline  
Reply With Quote
Old 05-23-2007, 07:01 AM   #10
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

StartTime --> You have not declared this anywhere, that's why it says it does not exist. Even if you rectify this, your logic will not work. Please review the following Help Guide section.

http://www.ninjatrader-support.com/H...V6/ToTime.html
NinjaTrader_Ray is offline  
Reply With Quote
Old 05-23-2007, 07:24 AM   #11
qitrader
Member
 
Join Date: Oct 2006
Location: , ,
Posts: 55
Thanks: 0
Thanked 0 times in 0 posts
Default

Hi

I changed the code to the following but it still doesn't plot the lines. Any help is appreciated. THe code compiled correctly.

protected override void Initialize()
{
Add(new Plot(Color.Orange, PlotStyle.Line, "PeriodHigh"));
Add(new Plot(Color.Orange, PlotStyle.Line, "PeriodLow"));

AutoScale = false;
CalculateOnBarClose = false; // Call 'OnBarUpdate' on every tick
Overlay = true; // Plots the indicator on top of price
}

protected override void OnBarUpdate()
{
if (currentDate != Time[0].Date)//if new day
{
PeriodHigh = 0; // re-initialize PeriodHigh,PeriodLow for the new day
PeriodLow = 9999;
}
if (ToTime(Time[0]) > start_time && ToTime(Time[0]) < end_time) {
if (High[0] > PeriodHigh) { PeriodHigh = High[0] ; }
if (Low[0] < PeriodLow) { PeriodLow = Low[0] ; }

}
}
Attached Files
File Type: cs OpeningRange.cs (5.7 KB, 8 views)
qitrader is offline  
Reply With Quote
Old 05-23-2007, 07:56 AM   #12
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

Hi,

Its not plotting since you are not setting any plot values. I would scrap this indicator and start through the wizard and add plots named PeriodHigh and PeriodLow and then have the wizard generate all of the code required.

Then add back your logic and when you have to set the value of your plots, you would do something like:

PeriodHigh.Set(plotValueHere);
NinjaTrader_Ray is offline  
Reply With Quote
Old 05-23-2007, 09:35 AM   #13
qitrader
Member
 
Join Date: Oct 2006
Location: , ,
Posts: 55
Thanks: 0
Thanked 0 times in 0 posts
Default

I think I am very close but I got 1 error message.

Cannot apply indexing with [] to an expression of type 'double'
Attached Files
File Type: cs OpenRange.cs (7.0 KB, 20 views)
qitrader is offline  
Reply With Quote
Old 05-23-2007, 10:08 AM   #14
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

PHigh is a variable not an array that can be indexed.

Should be PeriodHigh.Set(PHigh);
NinjaTrader_Ray is offline  
Reply With Quote
Old 05-24-2007, 06:52 AM   #15
qitrader
Member
 
Join Date: Oct 2006
Location: , ,
Posts: 55
Thanks: 0
Thanked 0 times in 0 posts
Default

Hi

The code works now but my logic is flawed. How do I use the following properties?

Bars.GetSessionBar(int sessionsAgo).High

Bars.GetSessionBar(int sessionsAgo).Low

Trying to gather the highest high and lowest low of session from start period to end period.

Thanks
qitrader 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


All times are GMT -6. The time now is 06:12 AM.