sean.dbtrader Posted January 13, 2017 Report Share Posted January 13, 2017 I would like to know if I can use Macro Express to solve a problem. I use two different trading platforms. When I type a stock ticker (a string of no more than 4 characters) into a window in one of the platforms (the sending platform) I would like that same string to be entered into a window of the other platform (the receiving platform). Is there any way to do this using Macro Express? The sending platform has an external linking feature, but it does not work with the receiving platform I'm using. Quote Link to comment Share on other sites More sharing options...
Cory Posted January 13, 2017 Report Share Posted January 13, 2017 Probably. Different solutions and levels of difficulty depending on the type of application. EG WinForm, web browsers, or UWP. Quote Link to comment Share on other sites More sharing options...
rberq Posted January 13, 2017 Report Share Posted January 13, 2017 Here's a possibility: 1. Type the string into the first window, but DON'T hit ENTER or click on a button or whatever needs to be done next. 2. Hit a hot key to start a macro. 3. Macro types Shift-down / Left-arrow(s) / Shift-up sequence to highlight the string you just typed, and copies highlighted string to clipboard. Macro then types ENTER or clicks the mouse or whatever the window (sending platform) expects you to do. 4. Macro activates the second window (receiving platform), tabs or mouse clicks or whatever to the target field, types or pastes from the clipboard. Sounds feasible, maybe very easy, maybe less easy. As Cory said, difficulty depends on just what applications you are dealing with. Quote Link to comment Share on other sites More sharing options...
sean.dbtrader Posted January 13, 2017 Author Report Share Posted January 13, 2017 Both platforms are windows apps. Thanks for your input rberq, but that sounds like it will take too long. I need this process to be fast and automatic. I need the program to detect that the ticker has been changed in one window and automatically change it in the other window. Any other thoughts on how I can solve this problem? Quote Link to comment Share on other sites More sharing options...
rberq Posted January 14, 2017 Report Share Posted January 14, 2017 You want it "fast and automatic ..." It is automatic. How fast is fast? Quote Link to comment Share on other sites More sharing options...
sean.dbtrader Posted January 14, 2017 Author Report Share Posted January 14, 2017 No more than 1 second. Do you think that the macro would work that fast? Quote Link to comment Share on other sites More sharing options...
acantor Posted January 14, 2017 Report Share Posted January 14, 2017 It's possible, but the project could turn into a major scripting job. Automatically detecting a screen update might be trivially simple, horrifically complex, or impossible. You won't know which until you try. I can almost guarantee it's going to take significant amount of trial and error experimentation. A simpler approach might be to semi-automate the task. Instead of automatically detecting a screen event, start the process manually by pressing and releasing a hotkey, typing one or two characters, or clicking the mouse on part of the UI. Sounds like a fun project for someone who derives pleasure from writing macros (which is almost everybody on this forum!) Quote Link to comment Share on other sites More sharing options...
rberq Posted January 14, 2017 Report Share Posted January 14, 2017 No more than 1 second. Do you think that the macro would work that fast? Perhaps. Computers are pretty fast. For example, using Alt-Tab to switch from one Windows application to another is practically instantaneous -- a macro can type that key combination in a millisecond where it would take you way longer just to position your fingers. Clicking on a data entry field whose location is known, or even tabbing to it, can be extremely fast when a macro is doing it. Just need to try it on the actual PC and applications. Could you maybe post screen shots of the two applications, indicating the fields to be typed into? Do you by chance have a dual monitor setup, where both applications can be visible at the same time, one on each monitor? Quote Link to comment Share on other sites More sharing options...
sean.dbtrader Posted January 14, 2017 Author Report Share Posted January 14, 2017 Yes, I have a multi-monitor setup. However, for this particular solution both applications will be on the same monitor and visible. I would be happy to post screenshots, but I can't even log in to one of the platforms right now because the trading servers are offline over the weekend. I'll post screenshots early next week. I think the solution posted by rberq would work. I'm going to try creating a script using his steps, but this would be my first Macro Express script so any help would be greatly appreciated. Quote Link to comment Share on other sites More sharing options...
rberq Posted January 15, 2017 Report Share Posted January 15, 2017 Keep us posted on your progress. Quote Link to comment Share on other sites More sharing options...
Cory Posted January 15, 2017 Report Share Posted January 15, 2017 I don't have a lot of time but it sounds like you're typing the same thing in two places. In that case I'd prompt for the string then have the macro enter the values into the text box controls in each window. Using the controls commands in MEP means one doesn't even have to activate the windows. In fact they could be visible. There's a tutorial on using control commands using Notepad made available by ISS. It's either in the samples with the install or on the support website. As far as speed, once the user enters the string, it would be effectively instant. Quote Link to comment Share on other sites More sharing options...
acantor Posted January 15, 2017 Report Share Posted January 15, 2017 I was also thinking that an elegant and reliable solution might be possible using controls. Learning to deal with Windows controls is not particularly easy; I have been using Macro Express since 1999 (perhaps earlier), and I am still figuring out how to automate tasks via controls. The tutorial that Cory referred to you is a good introduction. I have found that when capturing a control that appears in a window that has a changing title, choose the option to "save the control using its coordinates." Quote Link to comment Share on other sites More sharing options...
sean.dbtrader Posted January 16, 2017 Author Report Share Posted January 16, 2017 OK, I've run into my first problem. At this point I'm just trying to create a macro to activate the window and type some text to change the ticker (e.g. GOOG). I was able to get this to work with Notepad, but it doesn't work with the trading platform I'm using, TradeStation. If I manually activate the window, type the text "GOOG" and press enter it changes the chart symbol to GOOG. However, the macro does not change the chart symbol. I can see it activate the window but the text never goes through. I've attached a screenshot of the simple script. Quote Link to comment Share on other sites More sharing options...
sean.dbtrader Posted January 16, 2017 Author Report Share Posted January 16, 2017 I also tried using the Get Control command. Again, this works with Notepad. But if I try to set this up with TradeStation I get an error "You must first select a control. Please correct". It is like it does not consider the TradeStation child window I selected to be a control. I've attached a screenshot of this error. Quote Link to comment Share on other sites More sharing options...
Cory Posted January 16, 2017 Report Share Posted January 16, 2017 When you hover over the controls are they being detected? Try using another WinForm application to see what I mean. I'm not sure if your program is using MDI or what. There was no mention of child windows before. But app windows are usually easy enough to do as long as they don't have the same window title. Be aware that new "Modern", or "Metro" Windows apps are a problem for MEP. They're UWP. Make sure this is not the case. I don't agree that the Windows Control are more difficult. I think they'er really simple and they make the macros much more reliable and simpler. Quote Link to comment Share on other sites More sharing options...
sean.dbtrader Posted January 16, 2017 Author Report Share Posted January 16, 2017 I figured out the issue with the activation. TradeStation is running as an administrator so I needed to run Macro Express as administrator also. Now the simple activation and text type script works. I found some old posts on the forum about TradeStation that were helpful. Quote Link to comment Share on other sites More sharing options...
rberq Posted January 16, 2017 Report Share Posted January 16, 2017 I figured out the issue with the activation. Good. How about for the second application? Quote Link to comment Share on other sites More sharing options...
sean.dbtrader Posted January 16, 2017 Author Report Share Posted January 16, 2017 I have the full macro working, except it is not consistent. There seem to be 2 problems. Problem 1: The first command is Text Type: <SHIFTD><HOME><SHIFTU> to highlight the ticker that I just typed and then I do a clipboard copy. This works the first time and maybe the second and third time I run the macro, but after a few runs it seems to stop working. I put in a delay of 2 seconds so I can see what is happening. When it stops working the text is not highlighted but the cursor goes to the start. So the <HOME> command still runs, but it is like the SHIFT key is not being pressed. What could cause the macro to start behaving differently? Problem 2: The TradeStation behavior is also inconsistent. I'm calling Window Activate, then Type Clipboard Text, then Text Type: <ENTER> and then Wait for Text Playback. In some cases this works and at other times it seems the platform was activated but the text did not go through. I'm wondering if this might be a timing issue and I need to delay just a little bit after activating the window. Quote Link to comment Share on other sites More sharing options...
sean.dbtrader Posted January 16, 2017 Author Report Share Posted January 16, 2017 I think I just solved Problem 1. Instead of using Text Type and clipboard copy I switched to Capture Control from Focused Control and then Get Control Text from that control. It seems to work much better that way. Quote Link to comment Share on other sites More sharing options...
sean.dbtrader Posted January 16, 2017 Author Report Share Posted January 16, 2017 Success! I solved problem 2 by also using controls. Here is the final script that seems to work very well: Quote Link to comment Share on other sites More sharing options...
sean.dbtrader Posted January 16, 2017 Author Report Share Posted January 16, 2017 Is it possible to check the coordinates of a Control that I've captured? Once I've captured the Focused Control. I would like to have the macro behave differently if the control is in a different position. (e.g. I may have multiple Lightspeed windows open and I want to link each of those windows to there own TradeStation window). Quote Link to comment Share on other sites More sharing options...
rberq Posted January 17, 2017 Report Share Posted January 17, 2017 Congratulations! Cory and Alan were right about using controls instead of my primitive copy-to-clipboard method. I bet it's fast enough, too. Quote Link to comment Share on other sites More sharing options...
acantor Posted January 17, 2017 Report Share Posted January 17, 2017 Congratulations. Your script looks good! And it doesn't seem to need delays to make it run reliably. (Although in the fullness of time, you may discover the script will benefit from time "shims" to maximize reliability.) I can almost guarantee it's going to take significant amount of trial and error experimentation. Told you so! Quote Link to comment Share on other sites More sharing options...
Cory Posted January 17, 2017 Report Share Posted January 17, 2017 If you decide on inserting delays consider making them a variable (technically a constant). This way you can change them all at once. There's no time being used with controls like there is in TextType. Also using the clipboard takes time. In my experience switching to control commands usually eliminate timing issues. I don't like your control command to capture at a coordinate. It's likely to cause you troubles in the future. I'd change that to a Get Control ASAP. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.