Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

applying indicator to chart

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    applying indicator to chart

    Hello,

    I have connected to live connectione and i have appilied to the chart different indicator see on image.
    1.my sample indicator name customroc created by self the code is
    Code:
    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion
    
    //This namespace holds Indicators in this folder and is required. Do not change it. 
    namespace NinjaTrader.NinjaScript.Indicators
    {
    	public class customroc : Indicator
    	{
    		protected override void OnStateChange()
    		{
    			if (State == State.SetDefaults)
    			{
    				Description									= @"";
    				Name										= "customroc";
    				Calculate									= Calculate.OnBarClose;
    				IsOverlay									= false;
    				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;
    				Period					= 14;
    				Smooth					= 3;
    				AddPlot(Brushes.Green, "Abovezero");
    				AddPlot(Brushes.OrangeRed, "Belowzero");
    				AddLine(Brushes.Cornsilk, 1, "Zeroline");
    			}
    			else if (State == State.Configure)
    			{
    			}
    		}
    
    		protected override void OnBarUpdate()
    		{
    			//Add your custom indicator logic here.
    			if (CurrentBar < Period) return;
    		double Abovezero = CurrentDayOHL().CurrentOpen[0];
    			double Belowzero = CurrentDayOHL().CurrentOpen[0];
    		//	Abovezero.Set(ROC(Period)[0]); 
    //Belowzero.Set(ROC(Period)[0]);
    		}
    
    		#region Properties
    		[NinjaScriptProperty]
    		[Range(1, int.MaxValue)]
    		[Display(Name="Period", Order=1, GroupName="Parameters")]
    		public int Period
    		{ get; set; }
    
    		[NinjaScriptProperty]
    		[Range(1, int.MaxValue)]
    		[Display(Name="Smooth", Order=2, GroupName="Parameters")]
    		public int Smooth
    		{ get; set; }
    
    		[Browsable(false)]
    		[XmlIgnore]
    		public Series<double> Abovezero
    		{
    			get { return Values[0]; }
    		}
    
    		[Browsable(false)]
    		[XmlIgnore]
    		public Series<double> Belowzero
    		{
    			get { return Values[1]; }
    		}
    
    		#endregion
    
    	}
    }
    
    #region NinjaScript generated code. Neither change nor remove.
    
    namespace NinjaTrader.NinjaScript.Indicators
    {
    	public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
    	{
    		private customroc[] cachecustomroc;
    		public customroc customroc(int period, int smooth)
    		{
    			return customroc(Input, period, smooth);
    		}
    
    		public customroc customroc(ISeries<double> input, int period, int smooth)
    		{
    			if (cachecustomroc != null)
    				for (int idx = 0; idx < cachecustomroc.Length; idx++)
    					if (cachecustomroc[idx] != null && cachecustomroc[idx].Period == period && cachecustomroc[idx].Smooth == smooth && cachecustomroc[idx].EqualsInput(input))
    						return cachecustomroc[idx];
    			return CacheIndicator<customroc>(new customroc(){ Period = period, Smooth = smooth }, input, ref cachecustomroc);
    		}
    	}
    }
    
    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
    	public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
    	{
    		public Indicators.customroc customroc(int period, int smooth)
    		{
    			return indicator.customroc(Input, period, smooth);
    		}
    
    		public Indicators.customroc customroc(ISeries<double> input , int period, int smooth)
    		{
    			return indicator.customroc(input, period, smooth);
    		}
    	}
    }
    
    namespace NinjaTrader.NinjaScript.Strategies
    {
    	public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
    	{
    		public Indicators.customroc customroc(int period, int smooth)
    		{
    			return indicator.customroc(Input, period, smooth);
    		}
    
    		public Indicators.customroc customroc(ISeries<double> input , int period, int smooth)
    		{
    			return indicator.customroc(input, period, smooth);
    		}
    	}
    }
    
    #endregion
    *no errors but when i applied to chart its not working.
    2. price osilator sample indicator from the existing one i applied to chart its working.
    3.i downloaded form forum and appiled to chart no error in this case but its not working .
    Please can you see the image below and reply me.


    Click image for larger version

Name:	multipleindicator.png
Views:	1
Size:	106.5 KB
ID:	907528

    #2
    Hello,

    Thank you for the post.

    I see that the lines to Plot look to be from NT7, are you asking how to write the lines that are commented out? As it is the indicator would not plot, it is only calculating a value from the CurrentDayOHL indicator and storing it in a variable.

    To plot the values you have in the code currently you could do something like this:

    Code:
    Abovezero[0] = CurrentDayOHL().CurrentOpen[0];
    Belowzero[0] =  CurrentDayOHL().CurrentHigh[0];
    Or for the commented lines:

    Code:
    Abovezero[0] =ROC(Period)[0];
    Belowzero[0] = ROC(Period)[0];
    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by kevinenergy, 02-17-2023, 12:42 PM
    115 responses
    2,699 views
    1 like
    Last Post kevinenergy  
    Started by prdecast, Today, 06:07 AM
    1 response
    4 views
    0 likes
    Last Post NinjaTrader_LuisH  
    Started by Christopher_R, Today, 12:29 AM
    1 response
    14 views
    0 likes
    Last Post NinjaTrader_LuisH  
    Started by chartchart, 05-19-2021, 04:14 PM
    3 responses
    577 views
    1 like
    Last Post NinjaTrader_Gaby  
    Started by bsbisme, Yesterday, 02:08 PM
    1 response
    15 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Working...
    X