NoizeBit Posted July 8, 2015 Share Posted July 8, 2015 (edited) Hi,I'd like to ask for your help with an issue I've encountered when writing a MetaTrader automation script.Basically, it changes the GMT Offset parameter within an indicator's configuration window.The problem is that when it enters the variable to the correct place it also changes another parameter which is right under the currently edited field(...) Maybe because of that the rest of the commands after Send($sNewOffset) are never executed. I've tried delaying keystrokes, inserted sleeps to no avail.I've just started learning AutoIt a few days ago so there's a good chance I'm missing something important.#include <Date.au3> Local $sNewOffset CalcOffset() Func CalcOffset() $Arr = _Date_Time_GetTimeZoneInformation() ;Get current Time Zone information If $Arr[0] == 2 Then ConsoleWrite("Daylight Saving") $sNewOffset = "2.0" ;Set LocalGMTZone for Daylight Saving (DST on - UTC+02:00) Else ConsoleWrite("Normal Time") $sNewOffset = "1.0" ;Set LocalGMTZone for Normal Time (DST off - UTC+01:00) EndIf EndFunc ;==>CalcOffset WinActivate("MetaTrader") ;Change GMT Offset on first chart Send("!w") ;ALT+W / MT4 window selector Send("!a") ;ALT+A / Activate selected window Send("^i") ;CTRL+I / Indicators List Send("{TAB 2}") ;Press TAB 2 times to highlight Main Chart Send("{DOWN}") ;Press cursor DOWN to highlight selected ndicator Send("!e") ;ALT+E / Edit selected indicator Send("{END}") ;Go to the bottom of the list Send("{UP}") ;Go up one item to highlight LocalGMTZone parameter Send("{F2}") ;Edit selected parameter Send($sNewOffset) ;Enter previously calculated GMT offset value Send("{TAB}") ;Press TAB to highlight OK Send("{ENTER}") ;Press ENTER to simulate clicking on OK Send("{TAB 3}") ;Press TAB 3 times to highlight Close Send("{ENTER}") ;Press ENTER to simulate clicking on Close Edited July 8, 2015 by NoizeBit Link to comment Share on other sites More sharing options...
Jfish Posted July 9, 2015 Share Posted July 9, 2015 It would probably help if you told us what "MetaTrader" is and provided a screen shot. Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt Link to comment Share on other sites More sharing options...
jvds Posted July 9, 2015 Share Posted July 9, 2015 'Send("{DOWN}") ;Press cursor DOWN to highlight selected ndicator'which indicator are you selecting there to edit? Link to comment Share on other sites More sharing options...
NoizeBit Posted July 9, 2015 Author Share Posted July 9, 2015 (edited) MetaTrader is a trading platform offering both manual and automated trading on the Forex market. I've attached a screenshot, too.The indicator I'm trying to edit is a commercial one named Binary Brain Wave, but all indicators are edited the exact same way. Edited July 9, 2015 by NoizeBit Link to comment Share on other sites More sharing options...
Jfish Posted July 9, 2015 Share Posted July 9, 2015 I don't actually see a window called "MetaTrader" as in:WinActivate("MetaTrader")Semi-related: it may be that when you useSend($sNewOffset)you may be losing focus on the window so the rest of the commands don't work. You could try two things: (i) after that send you could winactivate with the title you need to regain focus (assuming that is what is wrong - which it may not be - just a guess - this would be easy to try - you may even see it happen when the script is running) and / or (ii) you could use Au3Info to get more information about the specific control you are trying to set and then use ControlSend or ControlCommand to set it - which target the control instead of sending more generic keystrokes (is the control for $sNewOffset a text field, drop down, ... what is it - can you show that specifically?). NoizeBit 1 Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt Link to comment Share on other sites More sharing options...
NoizeBit Posted July 9, 2015 Author Share Posted July 9, 2015 (edited) I don't actually see a window called "MetaTrader" as in:WinActivate("MetaTrader")Semi-related: it may be that when you useSend($sNewOffset)you may be losing focus on the window so the rest of the commands don't work. You could try two things: (i) after that send you could winactivate with the title you need to regain focus (assuming that is what is wrong - which it may not be - just a guess - this would be easy to try - you may even see it happen when the script is running) and / or (ii) you could use Au3Info to get more information about the specific control you are trying to set and then use ControlSend or ControlCommand to set it - which target the control instead of sending more generic keystrokes (is the control for $sNewOffset a text field, drop down, ... what is it - can you show that specifically?).You're right, it should be:WinActivate("8819: FXFS-Main Server")That seems like the issue, because the entering of the value is happening inside another window. Thanks for the advice, I'll try both ways to see if any of them solves this problem and get back with the results.$sNewOffset will be entered into a simple text field: Edited July 9, 2015 by NoizeBit Link to comment Share on other sites More sharing options...
jvds Posted July 9, 2015 Share Posted July 9, 2015 if you apply the indicators to your chart, and edit them until all good, isn't it easier to just save the template as the default template and then it will auto load with same settings every time you open a new chart? Link to comment Share on other sites More sharing options...
NoizeBit Posted July 9, 2015 Author Share Posted July 9, 2015 if you apply the indicators to your chart, and edit them until all good, isn't it easier to just save the template as the default template and then it will auto load with same settings every time you open a new chart?Unfortunately it's not, because that parameter needs to be edited only when Daylight Savings ends and starts again. Although you have a point with the template. It'd be much easier to save two templates and just overwrite the default when necessary by copying the file. Link to comment Share on other sites More sharing options...
jvds Posted July 10, 2015 Share Posted July 10, 2015 Your method is the easiest, if you need to do it without window focus you will need to go with window managementI was wondering if I can use _GUICtrlTreeView, _GUICtrlListView, _GUICtrlTab to manipulate another GUI outside a script, never done it, so i decided to try it out on metatrader, I could not make the script work without the need of window focus, but almost got it, only Send("!w") and Send("^i") is used, and for that you need windows focus, but there is probably a way around thouse also, the rest of the script does not need windows focus, btw i think you can do all this also with just using ControlSend Controlclick and the none UDF's control functions listed under windows management in the help file, but i was in a mood for experimenting with other stuff, and i need to improve my gui skills =Pexpandcollapse popup#include <GuiListView.au3> #include <GuiTreeView.au3> #include <GuiTab.au3> WinActivate("sdfsdf- Server") ;make sure to write your platform window name, use Autoit Window Info tool ;## could not bypass this one, for this part the window of Metatrader neetd to be active Send("!w") ;ALT+W / MT4 window selector ;here the chart windows is selected, not by name but by index winwait("Windows") $Win1 = WinGetHandle("Windows") ConsoleWrite("$Win1="&$Win1&@lf) $Ctl1 = ControlGetHandle ($Win1,"",'SysListView321') ConsoleWrite("$Ctl1="&$Ctl1&@lf) _GUICtrlListView_SetHotItem ( $Ctl1, 0 );select first item ;~ _GUICtrlListView_SetHotItem ( $Ctl1, 1 )select second item ;~ _GUICtrlListView_ClickItem($Ctl1, 0, "left", False, 1) ;click first item ;~ _GUICtrlListView_ClickItem($Ctl1, 1, "left", False, 1) ;click second item ControlClick($Win1,"",'[CLASS:Button; INSTANCE:1]','left',1) sleep(100) ; probably not necessary ;## I could not bypass this one, for this window of trader need to be active Send("^i") ;CTRL+I / Indicators List ;here you select the indicator you want to edit "Indicators on " is the short name, you can use complete name but it changes with the chart window name winwait("Indicators on ") ;wait for window $Win2 = WinGetHandle("Indicators on ") ;get window handle ConsoleWrite("$Win2="&$Win2&@lf) $Ctl2 = ControlGetHandle ($Win2,"",'SysTreeView321') ;get treeview inside $Win2 handle ConsoleWrite("$Ctl2="&$Ctl2&@lf) $treeHandle = _GUICtrlTreeView_FindItem($Ctl2, "Custom Moving Averages",False) ;get treeview item handle by name -->> replace 'Custom Moving Averages' with indicator complete name _GUICtrlTreeView_SelectItem($Ctl2, $treeHandle,$TVGN_CARET) ;select the item by its handle --->> this will not use the mouse also does not need window focus =D ;_GUICtrlTreeView_ClickItem($Ctl2,$treeHandle,'left',False,1,0) ;this will work, same as above but window need to be visible with the tests ive done ConsoleWrite("$treeHandle="&$treeHandle&@lf) ControlClick($Win2,"",'[CLASS:Button; INSTANCE:2]','left',1);click the edit button ;select the indicators tab you want to edit winwait("Custom Indicator -") $win3 = WinGetHandle("Custom Indicator -") ;'Custom Indicator -' is only part of the name, use full window name, to be more precise ConsoleWrite("$win3="&$win3&@lf) $Ctl3 = ControlGetHandle ($win3,"",'SysTabControl321') ;here you can direcly click the idex 2 for third tab or find the tab's index by searching the tab name with _GUICtrlTab_FindTab then click on the index it returns $tabindex = _GUICtrlTab_FindTab($Ctl3,'Inputs',False) _GUICtrlTab_ClickTab($Ctl3, $tabindex, "left", False, 1) ;click tab, it seems it works even if window is not focused ConsoleWrite("$tabindex="&$tabindex&@lf) ;this part is not working, i'm getting the handle of listview, but i did't try anything else, the way to go probably is select by listview index $Ctl3b = ControlGetHandle ($win3,"",'SysListView321') ConsoleWrite("$Ctl3b="&$Ctl3b&@lf) ;$listviewitem = _GUICtrlListView_FindInText ( $Ctl3b, '0') $listviewitem = _GUICtrlListView_FindText ( $Ctl3b, 'Shift' ) ConsoleWrite("$listviewitem="&$listviewitem&@lf)i did add custom moving average to my chart to test the script, so make sure you change the name or add the indicator if you test, also there are a lot of consolwrite that return the handles, if the handle return 0 or 0x0000 then it means it didn't get the handle of window or of control, use the autoit window info tool to make sure you use the correct names in the windows, I use and tested script with metatrader 4 Link to comment Share on other sites More sharing options...
NoizeBit Posted July 10, 2015 Author Share Posted July 10, 2015 Nice work you did there. To be honest with you I'm aiming to keep this one as simple as possible, it doesn't need to be sophisticated Another interesting thing: what if the Window Info tool shows no control class or instance for the window where the script should send ControlSend or ControlClick? How do you tell it to click on "OK" or send an Enter with ControlSend in such case? Link to comment Share on other sites More sharing options...
Jfish Posted July 10, 2015 Share Posted July 10, 2015 Nice work you did there. To be honest with you I'm aiming to keep this one as simple as possible, it doesn't need to be sophisticated Another interesting thing: what if the Window Info tool shows no control class or instance for the window where the script should send ControlSend or ControlClick? How do you tell it to click on "OK" or send an Enter with ControlSend in such case?If you can't see the input field information that you are trying to control I would suggest looking here: https://www.autoitscript.com/forum/topic/153520-iuiautomation-ms-framework-automate-chrome-ff-ie/ Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt Link to comment Share on other sites More sharing options...
NoizeBit Posted July 10, 2015 Author Share Posted July 10, 2015 If you can't see the input field information that you are trying to control I would suggest looking here: https://www.autoitscript.com/forum/topic/153520-iuiautomation-ms-framework-automate-chrome-ff-ie/ Thanks, will definitely give it a try. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now