![]() |
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Junior Member
Join Date: Apr 2009
Posts: 19
Thanks: 0
Thanked 0 times in 0 posts
|
Hi Guys,
I just started learning NT script.I used the existing NT CurrentDayOHL code and tried to apply DrawRegion to currentHigh, currentLow,and created the 50% Mid points. I got it worked but failed to delete those Plot lines.(I tried to command out but didn't work) Could anyone please give me some advice? Thanks in advance! protected override void OnBarUpdate() { if (currentOpen == double.MinValue) currentOpen = Open[0]; if (Bars.SessionBreak) { currentOpen = Open[0]; currentHigh = High[0]; currentLow = Low[0]; } currentHigh = Math.Max(currentHigh, High[0]); currentLow = Math.Min(currentLow, Low[0]); if (ShowOpen) { if (!PlotCurrentValue || !Bars.SessionBreak) CurrentOpen.Set(currentOpen); else for (int idx = 0; idx < CurrentOpen.Count; idx++) CurrentOpen.Set(idx, currentOpen); } if (ShowHigh) { if (!PlotCurrentValue || currentHigh != High[0]) CurrentHigh.Set(currentHigh); else for (int idx = 0; idx < CurrentHigh.Count; idx++) CurrentHigh.Set(idx, currentHigh); } if (ShowLow) { if (!PlotCurrentValue || currentLow != Low[0]) CurrentLow.Set(currentLow); else for (int idx = 0; idx < CurrentLow.Count; idx++) CurrentLow.Set(idx, currentLow); } mid.Set(Instrument.MasterInstrument.Round2TickSize ((currentHigh+currentLow)/2)); ch1.Set(currentHigh); cl1.Set(currentLow); mid1.Set (mid[0]+TickSize*1); mid2.Set (mid[0]-TickSize*1); CH1.Set (ch1[0]-TickSize*2); CL1.Set (cl1[0]+TickSize*2); DrawRegion("Reg1", CurrentBar, 0, mid1, mid2, Color.Transparent, Color.DarkRed,10); DrawRegion("Reg2", CurrentBar, 0, ch1, CH1, Color.Transparent, Color.DarkGreen,10); DrawRegion("Reg3", CurrentBar, 0, cl1, CL1, Color.Transparent, Color.DarkGreen,10); } #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 CurrentOpen { get { return Values[0]; } } [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 CurrentHigh { get { return Values[1]; } } [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 CurrentLow { get { return Values[2]; } } [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 mid { get { return Values[3]; } } [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 mid1 { get { return Values[4]; } } [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 mid2 { get { return Values[5]; } } [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 CH1 { get { return Values[6]; } } [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 CL1 { get { return Values[7]; } } [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 ch1 { get { return Values[8]; } } [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 cl1 { get { return Values[9]; } } [Browsable(true)] [Gui.Design.DisplayNameAttribute("Show open")] public bool ShowOpen { get { return showOpen; } set { showOpen = value; } } [Browsable(true)] [Gui.Design.DisplayNameAttribute("Show high")] public bool ShowHigh { get { return showHigh; } set { showHigh = value; } } [Browsable(true)] [Gui.Design.DisplayNameAttribute("Plot current value only")] public bool PlotCurrentValue { get { return plotCurrentValue; } set { plotCurrentValue = value; } } [Browsable(true)] [Gui.Design.DisplayNameAttribute("Show low")] public bool ShowLow { get { return showLow; } set { showLow = value; } } #endregion } } |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
Hello Kelvin Johnson,
Thank you for your post. What you can do if you don't want plots drawn is to convert the DataSeries that have public properties (plots) into non-plottable DataSeries. DataSeries in this manner are used in three places: 1) Declared in the Variables Region: Code:
private DataSeries mid; Code:
mid = new DataSeries (this); Code:
mid.Set(Instrument.MasterInstrument.Round2TickSize ((currentHigh+currentLow)/2)); http://www.ninjatrader-support.com/H...verview24.html Your example will require reworking the code for each DataSeries. All the public properties won't be necessary. You'll have to delete them in addition to restructuring DataSeries. Code:
[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 mid
{
get { return Values[3]; }
}
Ryan M
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Apr 2009
Posts: 19
Thanks: 0
Thanked 0 times in 0 posts
|
Hi Ryan,
Thank you so much for guiding. I'm one step away from getting what I want. How could I let the mid-point values show on the chat as well? { #region Variables private double currentOpen = double.MinValue; private double currentHigh = double.MinValue; private double currentLow = double.MaxValue; private bool plotCurrentValue = false; private bool showOpen = true; private bool showHigh = true; private bool showLow = true; private DataSeries mid; private DataSeries mid1; private DataSeries mid2; #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(new Pen(Color.Orange, 2), PlotStyle.Square, "Current Open")); Add(new Plot(new Pen(Color.Lime, 2), PlotStyle.Square, "Current High")); Add(new Plot(new Pen(Color.Cyan, 2), PlotStyle.Square, "Current Low")); mid = new DataSeries (this); mid1 = new DataSeries (this); mid2 = new DataSeries (this); Plots[0].Pen.DashStyle = DashStyle.Dash; Plots[1].Pen.DashStyle = DashStyle.Dash; Plots[2].Pen.DashStyle = DashStyle.Dash; AutoScale = false; CalculateOnBarClose = false; Overlay = true; } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { if (currentOpen == double.MinValue) currentOpen = Open[0]; if (Bars.SessionBreak) { currentOpen = Open[0]; currentHigh = High[0]; currentLow = Low[0]; } currentHigh = Math.Max(currentHigh, High[0]); currentLow = Math.Min(currentLow, Low[0]); if (ShowOpen) { if (!PlotCurrentValue || !Bars.SessionBreak) CurrentOpen.Set(currentOpen); else for (int idx = 0; idx < CurrentOpen.Count; idx++) CurrentOpen.Set(idx, currentOpen); } if (ShowHigh) { if (!PlotCurrentValue || currentHigh != High[0]) CurrentHigh.Set(currentHigh); else for (int idx = 0; idx < CurrentHigh.Count; idx++) CurrentHigh.Set(idx, currentHigh); } if (ShowLow) { if (!PlotCurrentValue || currentLow != Low[0]) CurrentLow.Set(currentLow); else for (int idx = 0; idx < CurrentLow.Count; idx++) CurrentLow.Set(idx, currentLow); } mid.Set (Instrument.MasterInstrument.Round2TickSize((curre ntHigh+currentLow)/2)); mid1.Set (mid[0]+TickSize*1); mid2.Set (mid[0]-TickSize*1); DrawRegion("Reg1", CurrentBar, 0, mid1, mid2, Color.Transparent, Color.DarkRed,10); } |
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
|
Unfortunately they are not shown per default for draw objects (your DrawRegion), you would need to custom code a marker with the DrawText method then.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Junior Member
Join Date: Apr 2009
Posts: 19
Thanks: 0
Thanked 0 times in 0 posts
|
Hi Bertrand,
I have added DrawText("MID1", true, "MID1", 0, mid1[0] ,1, Color.White, largeFont, StringAlignment.Near, Color.Transparent, Color.Transparent, 0); The chart shows text form rather than the price level.(the price level of 50% retracement : 1.5213). Am I using DrawText wrongly? |
|
|
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
|
Yes, as it would just DrawText the string input you give it, so it prints your MID1 text...try YourMIDValue.ToString() for example.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#7 |
|
Junior Member
Join Date: Apr 2009
Posts: 19
Thanks: 0
Thanked 0 times in 0 posts
|
Hi,
Thanks to Ryan's and Bertrand's helps I won't get what I want so shortly.Great appreciation to both of you and the whole NT support team. Last few questions of this thread. (1)Can Drawtext displays the price markers as PlotLine does? (2)How to make the price markers align with the last price? For the time being ,I set the right margin to 40 from chart properties else the last four decimal digits won't be seen. (3)The last decimal digit is not printed if it is zero. It's OK to me,just want the chart to look neat. (4)The reflection lines appear on chart by using DrawRegion when you plot in different time ranges.Is it inevitable?Any better solution? (5)Am I right to say that Variables,Initialize,onBarUpdate and Properties are the four major areas to look in when you are writing NT scripts? By the way,is there any tutorial about the definition of string,bool,double etc?Have you known any of your certified programmer conduct online courses solely on script writing for NT platform? Best Regards. |
|
|
|
|
|
#8 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
Hi Kelvin,
1) DrawText doesn't have the same features available as plotting. It's pretty much just an empty slate. You can custom code price markers but draw objects won't have this by default. 2) Price Markers indicate on the vertical axis where the last visible price/indicator was at. 3) You can work with the reference sample below for help on string formatting: http://www.ninjatrader-support2.com/...ad.php?t=19174 4) See the method signatures available for DrawRegion() You may be able to accomplish what you want by setting colors to transparent. 5) Those are the main areas to look for when writing indicators. Strategies have some additional items such as OnOrderUpdate(), OnExecution() Concepts of Bool, string, double have existed long before NinjaScript. Doing a google search on "Programming data types" may produce what you want. We hold a class every other week on building Automated strategies with our strategy wizard. This is a good class for getting started with NinjaScript. I've not heard of our partners offering NinjaScript educational seminars. See here for our complete online event schedule. See here for our list of NinjaScript partners.
Ryan M
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| help needed | schaljapin | Indicator Development | 3 | 02-27-2010 03:02 PM |
| Programmer NEEDED!!! | ilyap51 | General Programming | 1 | 12-03-2009 03:59 AM |
| help needed | shan777 | Charting | 8 | 07-06-2009 07:04 AM |
| MACD help needed | ju1234 | Strategy Development | 5 | 11-17-2008 07:43 AM |
| DrawLine help needed | GaryAlbers | Indicator Development | 2 | 02-17-2008 10:24 PM |