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!
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
NinjaTrader
Coding Help Needed
Collapse
X
-
Hi Jesse!
One of the indicators in NT7 uses a Color variable, say Color myVar, which then is used in item.ForeColor in ToolStripMenuItem(). For conversion to NT8, Color type becomes Brush type, so the varible becomes Brush myVar. But I can't use it in item.ForeColor anymore since the Media.Brush to Drawing.Color conversion error pops up. Any work-around is awaited.
Thanking
Mukaddim
Comment
-
Hello Mukaddim,
NT8 objects that are WPF elements should use "Brush" now instead of "Color" as we are using WPF. What specifically are you trying to convert, is it the ToolStripMenuItem? Have you used referenced and used Windows Forms controls in NT8 currently?
The menu system in NT8 uses MenuItem or NTMenuItem now which would use Styles instead of directly setting a Brush. As a general rule, if you are seeing an object take System.Drawing.Color in NT8, you have used the incorrect object. You will run into a lot of errors if you try to use windows forms elements in WPF as they are different frameworks.
You can find quite a few samples of toolbars and menu items here: https://ninjatrader.com/support/foru...327#post499327
When converting UI items from NT7 to NT8, it is best to leave all the code in NT7 and just redevelop this in NT8 due to the change in frameworks. NT7 used Windows Forms and NT8 uses WPF/XAML.
I look forward to being of further assistance.JesseNinjaTrader Customer Service
Comment
-
Hello Mukaddim,
What I am suggesting is that you do not carry over any of the NT7 toolbar syntax to NT8 and only keep your idea here.
You know of the toolbar concept in NT7 because you had used it, but because we use a new framework in NT8 that no longer has that toolbar you should only keep the idea that you want a toolbar in NT8 and get rid of the syntax you use now for NT7.
The samples I provided in the last post would be a good place to start re-learning how to use the Toolbar concept in NT8. Because we no longer use Windows Forms the ForeColor is only one part of the overall problems you will have with using this specific syntax in nt8.
NT8 exposes a lot of new controls in meaningful ways so you can access them easily. This was not present in NT7 so accessing items would often include a lot of looping or testing to find what you want. If you use the examples on the forum of existing concepts like adding button to the toolbar, you will see the better ways to access the UI controls in NT8 which prevent a lot of legwork.
I look forward to being of further assistance.JesseNinjaTrader Customer Service
Comment
-
Hi Jesse,
While working on the toolbar menu conversion, I was able to successfully convert the core of the indicator and it compiles fine, but the indicator doesn't show up in the list. So, I checked the LOG and found out that there's an error on calling the OnStateChange Method, stating that the Object Reference is not set to an instance of an Object. Have no clue what to do now. Please suggest.
Thanking
Mukaddim
Comment
-
Hello Mukaddim,
In this case, you know both the location "OnStateChange " and the error "Object Reference is not set to an instance of an Object."
If you search online for the general error message for C# it will give you some details but basically, this means an object you are using is null in OnStateChange.
So you will need to find what object you have used that is null. I would suggest to just add some Print() statements in OnStateChange in various locations to see where they stop, or put one print in OnStateChange to print the current state. Print(State);
Code:protected override void OnStateChange() { Print(State);
Code:if(ChartControl == null)
Code:Print("ChartControl is null? : " + (ChartControl == null));
I look forward to being of further assistance.JesseNinjaTrader Customer Service
Comment
-
Hello Mukaddim,
The Print(State); should be seen in the NinjaScript output window in addition to the error. Are you currently using the NinjaScript output window to further debug or are you watching the control center log tab?
You will still get the error while you add prints, the prints would simply help isolate what state the problem is in. My example of ChartControl will also not be specific to your script, I should have mentioned you need to replace "ChartControl" with whatever objects you are using.
If you cannot find the problem by using prints, you can also try commenting out your logic until you find the problem. Leaving just a shell of a script with all your logic commented out should allow the script to work in turn allowing you to slowly uncomment to find the problem.
I look forward to being of further assistance.JesseNinjaTrader Customer Service
Comment
-
Hello Mukaddim,
Before posting any code on this, have you tried to comment out your logic to further isolate where the problem is coming from? You will very likely run into this type of error frequently if you are dealing with the GUI items so this is something that is good to know how to debug yourself.
To further isolate the problem I would suggest to comment out the logic you use in OnStateChange and leave the script looking similar to a new empty script, how it just has the default properties and structure. This will also entail you comment out any logic that may require the OnStateChange logic such as logic in OnBarUpdate.
Once you comment down the script so it does nothing but no longer produces the error, you can uncomment just the OnStateChange logic one line at a time and check when you start getting the error. This will highlight the problem which will make it more apparent on how to fix it.
Very likely you are using an object such as ChartControl or some UI item that is null in one of the states where it is used. If you take a look at the examples I previously posted there are extensive null checks because the objects used are frequently null in the various states. State.Terminated is one of those places because the script is terminated a few extra times when you apply it which it does not have an associated ChartControl in those cases.
I look forward to being of further assistance.JesseNinjaTrader Customer Service
Comment
-
Hello Mukaddim,
Thank you for the reply.
Correct, you can pretty much apply that to any type to replace any custom NT7 series. Series<T> is a generic where T is the type of series you want such as string.
In regard to debugging, once you run through the script again if you are unable to find the problem please let me know and we could review the code together at that point. This is just one of those important processes for any GUI item you work on in NT8 so it is good practice to be able to find this error location in your code.
I look forward to being of further assistance.JesseNinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by geddyisodin, 04-25-2024, 05:20 AM
|
8 responses
61 views
0 likes
|
Last Post Yesterday, 10:45 AM | ||
Started by jxs_xrj, 01-12-2020, 09:49 AM
|
4 responses
3,288 views
1 like
|
Last Post
by jgualdronc
Today, 10:02 AM
|
||
Can someone turn this thinkscript into a ninjascript. 5PM CST OHL and Previous Day
by Option Whisperer
Started by Option Whisperer, Today, 09:55 AM
|
0 responses
5 views
0 likes
|
Last Post Today, 09:55 AM | ||
Started by halgo_boulder, 04-20-2024, 08:44 AM
|
2 responses
22 views
0 likes
|
Last Post Today, 09:41 AM | ||
Started by mishhh, 05-25-2010, 08:54 AM
|
19 responses
6,189 views
0 likes
|
Last Post
by rene69851
Today, 09:29 AM
|
Comment