NexusFi: Find Your Edge


Home Menu

 





Adding Horizontal Line to indicator /Ninjascript


Discussion in NinjaTrader

Updated
    1. trending_up 4,478 views
    2. thumb_up 6 thanks given
    3. group 3 followers
    1. forum 3 posts
    2. attach_file 1 attachments




 
Search this Thread
  #1 (permalink)
jgivler
Las Vegas, NV
 
Posts: 2 since Feb 2019
Thanks Given: 0
Thanks Received: 1

I am trying to customize the ninjascript code on a stock RVI indicator in NT8. All I want to do is add 3 more horizontal lines. So that I have the 70, 60, 40, 30 levels marked. The stock RVI indicator has one horizontal line, called the signal line, that functions as one of them. How can I add in 3 more horizontal lines, with specific width, dash style and color? I've tried manually adding code in and nothing happens.

Secondly, although I have created a copy of the original code and saved as a new indicator, when I go to the chart to add the indicator, it is not an option in the list. Do I have to do something after writing a new indicator code to make it be added to the indicator list?

Thanks!


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Six Days to Kickoff: World Cup Prediction Markets Hit $1 …
Prediction Markets & Event Contracts
Would a node-based workflow for automated trading be useful?
Traders Hideout
Weekend Update: First Qatari LNG Transit Attempted -- IR …
Traders Hideout
The June 15 Resolution Trap: Irans Agreed Text Still Pri …
Prediction Markets & Event Contracts
CFTC Opens First COT Report Review in 20 Years -- Asks W …
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
NexusFi site changelog and issues/problem reporting
8 thanks
Darmok and Jalad at Tanagra
1 thanks
  #2 (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,872


jgivler View Post
I am trying to customize the ninjascript code on a stock RVI indicator in NT8. All I want to do is add 3 more horizontal lines. So that I have the 70, 60, 40, 30 levels marked. The stock RVI indicator has one horizontal line, called the signal line, that functions as one of them. How can I add in 3 more horizontal lines, with specific width, dash style and color? I've tried manually adding code in and nothing happens.

Secondly, although I have created a copy of the original code and saved as a new indicator, when I go to the chart to add the indicator, it is not an option in the list. Do I have to do something after writing a new indicator code to make it be added to the indicator list?

Thanks!

The absolute easiest way to do this is is to add the lines you want to the panel you want via the Constant lines indicator that comes stock with NT8. Else, you can just copy the RVI indicator and add the code to give you the lines.

ES 09-20 (2000 Tick) 2020_09_09 (4_37_03 PM)


--------------------------------------------------------
- Trade what you see. Invest in what you believe -
--------------------------------------------------------
Reply With Quote
Thanked by:
  #3 (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,581 since Oct 2009
Thanks Given: 4,267
Thanks Received: 6,208


Add the lines which are in Bold and compile your script or just press F5 to compile then you should see it in your list of indicators. Basically, each time you add a line via the AddLine command, Ninja adds it in a special collection names Lines[] which holds all the lines created in the script. Since there was already one line to represent the 50 level and the two other lines then the Lines[] collection contains 3 items.

You can modify the properties of a line by using this collection like this:

Lines[1].Width = 2;
Lines[1].DashStyleHelper = DashStyleHelper.Dash;

You can learn a bit more by visiting this page:
https://ninjatrader.com/support/helpGuides/nt8/lines.htm

 
Code
		protected override void OnStateChange()
		{
			if (State == State.SetDefaults)
			{
				Description					= NinjaTrader.Custom.Resource.NinjaScriptIndicatorDescriptionRVI;
				Name						= "myNewRVI";
				IsSuspendedWhileInactive	= true;
				Period						= 14;
				IsOverlay					= false;

				AddPlot(Brushes.Goldenrod,		NinjaTrader.Custom.Resource.NinjaScriptIndicatorNameRVI);
				AddLine(Brushes.DarkGray,	50,	NinjaTrader.Custom.Resource.RVISignalLine);
				AddLine(Brushes.Yellow,	30,	"above50");
				AddLine(Brushes.Cyan,	70,	"below50");
			}

			else if (State == State.Configure)
			{
				savedCurrentBar	= -1;
				dnAvgH			= dnAvgL = upAvgH = upAvgL = lastDnAvgH
								= lastDnAvgL = lastUpAvgH = lastUpAvgL = 0;
				Lines[1].Width = 2;
				Lines[1].DashStyleHelper = DashStyleHelper.Dash;
				Lines[2].Width = 2;
				Lines[2].DashStyleHelper = DashStyleHelper.Dash;
		}


Reply With Quote
Thanked by:
  #4 (permalink)
jgivler
Las Vegas, NV
 
Posts: 2 since Feb 2019
Thanks Given: 0
Thanks Received: 1

Thank you guys so much! I learned from both of you. Really appreciate that you took the time to help!!!

Best,
J


Reply With Quote




Last Updated on September 10, 2020


© 2026 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 - Downloads - Top
no new posts