![]() |
|
|||||||
| Indicator Development Support for the development of custom indicators using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Join Date: Mar 2007
Location: , ,
Posts: 1
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#2 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
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
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Member
Join Date: Oct 2006
Location: , ,
Posts: 55
Thanks: 0
Thanked 0 times in 0 posts
|
I am also interested in this indicator.
Is there a function that allows you to store values from a given time/date? thanks |
|
|
|
|
|
#4 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
No there is not.
Ray
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Member
Join Date: Oct 2006
Location: , ,
Posts: 55
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#6 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
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
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#7 |
|
Member
Join Date: Oct 2006
Location: , ,
Posts: 55
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#8 |
|
Member
Join Date: Oct 2006
Location: , ,
Posts: 55
Thanks: 0
Thanked 0 times in 0 posts
|
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 } } |
|
|
|
|
|
#9 |
|
Member
Join Date: Oct 2006
Location: , ,
Posts: 55
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#10 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
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
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#11 |
|
Member
Join Date: Oct 2006
Location: , ,
Posts: 55
Thanks: 0
Thanked 0 times in 0 posts
|
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] ; } } } |
|
|
|
|
|
#12 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
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);
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#13 |
|
Member
Join Date: Oct 2006
Location: , ,
Posts: 55
Thanks: 0
Thanked 0 times in 0 posts
|
I think I am very close but I got 1 error message.
Cannot apply indexing with [] to an expression of type 'double' |
|
|
|
|
|
#14 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
PHigh is a variable not an array that can be indexed.
Should be PeriodHigh.Set(PHigh);
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#15 |
|
Member
Join Date: Oct 2006
Location: , ,
Posts: 55
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|