NexusFi: Find Your Edge


Home Menu

 





Form/Window Indicator appears in all open workspaces


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one bmtrader333 with 7 posts (3 thanks)
    2. looks_two DavidHP with 2 posts (1 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 nightshade with 1 posts (0 thanks)
    1. trending_up 5,371 views
    2. thumb_up 4 thanks given
    3. group 4 followers
    1. forum 10 posts
    2. attach_file 2 attachments




 
Search this Thread

Form/Window Indicator appears in all open workspaces

  #1 (permalink)
 bmtrader333 
Greensboro, NC, USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: ES, NQ
Posts: 12 since Jan 2012
Thanks Given: 1
Thanks Received: 5

Hello,

I'm having a problem with a custom ninjascript indicator I built for NT7. The indicator creates its own Form/Window to display information in.

My problem is this: when I add my indicator to a chart in one workspace, the form/window it creates shows up not only in the workspace in which the indicator's home chart is located, but also in all other open workspaces in my NinjaTrader 7 client.

I know it is possible to get my indicator's form/window to only show up in the workspace in which it is applied (I have a paid-for 3rd-party indicator that does this successfully), but I don't know how to do this. Can anyone tell me how to do this or at least point me in the right direction?

(When I asked this question on the NT forums, I just got the dreaded reply that my problem was "unsupported".)

Thanks in advance for any help with this question.

Started this thread Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
Trade idea based off three indicators.
Traders Hideout
MC PL editor upgrade
MultiCharts
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Better Renko Gaps
The Elite Circle
Increase in trading performance by 75%
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Diary of a simple price action trader
26 thanks
Just another trading journal: PA, Wyckoff & Trends
25 thanks
Tao te Trade: way of the WLD
23 thanks
My NQ Trading Journal
16 thanks
HumbleTraders next chapter
9 thanks
  #3 (permalink)
 nightshade 
canton mi
 
Experience: Beginner
Platform: ninja xtrader
Trading: tf, es
Posts: 230 since Jan 2014
Thanks Given: 328
Thanks Received: 146



bmtrader333 View Post
Hello,

I'm having a problem with a custom ninjascript indicator I built for NT7. The indicator creates its own Form/Window to display information in.

My problem is this: when I add my indicator to a chart in one workspace, the form/window it creates shows up not only in the workspace in which the indicator's home chart is located, but also in all other open workspaces in my NinjaTrader 7 client.

I know it is possible to get my indicator's form/window to only show up in the workspace in which it is applied (I have a paid-for 3rd-party indicator that does this successfully), but I don't know how to do this. Can anyone tell me how to do this or at least point me in the right direction?

(When I asked this question on the NT forums, I just got the dreaded reply that my problem was "unsupported".)

Thanks in advance for any help with this question.

how do you post a forum i cant find the button

Reply With Quote
  #4 (permalink)
 
DavidHP's Avatar
 DavidHP 
Isla Mujeres, MX
Legendary Market Wizard
 
Experience: Advanced
Platform: NinjaTrader
Broker: Ninjatrader / Optimus Futures / AmpFutures
Trading: ES / 6E / 6B / CL
Frequency: Every few days
Duration: Minutes
Posts: 1,609 since Aug 2009
Thanks Given: 11,335
Thanks Received: 2,743


bmtrader333 View Post
Hello,

I'm having a problem with a custom ninjascript indicator I built for NT7. The indicator creates its own Form/Window to display information in.

You will get more response if you post the indicator and/or image so we can analyze and respond easily.

FWIW

Rejoice in the Thunderstorms of Life . . .
Knowing it's not about Clouds or Wind. . .
But Learning to Dance in the Rain ! ! !
Follow me on Twitter Reply With Quote
Thanked by:
  #5 (permalink)
 bmtrader333 
Greensboro, NC, USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: ES, NQ
Posts: 12 since Jan 2012
Thanks Given: 1
Thanks Received: 5

I'm posting the relevant parts of the code below. (The "..." below just represent indicator code that I have omitted from my post.) The indentation got messed up a bit, but I think the code is still fairly readable. This code creates a "reconstructed tape" that is similar to what you'd see with a time & sales window. (Sorry that I can't post a screenshot of this. I tried, but I don't have enough posts here at Big Mike's to be allowed to post an image...)

For some reason, any reconstructed tape form/window that this code creates shows up in all open workspaces in my NT7 client. I want the reconstructed tape window to only show up in the workspace that houses the chart to which this indicator is applied. (In other words, I want the reconstructed tape window to only display in the workspace in which it is applied, and I want the reconstructed tape window to only show up in the available window list of the workspace in which it is applied. Currently, the reconstructed tape window displays in all open workspaces, and it shows up in the available window list of all open workspaces.)

Again, any help in figuring out how to get this reconstructed tape form/window to only show up in the workspace in which it is applied is greatly appreciated. (I know this is possible because the paid-for 3rd party reconstructed tape indicator that I am emulating creates a form/window that displays, and is available for display, only in the workspace that contains the chart to which it is applied.)

 
Code
 
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using System.IO;
using System.Windows.Forms;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
#endregion

// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{

    public class ReconTickRecorder05 : Indicator
    {

...

		private		Int32			windowX = 30;
		private		Int32			windowY = 30;
		private		Int32			windowWidth = 150;
		private		Int32			windowHeight = 300;
		private		RT_Form 		        RT_Form1;
		private		int				numGridRows = 70;
		private		Color			bidColor = Color.Red;
		private		Color			askColor = Color.Lime;


...

		protected override void OnStartUp()
		{	
			// create window for recon tape
			// Create a new instance of the form.
   			RT_Form1 = new RT_Form(this);
			RT_Form1.createRTWindow();
		}


		protected override void OnTermination()
		{	
			// dispose of recon tape output window
			if (RT_Form1.Exists) { RT_Form1.Dispose(); }
		}

...

		class RT_Form : Form 
		{
			private		ReconTickRecorder05 	myRT;
			private		DataGridView			myDataGridView;	
			private		bool					exists = false;
		
			public RT_Form(ReconTickRecorder05 outerRT)
			{
				myRT = outerRT;
				exists = true;
			}
			
			public void createRTWindow()
			{
				this.FormBorderStyle = FormBorderStyle.Sizable;
				// Set the caption bar text of the form. 
				if (myRT.Instrument != null) { this.Text = myRT.Instrument.MasterInstrument.Name + "_RT"; }
				else { this.Text = "RTape"; }
				this.MaximizeBox = true;
				this.MinimizeBox = true;
				
				// create DataGridView and add it to form
				myDataGridView = new DataGridView();		
				this.Controls.Add(myDataGridView);

				// set properties of myDataGridView
				myDataGridView.ColumnCount = 3;
				myDataGridView.Name = "RT_DataGridView";
myDataGridView.AutoSizeColumnsMode=DataGridViewAutoSizeColumnsMode.DisplayedCellsExceptHeader;	
				myDataGridView.CellBorderStyle = DataGridViewCellBorderStyle.None;
				myDataGridView.RowHeadersVisible = false;
				myDataGridView.Font = new Font(System.Drawing.FontFamily.GenericSansSerif, (float)8.25);
				myDataGridView.AllowUserToAddRows = false;
				myDataGridView.AllowUserToDeleteRows = false;
				myDataGridView.AllowUserToOrderColumns = false;
				myDataGridView.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;
				myDataGridView.AllowUserToResizeColumns = false;
				myDataGridView.AllowUserToResizeRows = false;
				myDataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
				myDataGridView.MultiSelect = false;
				myDataGridView.Dock = DockStyle.Fill;
				myDataGridView.ReadOnly = true;			
				myDataGridView.ColumnHeadersVisible = false;
				myDataGridView.RowsDefaultCellStyle.BackColor = Color.Black;
				myDataGridView.RowsDefaultCellStyle.ForeColor = Color.Red;
				myDataGridView.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
				myDataGridView.RowTemplate.Height = 13;
				myDataGridView.ScrollBars = System.Windows.Forms.ScrollBars.None;

				myDataGridView.Columns[0].Name = "Time";
				myDataGridView.Columns[1].Name = "Price";
				myDataGridView.Columns[2].Name = "Volume";
				myDataGridView.Columns[2].MinimumWidth = 30;
				
				// Display the form.
				this.StartPosition = FormStartPosition.Manual;
				this.Location = new Point(myRT.WindowX, myRT.WindowY);
				this.Size = new Size(myRT.WindowWidth, myRT.WindowHeight);
				this.Show();
			}
			
			public void printRTRow(string[] rowArray, int rowType)
			{
				// print new row
				myDataGridView.Rows.Insert(0, rowArray);
				if (rowType == 1) { myDataGridView.Rows[0].DefaultCellStyle.ForeColor = myRT.BidColor; }
				else if (rowType == 2 ) { myDataGridView.Rows[0].DefaultCellStyle.ForeColor = myRT.AskColor; }
				else { myDataGridView.Rows[0].DefaultCellStyle.ForeColor = Color.Beige; }
				
				// remove any row beyond specified NumGridRows as it is created
				if (myDataGridView.Rows.Count > myRT.NumGridRows) {
					myDataGridView.Rows.RemoveAt(myDataGridView.Rows.Count - 1);	
				}
			}
			
			protected override void OnLocationChanged(System.EventArgs e)
			{
				try
				{
					myRT.WindowX = this.Bounds.X;
					myRT.WindowY = this.Bounds.Y;
				}
				catch{}
				base.OnLocationChanged(e);
			}

			protected override void OnResizeEnd(System.EventArgs e)
			{
				try
				{
					myRT.WindowWidth = this.Bounds.Width;
					myRT.WindowHeight = this.Bounds.Height;	
				}
				catch{}
				base.OnResizeEnd(e);
			}
			
			protected override void OnClosed(System.EventArgs e)
			{
				try
				{
					this.exists = false;
				}
				catch{}
				base.OnClosed(e);
			}
						
			#region RT_Form_Properties
			
			public bool Exists
			{
				get { return exists; }
			}
			
			#endregion
			
			
		} // end class RT_Form


        #region Properties

...

	[Description("Number of rows in Recon Tape Output Window")]
        [GridCategory("2. Recon Tape Output Window")]
        [Gui.Design.DisplayNameAttribute("1. NumRTRows")]
        public int NumGridRows
        {
            get { return numGridRows; }
            set { numGridRows = Math.Max(1, value); }
        }		
		
	[XmlIgnore()]
	[Description("Color of Bids in Recon Tape Output Window")]
        [GridCategory("2. Recon Tape Output Window")]
        [Gui.Design.DisplayNameAttribute("2. Bid Color")]
        public Color BidColor
        {
            get { return bidColor; }
            set { bidColor = value; }
        }
		
	[Browsable(false)]
	public string BidColorSerialize
	{
		get { return NinjaTrader.Gui.Design.SerializableColor.ToString(bidColor); }
		set { bidColor = NinjaTrader.Gui.Design.SerializableColor.FromString(value); }
	}
		
	[XmlIgnore()]
	[Description("Color of Asks in Recon Tape Output Window")]
        [GridCategory("2. Recon Tape Output Window")]
        [Gui.Design.DisplayNameAttribute("3. Ask Color")]
        public Color AskColor
        {
            get { return askColor; }
            set { askColor = value; }
        }
		
	[Browsable(false)]
	public string AskColorSerialize
	{
		get { return NinjaTrader.Gui.Design.SerializableColor.ToString(askColor); }
		set { askColor = NinjaTrader.Gui.Design.SerializableColor.FromString(value); }
	}
		
	[Description("Recon Tape Output Window X position")]
        [GridCategory("2. Recon Tape Output Window")]
        [Gui.Design.DisplayNameAttribute("4. Window X position")]
        public Int32 WindowX
        {
            get { return windowX; }
            set { windowX = Math.Max(0, value); }
        }
		
	[Description("Recon Tape Output Window Y position")]
        [GridCategory("2. Recon Tape Output Window")]		
        [Gui.Design.DisplayNameAttribute("5. Window Y position")]
        public Int32 WindowY
        {
            get { return windowY; }
            set { windowY = Math.Max(0, value); }
        }
		
	[Description("Recon Tape Output Window width")]
        [GridCategory("2. Recon Tape Output Window")]		
        [Gui.Design.DisplayNameAttribute("6. Window width")]
        public Int32 WindowWidth
        {
            get { return windowWidth; }
            set { windowWidth = Math.Max(20, value); }
        }
		
	[Description("Recon Tape Output Window height")]
        [GridCategory("2. Recon Tape Output Window")]		
        [Gui.Design.DisplayNameAttribute("7. Window height")]
        public Int32 WindowHeight
        {
            get { return windowHeight; }
            set { windowHeight = Math.Max(20, value); }
        }		
		
        #endregion


    } // end class ReconTickRecorder05

} // namespace

Started this thread Reply With Quote
  #6 (permalink)
 
DavidHP's Avatar
 DavidHP 
Isla Mujeres, MX
Legendary Market Wizard
 
Experience: Advanced
Platform: NinjaTrader
Broker: Ninjatrader / Optimus Futures / AmpFutures
Trading: ES / 6E / 6B / CL
Frequency: Every few days
Duration: Minutes
Posts: 1,609 since Aug 2009
Thanks Given: 11,335
Thanks Received: 2,743


bmtrader333 View Post
I'm posting the relevant parts of the code below. (The "..." below just represent indicator code that I have omitted from my post.)



With 'secret code' it is probably best for you to go to the Ninjatrader website and see if you can hire a professional coder to resolve the issue.

Maybe someone here will try to tackle the problem with your code, but with incomplete code you probably will only get incomplete answers and no resolution.

L8r

Rejoice in the Thunderstorms of Life . . .
Knowing it's not about Clouds or Wind. . .
But Learning to Dance in the Rain ! ! !
Follow me on Twitter Reply With Quote
  #7 (permalink)
 bmtrader333 
Greensboro, NC, USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: ES, NQ
Posts: 12 since Jan 2012
Thanks Given: 1
Thanks Received: 5

Thanks for your input DavidHP...

But actually, in response to DavidHP's most friendly feedback, I have attached a working version of my indicator code example above. It's the exact same code as above, minus the points of ellipsis, and with empty Initialize() and OnBarUpdate() methods added. For anyone who wants to have working code to play with, this indicator code illustrates the problem. When you apply it to a chart, it creates a form/window that displays in all open workspaces on your NT7 client and that shows up in the list of available windows for every open workspace on your NT7 client. (Make sure to have at least two workspaces open when you apply this indicator to a chart to be able to see this effect.)

It's easy to fix my problem by just setting the form's Visible property to false whenever the workspace in which it is originally applied is not the workspace currently being viewed. (When the form is first created/instantiated, set a variable to hold the "name" of the workspace currently being viewed. Later checks compare this workspace "name" to the "name" of the workspace currently being viewed. If they don't match, make the form invisible. If they do match, make the form visible again.)

Unfortunately, this requires that I be able to get at which workspace is currently being viewed through ninjascript code.

Does anyone on here know what calls to make in ninjascript in order to get at workspace-related info?

Thanks in advance for any help with this question.

Attached Files
Elite Membership required to download: ReconTickRecorder05.zip
Started this thread Reply With Quote
  #8 (permalink)
 bmtrader333 
Greensboro, NC, USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: ES, NQ
Posts: 12 since Jan 2012
Thanks Given: 1
Thanks Received: 5

Haven't had power since the night of my last post due to an ice storm that hit my area...

In any case, I now have a semi-solution to my problem that's probably about as good as I'm going to get. Thanks to Gomi for his above/sticky post about the free utility/program Microsoft FxCop. (I'm still 1 post shy of being able to post links... but this sticky link is at the top of the NinjaTrader Programming front-page, and it's entitled: How to check your code using Visual Studio and FxCop.)

I didn't use FxCop to analyze my indicator code, but I did point it to the targets NinjaTrader.Custom.dll, NinjaTrader.Core.dll, and to Ninjatrader.exe in order to get a class-hierarchy/tree to examine. After perusing around around a little, I was lucky enough to find what I needed in the class-hierarchy/tree of NinjaTrader.Core.dll.

NinjaTrader 7 has a public static class in the NinjaTrader.Gui namespace called NinjaTrader.Gui.WorkspaceOptions. Within this class is a public static method called NinjaTrader.Gui.WorkspaceOptions.GetCurrentFilename() which returns a string that is the filepath to the xml file that your current workstation is saved to. This will be something like:

C:\Users\<user_name>\Documents\NinjaTrader 7\workspaces\MyWorkspace.xml

The last part of the string is always <the_name_of_your_current_workspace>.xml.

So, once you have this string, you can parse it to get the name of the current workspace. (You could also just use the entire filename of the current workspace in future comparisons, without parsing out the name, if you want to.)

From there, you can toggle the Visible property of the form between true and false based on the name (or filename) of the current workspace (see my previous post for the basic logic behind this toggling) in order to make sure your form/window only shows up in the workspace where the indicator that creates it is applied.


In the solution I came up with, I actually created a boolean variable (universalRTVisibility) to allow you to purposefully show the indicator's form/window in all workspaces if you want to. Since, the full code for this indicator implements something like a time & sales window that gets called at every market data event, this helps to increase efficiency significantly by allowing one to run as few instances of the indicator as possible. If you also use a form/window in an indicator that uses a lot of CPU cycles, you might want to run as few instances of it as possible, as well. Of course, if your workspaces are not set up to allow for this (for example, if the indicator's form/window is not positioned in the same place in every workspace), then you'll probably just want to contain the indicator's form/window within the workspace in which it is applied. Again, with the solution I came up with, you can choose to set things up either way.

I have attached a new version of my previously attached indicator that shows the solution to my problem using the above call and a little bit of logic. Unfortunately, this solution only toggles visibility of the indicator's form/window off/on as instrument market data arrives to the chart where the indicator is applied. In slow markets this could cause the indicator's form/window to show up in workspaces where it is not applied until a market data event arrives. Also, when the indicator is applied to a chart before/after the chart's session hours, the indicator's form/window will remain visible and available in all workspaces until a market data event arrives, regardless of the value of universalRTVisibility. Finally, in the worst case scenario, with universalRTVisibility set to false, you could be viewing a workspace that does not house your indicator when the market session for your indicator's chart ends. In such case, switching to the workspace that houses your indicator will not cause the indicator to turn visible because no market events will be arriving for the chart/instrument that houses your indicator. In such case, you can just reapply your indicator to get its form/window to show up again.

Most of the time, though, especially during regular session hours in reasonably "busy" markets, the form/window created by this indicator will appear and disappear fairly quickly as you switch from workspace to workspace, provided the universalRTVisibility flag is set to false. And again, if you set the universalRTVisibility flag to true, the form/window this indicator creates will remain visible and available in all open workspaces as you switch between them.

If anyone else can come up with a more elegant solution, that would be great. NinjaTrader.Gui.WorkspaceOptions does have a method, OnSwitchWorkspace(System.Object, System.EventArgs), that looks like it could be promising. But this method is both static and private. I have been unable to override this method for these reasons.

Hope this info helps anyone who has a similar problem to the one I had and/or anyone who may want to access workspace-related calls from within Ninjascript in NinjaTrader 7 for whatever reason.

Attached Files
Elite Membership required to download: ReconTickRecorder05_Solution.zip
Started this thread Reply With Quote
Thanked by:
  #9 (permalink)
 bmtrader333 
Greensboro, NC, USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: ES, NQ
Posts: 12 since Jan 2012
Thanks Given: 1
Thanks Received: 5

Now that I am allowed to post links, I thought I would add some info about the version of FxCop that I used.

First, I downloaded and installed Microsoft Windows SDK for Windows 7 and .NET Framework 3.5 SP1 from this webpage:

https://www.microsoft.com/en-us/download/details.aspx?id=3138

This SDK does not install FxCop, but it provides a link to do so: "Tools/Install Microsoft FXCop" once it is installed. (Locate this link under the "Microsoft Windows SDK v7.0" link in the Windows 7 Start menu once the SDK is installed.)

Clicking on the "Install Microsoft FXCop" link installs Microsoft FXCop v1.36 that generates its own Start menu link: "Microsoft FxCop" under Windows 7.

FxCop v1.36 is the tool I used to explore NinjaTrader 7's class-hierarchies/trees as described in my previous post.

Started this thread Reply With Quote
  #10 (permalink)
 bmtrader333 
Greensboro, NC, USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: ES, NQ
Posts: 12 since Jan 2012
Thanks Given: 1
Thanks Received: 5


Just to streamline things a bit for those who may be interested, here is a direct link to Gomi's most helpful post about how to use Microsoft FXCop:


Started this thread Reply With Quote




Last Updated on April 30, 2014


© 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