Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
I'm looking to implement use of send keys in my script to automatically do a one off duplicate in new tab when an event occurs. So i will be using send keys method to submit my "dupicate in new tab" hot key;
if(event logic)
{
event logic=false // to stop unlimited duplications
System.Windows.Forms.Sendkeys.SendWait(insert duplicate in new tab hotkey e.g ctrl + a, "^a");
}
I'm getting some unexpected action in that the first instance of the method getting actioned, it opens the search function on the chart as if the letter (a) part of the hitkey only has been pressed rather than ctrl+a.
I believe that I need to ensure the current tab is the active tab first then run the send keys method. My forum search here found a similar post, where someone used the following code in NT7:
// Make sure chart window is active.
ChartControl.ParentForm.Activate();
However this method is not avaialble in NT8, can anyone help with an equivalent NT8 code to use to ensure the chart window is active before running the send keys method?
If anyone knows of some other cause of the unexpected action resulting in the search getting activated on sending the hotkey, please let me know.
Many thanks
Can you help answer these questions from other members on NexusFi?
Have you tried the ChartPanel class?
It has an .IsFocused method that might help.
It may be a good idea to loop through a collection of open windows before triggering the sendkey, just to make sure you're dealing with the correct window
Thanks for the suggestion Samir. I tried the IsFocused and receive an error: The calling thread cannot access this object because a different thread owns it. Do you know how to overcome this?
Edit: Solved, It needs to go within a dispatcher, this is all new to me but i'm trying to work it out...
Good to hear. There are some interesting threads on the NinjaTrader forum for this kind of thing, but sendkeys per se is not supported. One example is in the link below by Ninja's very helpful Chelsea. If the link doesn't show, just do a search on the forum for "Modifications to chart WPF elements and tab considerations".
I'm not sure if it was in this particular thread, but I remember once reading a discussion where it was realized that a custom toolbar was appearing on only one tab of an open chart window. It was a dispatcher issue if I recall. The NT team then revised the code so that it checks which tabs/windows are open and/or have focus.
Thanks, I'll look into it all. This stuff is really pushing my coding abilities (beginner) but I'll keep plugging away at it to try and get to where I want it to be. Getting some pretty funky outcomes at the moment and one major system crash this morning but I'll keep trying...and backing up as I go!
I'm getting there, the Focus method appears to be working and I am then checking it by printing the IsFocused bool output, e.g when IsFocused is true I am treating that as confimation that the correct chart is in selected.
When I then fire off the send keys I get the following error;
"Error on calling 'OnBarUpdate' method on bar 10983: Source array was not long enough. Check srcIndex and length, and the array's lower bounds."
The autoTabDuplicate is just a bool switch so that I don't get an infinite loop of charts being duplicated.
Can anyone help me get passed the error?
EDIT: Ok realised I was mixing ChartControl with ChartPanel. When I use ChartControl.IsFocused it returns false so the ChartControl.OwnerChart.Focus() doesn;t appear to be working.