Announcement

Collapse
No announcement yet.

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.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by sjsj2732, 03-23-2026, 04:31 AM
    0 responses
    77 views
    0 likes
    Last Post sjsj2732  
    Started by NullPointStrategies, 03-13-2026, 05:17 AM
    0 responses
    313 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    314 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    149 views
    1 like
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    114 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Working...
    X