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

How to add another script into chart

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

    How to add another script into chart

    I have custom class in MyCustomMethods


    Code:
    public class myPositionInfo : Indicator
    	{
    		private readonly StringFormat	far			= new StringFormat {Alignment = StringAlignment.Far};
    		private readonly Font			font1		= new Font("Arial", 9, FontStyle.Bold);
    		private readonly StringFormat	near		= new StringFormat {Alignment = StringAlignment.Near};
    		private readonly Pen			pen			= new Pen(Color.Black);
    		private readonly Brush			redbrush	= new SolidBrush(Color.FromArgb(250, Color.Red));
    
    		[Browsable(false)] public	double		OpenPl		{ get; set;}  
    		protected	override	void	Initialize()	{		Overlay = true;	}
    
    		protected	override	void	OnBarUpdate()	{}
    
    		public	override	void	Plot(Graphics graphics, Rectangle bounds, double min, double max)
    		{
    			if (ChartControl == null) 				return;
    
    			graphics.FillRectangle(graybrush,	5, bounds.Height - 67, 210, 47);
    			graphics.DrawRectangle(pen,			5, bounds.Height - 67, 210, 47);
    			graphics.DrawString("Tracked P&L :"+OpenPl, font1, redbrush, 135f, bounds.Height - 35, far);
    		}
    
    	}

    However, I am unable to call (thus add it on chart) from another primary indicator, using this:

    OnStartup:


    myPositionInfo xyz = new myPositionInfo();
    Add(xyz); //<--- gives error

    How to do that?

    #2
    Hello, TazoTodua.

    Thanks for the post.

    You must make a separate indicator called myPositionInfo. The OnBarUpdate override will not be subscribed in the runtime if the indicator is not initialized by NinjaTrader in the Indicators folder.

    Please see this reference sample linked below on plotting from within a strategy. It is a custom strategy that employs a custom indicator.
    When running a strategy on a chart you may find the need to plot values onto a chart. If these values are internal strategy calculations that are difficult to migrate to an indicator, you can use the following technique to achieve a plot. NinjaTrader 8 With NinjaTrader 8 we introduced strategy plots which provide the ability


    Also, see this reference sample on exposing values from a custom indicator that are not plots.


    Please let us know if we may be of any further assistance.
    Chris L.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Belfortbucks, Today, 09:29 PM
    0 responses
    3 views
    0 likes
    Last Post Belfortbucks  
    Started by zstheorist, Today, 07:52 PM
    0 responses
    7 views
    0 likes
    Last Post zstheorist  
    Started by pmachiraju, 11-01-2023, 04:46 AM
    8 responses
    150 views
    0 likes
    Last Post rehmans
    by rehmans
     
    Started by mattbsea, Today, 05:44 PM
    0 responses
    6 views
    0 likes
    Last Post mattbsea  
    Started by RideMe, 04-07-2024, 04:54 PM
    6 responses
    33 views
    0 likes
    Last Post RideMe
    by RideMe
     
    Working...
    X