NexusFi: Find Your Edge


Home Menu

 





NT8 send keys


Discussion in NinjaTrader

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




 
Search this Thread

NT8 send keys

  #1 (permalink)
 b16aln 
London
 
Experience: None
Platform: ninjatrader
Trading: ftse100
Posts: 67 since Sep 2017
Thanks Given: 11
Thanks Received: 23

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

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
ZombieSqueeze
Platforms and Indicators
NexusFi Journal Challenge - May 2024
Feedback and Announcements
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Better Renko Gaps
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
38 thanks
Just another trading journal: PA, Wyckoff & Trends
30 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
23 thanks
GFIs1 1 DAX trade per day journal
21 thanks
  #2 (permalink)
 SamirOfSalem   is a Vendor
 
Posts: 74 since Jan 2020
Thanks Given: 23
Thanks Received: 44

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
Thanked by:
  #3 (permalink)
 b16aln 
London
 
Experience: None
Platform: ninjatrader
Trading: ftse100
Posts: 67 since Sep 2017
Thanks Given: 11
Thanks Received: 23


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

Started this thread Reply With Quote
  #4 (permalink)
 SamirOfSalem   is a Vendor
 
Posts: 74 since Jan 2020
Thanks Given: 23
Thanks Received: 44


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://[AUTOLINK]ninjatrader[/AUTOLINK].com/support/forum/forum/[AUTOLINK]ninjatrader[/AUTOLINK]-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
Thanked by:
  #5 (permalink)
 b16aln 
London
 
Experience: None
Platform: ninjatrader
Trading: ftse100
Posts: 67 since Sep 2017
Thanks Given: 11
Thanks Received: 23

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!

Started this thread Reply With Quote
  #6 (permalink)
 
sam028's Avatar
 sam028 
Site Moderator
 
Posts: 3,765 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,629


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
Thanked by:
  #7 (permalink)
 b16aln 
London
 
Experience: None
Platform: ninjatrader
Trading: ftse100
Posts: 67 since Sep 2017
Thanks Given: 11
Thanks Received: 23

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.

Started this thread Reply With Quote
  #8 (permalink)
 b16aln 
London
 
Experience: None
Platform: ninjatrader
Trading: ftse100
Posts: 67 since Sep 2017
Thanks Given: 11
Thanks Received: 23

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

Started this thread Reply With Quote
Thanked by:
  #9 (permalink)
 
Mindset's Avatar
 Mindset 
Singapore
 
Experience: Intermediate
Platform: NT
Broker: ib
Trading: MES
Posts: 365 since Sep 2009
Thanks Given: 90
Thanks Received: 291

 
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




Last Updated on September 16, 2020


© 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