NexusFi: Find Your Edge


Home Menu

 





Adding Horizontal Line to indicator /Ninjascript


Discussion in NinjaTrader

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




 
 

Adding Horizontal Line to indicator /Ninjascript

 
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!


Can you help answer these questions
from other members on NexusFi?
NexusFi Journal Challenge - April 2024
Feedback and Announcements
Futures True Range Report
The Elite Circle
ZombieSqueeze
Platforms and Indicators
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
Deepmoney LLM
Elite Quantitative GenAI/LLM
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
61 thanks
Funded Trader platforms
38 thanks
NexusFi site changelog and issues/problem reporting
26 thanks
GFIs1 1 DAX trade per day journal
19 thanks
The Program
18 thanks
 
 
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


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 -
--------------------------------------------------------
Thanked by:
 
 
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


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

Thanked by:
 
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


 



Last Updated on September 10, 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