NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 04-05-2010, 11:46 AM   #1
kelvin johnson
Junior Member
 
Join Date: Apr 2009
Posts: 19
Thanks: 0
Thanked 0 times in 0 posts
Default Helps Needed

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
}
}
Attached Images
File Type: jpg ntret.JPG (47.7 KB, 11 views)
kelvin johnson is offline  
Reply With Quote
Old 04-05-2010, 12:38 PM   #2
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

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;
2) Instantiated in the Initialize() Method:
Code:
mid = new DataSeries (this);
3) Values set in OnBarUpdate() method:
Code:
mid.Set(Instrument.MasterInstrument.Round2TickSize ((currentHigh+currentLow)/2));
The tutorial below can help with using DataSeries that are not plots.
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]; }
}
NinjaTrader_RyanM is offline  
Reply With Quote
Old 04-06-2010, 02:09 AM   #3
kelvin johnson
Junior Member
 
Join Date: Apr 2009
Posts: 19
Thanks: 0
Thanked 0 times in 0 posts
Default

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);

}
Attached Images
File Type: jpg ntret.JPG (55.8 KB, 9 views)
kelvin johnson is offline  
Reply With Quote
Old 04-06-2010, 04:35 AM   #4
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
Default

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.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 04-06-2010, 12:01 PM   #5
kelvin johnson
Junior Member
 
Join Date: Apr 2009
Posts: 19
Thanks: 0
Thanked 0 times in 0 posts
Default

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?
Attached Images
File Type: jpg ntret.JPG (43.8 KB, 7 views)
kelvin johnson is offline  
Reply With Quote
Old 04-06-2010, 12:05 PM   #6
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
Default

Yes, as it would just DrawText the string input you give it, so it prints your MID1 text...try YourMIDValue.ToString() for example.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 04-07-2010, 10:33 AM   #7
kelvin johnson
Junior Member
 
Join Date: Apr 2009
Posts: 19
Thanks: 0
Thanked 0 times in 0 posts
Default

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.
Attached Images
File Type: jpg ntret.JPG (57.3 KB, 9 views)
kelvin johnson is offline  
Reply With Quote
Old 04-07-2010, 11:18 AM   #8
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 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.
NinjaTrader_RyanM 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
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


All times are GMT -6. The time now is 12:51 PM.