NT8 send keys - futures io
futures io futures trading



NT8 send keys


Discussion in NinjaTrader

Updated by Mindset
      Top Posters
    1. looks_one b16aln with 5 posts (1 thanks)
    2. looks_two SamirOfSalem with 2 posts (2 thanks)
    3. looks_3 sam028 with 1 posts (1 thanks)
    4. looks_4 Mindset with 1 posts (0 thanks)
    1. trending_up 723 views
    2. thumb_up 4 thanks given
    3. group 5 followers
    1. forum 8 replies
    2. attach_file 0 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 100,000 members
  • 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 and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

NT8 send keys

(login for full post details)
  #1 (permalink)
London
 
Experience: None
Platform: ninjatrader
Trading: ftse100
 
Posts: 40 since Sep 2017
Thanks: 8 given, 9 received

Hi,

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

Reply With Quote

Can you help answer these questions
from other members on futures io?
3x Fangdango
Traders Hideout
SC parameter optimization
Sierra Chart
Do You Have A PlayBooks/What Form Does It Take?
Traders Hideout
FX Futures have been nagging me for a while
Currencies
Degiro Negative Balance Advice
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on futures io
Lost & losing hope
25 thanks
Finally Turning the Corner, tha "its 80% Psychology" thing...
21 thanks
Emini 4 Tick Scalp still valid?
18 thanks
VWAP for stock index futures trading?
17 thanks
Coronavirus COVID-19
13 thanks
 
(login for full post details)
  #2 (permalink)
Dubai + United Arab Emirates
 
 
Posts: 9 since Jan 2020
Thanks: 3 given, 5 received

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

I hope this helps.

Reply With Quote
The following user says Thank You to SamirOfSalem for this post:
 
(login for full post details)
  #3 (permalink)
London
 
Experience: None
Platform: ninjatrader
Trading: ftse100
 
Posts: 40 since Sep 2017
Thanks: 8 given, 9 received


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...

Reply With Quote
 
(login for full post details)
  #4 (permalink)
Dubai + United Arab Emirates
 
 
Posts: 9 since Jan 2020
Thanks: 3 given, 5 received


b16aln View Post
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".

https://ninjatrader.com/support/forum/forum/ninjatrader-8/indicator-development/96376-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.

Reply With Quote
The following user says Thank You to SamirOfSalem for this post:
 
(login for full post details)
  #5 (permalink)
London
 
Experience: None
Platform: ninjatrader
Trading: ftse100
 
Posts: 40 since Sep 2017
Thanks: 8 given, 9 received

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!

Reply With Quote
 
(login for full post details)
  #6 (permalink)
Site Moderator
 
 
sam028's Avatar
 
Posts: 3,639 since Jun 2009
Thanks: 3,768 given, 4,445 received


b16aln View Post
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!

You may check what NinjaTrader.Gui.Tools.TabControlCommands.DuplicateInTab.execute(param) is doing. It's not documented so may be tricky to use.

Success requires no deodorant! (Sun Tzu)
Follow me on Twitter Reply With Quote
The following user says Thank You to sam028 for this post:
 
(login for full post details)
  #7 (permalink)
London
 
Experience: None
Platform: ninjatrader
Trading: ftse100
 
Posts: 40 since Sep 2017
Thanks: 8 given, 9 received

Thanks Sam, I couldn't get that option to work.

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."

So i'm stuck again.....

The code currently looks like;

if(useAutoTabDuplicate==true)
{
useAutoTabDuplicate=false;

ChartControl.Dispatcher.InvokeAsync((Action)(() =>
{
ChartControl.OwnerChart.Focus();
Print(ChartPanel.IsFocused);
}));

System.Windows.Forms.SendKeys.SendWait("^z");
}

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.

Reply With Quote
 
(login for full post details)
  #8 (permalink)
London
 
Experience: None
Platform: ninjatrader
Trading: ftse100
 
Posts: 40 since Sep 2017
Thanks: 8 given, 9 received

In case anyone interested, this worked;
ChartControl.OwnerChart.OnDuplicateInNewTab();
Thanks for all your help guys, very helpful indeed!

Reply With Quote
The following user says Thank You to b16aln for this post:
 
(login for full post details)
  #9 (permalink)
Singapore
 
Experience: Intermediate
Platform: NT
Broker: ib
Trading: MES
 
Mindset's Avatar
 
Posts: 360 since Sep 2009
Thanks: 88 given, 287 received

 
Code
	[DllImport("user32.dll")]
    	public static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);
anyone know the equivalent in NT8?

I too am trying to sendKey but I just get an error message when I copy paste this code (missing namespace?)

Reply With Quote


futures io Trading Community Platforms and Indicators NinjaTrader > NT8 send keys


September 16, 2020


Upcoming Webinars and Events
     



Copyright © 2020 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts