NexusFi: Find Your Edge


Home Menu

 





Ninjascript help Please


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one GraDman with 5 posts (3 thanks)
    2. looks_two trendisyourfriend with 4 posts (6 thanks)
    3. looks_3 Jasonnator with 4 posts (9 thanks)
    4. looks_4 JonnyBoy with 1 posts (3 thanks)
      Best Posters
    1. looks_one JonnyBoy with 3 thanks per post
    2. looks_two Jasonnator with 2.3 thanks per post
    3. looks_3 trendisyourfriend with 1.5 thanks per post
    4. looks_4 GraDman with 0.6 thanks per post
    1. trending_up 4,484 views
    2. thumb_up 21 thanks given
    3. group 7 followers
    1. forum 13 posts
    2. attach_file 3 attachments




 
Search this Thread

Ninjascript help Please

  #1 (permalink)
GraDman
Tennessee
 
Posts: 6 since Aug 2020
Thanks Given: 9
Thanks Received: 4

Hi,

I have been learning ninja script, what I'm trying to do is program my indicator so that at market open (9:30am) it will start to plot a line of the market open price until the market closes (5:00pm) where it then stops plotting the market open price line until the next market day.

The Current Price line indicator that comes loaded with NT8 doesn't start at 9:30am through to market close at 5pm.

I have been reading and studying the NinjaScript Reference like crazy trying to workout the DateTime / TimeSpan section to the point of getting a headache lol

So any help or advice would be appreciated.

Thanks
Gra.

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Ninja Mobile Trader VPS (ninjamobiletrader.com)
Trading Reviews and Vendors
Better Renko Gaps
The Elite Circle
Exit Strategy
NinjaTrader
Are there any eval firms that allow you to sink to your …
Traders Hideout
Online prop firm The Funded Trader (TFT) going under?
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
59 thanks
Funded Trader platforms
37 thanks
GFIs1 1 DAX trade per day journal
22 thanks
NexusFi site changelog and issues/problem reporting
22 thanks
The Program
20 thanks
  #2 (permalink)
 
trendisyourfriend's Avatar
 trendisyourfriend 
Quebec Canada
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG
Trading: ES, NQ, YM
Frequency: Daily
Duration: Minutes
Posts: 4,527 since Oct 2009
Thanks Given: 4,171
Thanks Received: 6,018

Try this:

 
Code
{
	public class bmPlotOpenTillEOD : Indicator
	{
		private DateTime barTime;
		private bool permissionToDraw;
		private double openLevel;
		
		protected override void OnStateChange()
		{
			if (State == State.SetDefaults)
			{
				Description									= @"This indicator plots a line representing the open level till the end of day (EOD).";
				Name										= "bmPlotOpenTillEOD";
				Calculate									= Calculate.OnBarClose;
				IsOverlay									= true;
				DisplayInDataBox							= true;
				DrawOnPricePanel							= true;
				DrawHorizontalGridLines						= false;
				DrawVerticalGridLines						= false;
				PaintPriceMarkers							= true;
				ScaleJustification							= NinjaTrader.Gui.Chart.ScaleJustification.Right;
				//Disable this property if your indicator requires custom values that cumulate with each new market data event. 
				//See Help Guide for additional information.
				IsSuspendedWhileInactive					= true;
				
				AddPlot(Brushes.Yellow, "Open Level"); //
				Plots[0].DashStyleHelper = DashStyleHelper.Solid;
				Plots[0].PlotStyle = PlotStyle.Line;
				Plots[0].Width = 2;
				
			}
			else if (State == State.Configure)
			{
				permissionToDraw = false;
				openLevel = 0;
			}
		}

		protected override void OnBarUpdate()
		{
			// indicator logic
			
			// read the time of the current bar
			barTime = Bars.GetTime(CurrentBar);

			// let's check if we can start drawing the open level
			if ( barTime.Hour == 9 && barTime.Minute == 31 ) {
				permissionToDraw = true;
				// remember the open level
				openLevel = Open[0];
			}

			if ( permissionToDraw ) {
				plotOpenLevel[0] = openLevel;
			}

			if( barTime.Hour == 17 ) {
				permissionToDraw = false;
				openLevel = 0;
			}

		}
		
		// custom wrappers section
		private Series<double> plotOpenLevel
		{
		  get { Update(); return Values[0]; }
		}

	}
}

Reply With Quote
Thanked by:
  #3 (permalink)
GraDman
Tennessee
 
Posts: 6 since Aug 2020
Thanks Given: 9
Thanks Received: 4


Hi again,

Thanks for your quick response and the code, It works but with a slight problem, what I'm seeing is it's not taking the open[0] price right at 9:30am, if you look at today, there were 2 bars with the 9:30 time stamp and it drew the line from the second one that had a half point difference. I tried adding so that it counted for the second as well but if you don't tell it to look for the exact second that the current bar prints at, it wont plot the line.

Thanks for your help.
Gra

Reply With Quote
  #4 (permalink)
 
trendisyourfriend's Avatar
 trendisyourfriend 
Quebec Canada
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG
Trading: ES, NQ, YM
Frequency: Daily
Duration: Minutes
Posts: 4,527 since Oct 2009
Thanks Given: 4,171
Thanks Received: 6,018


GraDman View Post
Hi again,

Thanks for your quick response and the code, It works but with a slight problem, what I'm seeing is it's not taking the open[0] price right at 9:30am, if you look at today, there were 2 bars with the 9:30 time stamp and it drew the line from the second one that had a half point difference. I tried adding so that it counted for the second as well but if you don't tell it to look for the exact second that the current bar prints at, it wont plot the line.

Thanks for your help.
Gra

What instrument are you testing? ES?
If that is the case then the open can be read at 9:31 ET with Ninjatrader on a 1 minute chart. There is only one bar at 9:31 ET.

Reply With Quote
  #5 (permalink)
GraDman
Tennessee
 
Posts: 6 since Aug 2020
Thanks Given: 9
Thanks Received: 4

Sorry I forgot to say that I'm trading the ES, using a 2000 tick chart, today there is 2 bars at 9:30 am, looking back in my history sometimes there is 3 bars at 9:30am.

Reply With Quote
  #6 (permalink)
 
JonnyBoy's Avatar
 JonnyBoy 
Montreal, Quebec
 
Experience: Advanced
Platform: NinjaTrader 8
Broker: Kinetick
Trading: ES
Posts: 1,561 since Apr 2012
Thanks Given: 706
Thanks Received: 3,854


GraDman View Post
Sorry I forgot to say that I'm trading the ES, using a 2000 tick chart, today there is 2 bars at 9:30 am, looking back in my history sometimes there is 3 bars at 9:30am.

As a tick data series is non time dependent it means a bar of this type can traverse the market open without closing. I.E. it doesn't care about time.

Try this. It should be good for any bar type / data series.

--------------------------------------------------------
- Trade what you see. Invest in what you believe -
--------------------------------------------------------
Attached Files
Elite Membership required to download: Opening-Price-(R1).zip
Reply With Quote
  #7 (permalink)
 
trendisyourfriend's Avatar
 trendisyourfriend 
Quebec Canada
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG
Trading: ES, NQ, YM
Frequency: Daily
Duration: Minutes
Posts: 4,527 since Oct 2009
Thanks Given: 4,171
Thanks Received: 6,018

You'll need to create a new indicator which Calculate.OnEachTick and you will also need to add a 1 minute dataseries and use the BarsArray[1] instruction to refer to this dataseries. I named this indicator "PlotOpenLevel".

The changes are:

in the State == State.Configure condition add this line...
AddDataSeries(Data.BarsPeriodType.Minute, 1);

In the OnBarUpdate method you need to read the time this way:
BarsArray[1] refers to the minute interval
barTime = BarsArray[1].GetTime(CurrentBar);

Then at 9:31 we read the open of the bar on the minute interval
openLevel = BarsArray[1].GetOpen(CurrentBar);

 
Code
{
	public class PlotOpenLevel : Indicator
	{
		
		private DateTime barTime;
		private bool permissionToDraw;
		private double openLevel;
		
		protected override void OnStateChange()
		{
			if (State == State.SetDefaults)
			{
				Description									= @"Enter the description for your new custom Indicator here.";
				Name										= "PlotOpenLevel";
				Calculate									= Calculate.OnEachTick;
				IsOverlay									= true;
				DisplayInDataBox							= true;
				DrawOnPricePanel							= true;
				DrawHorizontalGridLines						= true;
				DrawVerticalGridLines						= true;
				PaintPriceMarkers							= true;
				ScaleJustification							= NinjaTrader.Gui.Chart.ScaleJustification.Right;
				//Disable this property if your indicator requires custom values that cumulate with each new market data event. 
				//See Help Guide for additional information.
				IsSuspendedWhileInactive					= true;
				AddPlot(Brushes.Orange, "OpeningPrice");
			}
			else if (State == State.Configure)
			{
				AddDataSeries(Data.BarsPeriodType.Minute, 1);
				permissionToDraw = false;
				openLevel = 0;
			}
		}

		protected override void OnBarUpdate()
		{
			//Add your custom indicator logic here
			
			// read the time of the current bar
			barTime = BarsArray[1].GetTime(CurrentBar);
			// let's check if we can start drawing the open level
			if ( barTime.Hour == 9 && barTime.Minute == 31 ) {
				permissionToDraw = true;
				// remember the open level
				openLevel = BarsArray[1].GetOpen(CurrentBar);
			}

			if ( permissionToDraw ) {
				OpeningPrice[0] = openLevel;
			}

			if( barTime.Hour == 17 ) {
				permissionToDraw = false;
				openLevel = 0;
			}			
		}

		#region Properties

		[Browsable(false)]
		[XmlIgnore]
		public Series<double> OpeningPrice
		{
			get { return Values[0]; }
		}
		#endregion

	}
}

Reply With Quote
Thanked by:
  #8 (permalink)
 
trendisyourfriend's Avatar
 trendisyourfriend 
Quebec Canada
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG
Trading: ES, NQ, YM
Frequency: Daily
Duration: Minutes
Posts: 4,527 since Oct 2009
Thanks Given: 4,171
Thanks Received: 6,018

PlotOpenLine

Attached Files
Elite Membership required to download: bmPlotOpenMultiTF.zip
Reply With Quote
Thanked by:
  #9 (permalink)
 
Jasonnator's Avatar
 Jasonnator 
Denver, Colorado United States
 
Experience: Intermediate
Platform: NT8 + Custom
Broker: NT Brokerage, Kinetick, IQFeed, Interactive Brokers
Trading: ES
Posts: 159 since Dec 2014
Thanks Given: 40
Thanks Received: 166

You need to use the SessionIterator. What you're trying to do is exactly its use case. SessionIterator combined with IsFirstTickOfBar will get you exactly the functionality you want.

Cheers

Reply With Quote
Thanked by:
  #10 (permalink)
GraDman
Tennessee
 
Posts: 6 since Aug 2020
Thanks Given: 9
Thanks Received: 4



Jasonnator View Post
You need to use the SessionIterator. What you're trying to do is exactly its use case. SessionIterator combined with IsFirstTickOfBar will get you exactly the functionality you want.

Cheers

Thanks you, I just watched your new video, I hope you cover this sometime in a video

Reply With Quote
Thanked by:




Last Updated on August 28, 2020


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts