NexusFi: Find Your Edge


Home Menu

 





AutoHotkey Scripts


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one monpere with 23 posts (98 thanks)
    2. looks_two traderap101 with 13 posts (12 thanks)
    3. looks_3 trendisyourfriend with 12 posts (0 thanks)
    4. looks_4 perryg with 6 posts (2 thanks)
      Best Posters
    1. looks_one monpere with 4.3 thanks per post
    2. looks_two traderap101 with 0.9 thanks per post
    3. looks_3 SilverFut with 0.7 thanks per post
    4. looks_4 perryg with 0.3 thanks per post
    1. trending_up 36,267 views
    2. thumb_up 115 thanks given
    3. group 35 followers
    1. forum 64 posts
    2. attach_file 10 attachments




 
Search this Thread

AutoHotkey Scripts

  #51 (permalink)
traderap101
London UK
 
Posts: 18 since Jul 2022
Thanks Given: 3
Thanks Received: 16

Can you post an image of your equivalent Control Center window. I am curious as to why your Tools menu co-ordinates on Control Center are different to my version of NT8.

To identify co-ordinate positions on a Window, run the program AutoHotkey Window Spy found in the AutoHotkey installation

"C:\Program Files\AutoHotkey\WindowSpy.ahk"

This should also be listed under Windows Start menu for AutoHotkey

Hover your mouse over the Nt8 Control Center to find the co-ordinates of the Tools menu.

However rather than go down this path, if others also encounter similar issues because of layout changes between different versions of NT8, I can change the script to work on an open Historical Data window which the user has to manually open before running the script.

Attached Thumbnails
Click image for larger version

Name:	Screenshot 2023-06-10 202036.png
Views:	35
Size:	35.4 KB
ID:	332705  
Reply With Quote

Can you help answer these questions
from other members on NexusFi?
REcommedations for programming help
Sierra Chart
ZombieSqueeze
Platforms and Indicators
Trade idea based off three indicators.
Traders Hideout
MC PL editor upgrade
MultiCharts
Better Renko Gaps
The Elite Circle
 
  #52 (permalink)
 
trendisyourfriend's Avatar
 trendisyourfriend 
Quebec Canada
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG
Trading: ES, NQ, YM
Frequency: Daily
Duration: Minutes
Posts: 4,527 since Oct 2009
Thanks Given: 4,176
Thanks Received: 6,020


traderap101 View Post
Can you post an image of your equivalent Control Center window. I am curious as to why your Tools menu co-ordinates on Control Center are different to my version of NT8.
.


Reply With Quote
  #53 (permalink)
traderap101
London UK
 
Posts: 18 since Jul 2022
Thanks Given: 3
Thanks Received: 16



trendisyourfriend View Post

Ok, run the WindowSpy program, select the Control Center window so it is Active in Windows, hover your mouse over the centre of the Tools section and tell me what co-ordinates you get in the "Mouse Position" section under "Window"
"

Reply With Quote
  #54 (permalink)
 
trendisyourfriend's Avatar
 trendisyourfriend 
Quebec Canada
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG
Trading: ES, NQ, YM
Frequency: Daily
Duration: Minutes
Posts: 4,527 since Oct 2009
Thanks Given: 4,176
Thanks Received: 6,020


traderap101 View Post
Ok, run the WindowSpy program, select the Control Center window so it is Active in Windows, hover your mouse over the centre of the Tools section and tell me what co-ordinates you get in the "Mouse Position" section under "Window"
"

333,12 between the two letters 'o' of Tools

The other mouse click for 'Get Market Replay Data' :

/* Select Instrument Field */
MouseClick("Left", 30, 625)

Mine is at 18, 629

Reply With Quote
  #55 (permalink)
traderap101
London UK
 
Posts: 18 since Jul 2022
Thanks Given: 3
Thanks Received: 16

OK, it looks like there are subtle changes in the window layout between different versions of NinjaTrader. The following variables are the positions the script uses for mouse clicks and download button status. These will need to be checked for their co-ordinate positions for a users NT8 version if it's not V8.1.1.1.

These can be found through AutoHotkey Window Spy C:\Program Files\AutoHotkey\WindowSpy.ahk and then the code will need to be changed.

 
Code
/* Tools Menu on Control Center */
XTools := 250
YTools := 10

/* Rotating triangle on Historial Data for Get Market Replay data */
XRotatingTriangle := 35
YRotatingTriangle := 630

/* Instrument field on Historical Data window */
XInstrument := 30
YInstrument := 625

/* Download button */
XDownloadButton := 645
YDownloadButton := 610
I will have a think about whether there is an alternative way to find these positions programmatically for the next version.

Thanks.

Reply With Quote
Thanked by:
  #56 (permalink)
 
trendisyourfriend's Avatar
 trendisyourfriend 
Quebec Canada
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG
Trading: ES, NQ, YM
Frequency: Daily
Duration: Minutes
Posts: 4,527 since Oct 2009
Thanks Given: 4,176
Thanks Received: 6,020


traderap101 View Post
OK, it looks like there are subtle changes in the window layout between different versions of NinjaTrader. The following 3 code fragments are the different mouse clicks in the script. These will need to be checked for their co-ordinate positions for a users installation. Once these have been found through Window Spy, then the code will need to be changed.
.

The script works perfectly now with these settings:
I needed to modify three mouseclick coordinates and another one for the BG color of the download button.

 
Code
    MyDebug("Message", "Found Control Center window")

    WinActivate
    Sleep SleepBetweenActions / 2

    /* Click Tools menu item */
    MouseClick("Left", 333, 12)

---

    if (WinWait(HistoricalData, , 5)) {
        MyDebug("Message", "Opened " HistoricalData " window")
        WinActivate

        /* Expand the rotating triangle for Get Market Replay data */
        MouseClick("Left", 35, 630)
        Sleep SleepBetweenActions

---

                if (WinExist(HistoricalData)) {
                    WinActivate

                    ; Skip weekend days based on user configuration
                    if ((SkipSaturday and !StrCompare(FormatTime(ProcessDate, "WDAY"), "7")) or (SkipSunday and !StrCompare(FormatTime(ProcessDate, "WDAY"), "1"))) {
                        MyDebug("Skipping", Instrument " for date " FormatTime(ProcessDate, "ShortDate") " as it is a weekend skip date")
                        ProcessDate := DateAdd(ProcessDate, 1, "Days")
                        continue
                    }

                    MyDebug("Processing", Instrument " for date " FormatTime(ProcessDate, "ShortDate") "")

                    /* Select Instrument Field */
                    MouseClick("Left", 68, 624)

---

                    /* Get colour of a download button pixel before presssing enter as this pixel color will be checked to see if download has finished */
                    BeforeColor := PixelGetColor(817, 659)

Reply With Quote
  #57 (permalink)
 
trendisyourfriend's Avatar
 trendisyourfriend 
Quebec Canada
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG
Trading: ES, NQ, YM
Frequency: Daily
Duration: Minutes
Posts: 4,527 since Oct 2009
Thanks Given: 4,176
Thanks Received: 6,020

Do you think you could adapt your script to download historical datas ?

Ideally, here is what i would need:

Given a defined list of instruments, i need to download data from a specific date in the past to now using a 1 minute chart.

Then, once the minute data have been downloaded, we repeat the process but this time using a 500 tick chart.

Reply With Quote
  #58 (permalink)
 
trendisyourfriend's Avatar
 trendisyourfriend 
Quebec Canada
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG
Trading: ES, NQ, YM
Frequency: Daily
Duration: Minutes
Posts: 4,527 since Oct 2009
Thanks Given: 4,176
Thanks Received: 6,020

I tried to run your script to download 2 days and for 3 instruments. It just processes 1 instrument, the 1st in the list and for 1 day. After that, i see no activity going on and if i try to bring another window in front, the script brings the historical data window in front but still nothing happens. I need to close the historicacl data window to force the script to generate an error and stop.

Reply With Quote
  #59 (permalink)
 
trendisyourfriend's Avatar
 trendisyourfriend 
Quebec Canada
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG
Trading: ES, NQ, YM
Frequency: Daily
Duration: Minutes
Posts: 4,527 since Oct 2009
Thanks Given: 4,176
Thanks Received: 6,020


trendisyourfriend View Post
I tried to run your script to download 2 days and for 3 instruments. It just processes 1 instrument, the 1st in the list and for 1 day. After that, i see no activity going on and if i try to bring another window in front, the script brings the historical data window in front but still nothing happens. I need to close the historicacl data window to force the script to generate an error and stop.

I found the problem thid morning with fresh eyes.

I needed to update this line:

Reply With Quote
  #60 (permalink)
traderap101
London UK
 
Posts: 18 since Jul 2022
Thanks Given: 3
Thanks Received: 16


V1.2 Market Replay Download for Multi-Instrument and Multi-Date

Here is V1.2 of the code. The main changes in this version are:
  1. Resizes the Historical Data window to a predefined size during the script execution so that fields are in known positions during execution. Reverts back to original size after script execution.

  2. XTools variable added so that script can handle x-axis variation of the Tools menu position in the Control Center window between NinjaTrader 8.0.28.0 and NinjaTrader 8.1.1.1. For NinjaTrader 8.0.28.0 change the script as follows
    XTools := 300
  3. Adds an option to see a progress window with status bar whilst the download is happening. This is just a visual and has no bearing on the script itself. To turn it off
    ShowStatusWindow := false

User Parameters
The most likely parameters that a user may need to modify are the following:

/* Comma separated instrument list to download. Make sure you type in the correct name without any extraneous spaces or characters. */
InstrumentList := "MNQ 09-23,MES 09-23"

/* Starting date to process in YYYYMMDD format */
StartDate := 20230605

/* Number of days to download */
NumberofDaysToDownload := 2

/* Skip Days */
SkipSaturday := true
SkipSunday := false

/* Download progress status window toggle */
ShowProgressWindow := true

/* Number of millseconds to wait between keystroke/mouse actions on windows */
SleepBetweenActions := 400

Usage
If you need to abort the script then close the Historical Data window. Do NOT bring any other window into active focus whilst it is running as the script might accidentally send mouse clicks / keystrokes into the wrong window.

 
Code
/*

Written by Trader AP
Use at your own risk

V1.0 - 10 June 2023 - Original Version
V1.1 - 10 June 2023 - Amended to resize Historical Window to specific size/position in order to
                      mouseclick and detect download button in the right position
V1.2 - 12 June 2023 - Added a Status Window to see progress of script.  Tested on NT 8.0.28.0 64-bit which requires slightly different parameters for XTools = 300

*/

#SingleInstance Force

/* Comma separated instrument list to download.  Make sure you type in the correct name without any extraneous spaces or characters. */
InstrumentList := "MNQ 09-23,MES 09-23"

/* Starting date to process in YYYYMMDD format */
StartDate := 20230605

/* Number of days to download */
NumberofDaysToDownload := 2

/* Skip Days */
SkipSaturday := true
SkipSunday := false

/* Download progress status window toggle */
ShowProgressWindow := true

/* Number of millseconds to wait between keystroke/mouse actions on windows */
SleepBetweenActions := 400

/* Today's date in YYYYMMDD format */
TodaysDate := A_YYYY A_MM A_DD

/* Window Title Names */
HistDataWindow := "Historical Data"
DownloadWindow := "Download Progress"

/* Size of Download progress window */
DownloadWindowSize := "W400 H30 cgreen vMyProgress"

/* The following are window x & y positions needed for mouse clicks and keystrokes */
/* Use C:\Program Files\AutoHotkey\WindowSpy.ahk (AutoHotkey Window Spy) */
/* to identify these positions if script does not work */

/* Position of Tools menu on Control Center window */
/* Change XTools to 300 for Ninja Trader 8.0.28.0 */
XTools := 250
YTools := 10

/* Position of rotating triangle for Get Market Replay data in Historical Data window */
XRotatingTriangle := 35
YRotatingTriangle := 630

/* Position of Instrument field in Historical Data window */
XInstrument := 30
YInstrument := 625

/* Position of download button in Historical Data window */
XDownloadButton := 645
YDownloadButton := 610

/* Resize Historical Data window to the following whilst processing mouse clicks and getting button status */
XFixedSizeHDWindow := 1
YFixedSizeHDWindow := 1
WFixedSizeHDWindow := 750
HFixedSizeHDWindow := 650

/* Function for formatted debug & status bar messages */
MyDebug(MessagePrefix, Message, ShowMessageBox := false, ShowStatusOnBar := false)
{
    if (ShowProgressWindow && ShowStatusOnBar && WinExist(DownloadWindow)) {
        MyProgressStatusBar.SetText(FormatTime(A_Now, "ShortDate") " " A_Hour ":" A_Min ":" A_Sec " " Format("{1:-12}", MessagePrefix ": ") Message)
    }

    OutputDebug FormatTime(A_Now, "ShortDate") " " A_Hour ":" A_Min ":" A_Sec " " Format("{1:-12}", MessagePrefix ": ") Message "`n"

    if ShowMessageBox {
        MsgBox(Message, MessagePrefix, MessagePrefix == "Error" ? "Icon!" : "Iconi")
    }
}

/* A few defensive checks on user parameters */
if (StrLen(InstrumentList) = 0) {
    MyDebug("Error", "Script InstrumentList is blank", true)
    return
}

if (StrLen(StartDate) != 8) {
    MyDebug("Error", "Script StartDate is not in the right format", true)
    return
}

if (DateDiff(TodaysDate, StartDate, "days") < 0) {
    MyDebug("Error", "Script StartDate " FormatTime(StartDate, "ShortDate") " is greater than today's date", true)
    return
}

/* Change number of download days to not exceed today's system date */
NumberofDaysToDownload := Min(NumberofDaysToDownload, DateDiff(TodaysDate, StartDate, "days"))

/* Calculate the number of items to download */
TotalDownloadItems := 0
Loop Parse, InstrumentList, "," {
    TotalDownloadItems += 1
}
TotalDownloadItems := TotalDownloadItems * NumberofDaysToDownload

/* Start the mouse and keystroke emulation */
MyDebug("Message", "Starting Historical Market Replay Data Download for " NumberofDaysToDownload " day" (NumberofDaysToDownload == 1 ? "" : "s"), false)
MyDebug("Message", "Total Number of Downloads " TotalDownloadItems)

if (WinExist(HistDataWindow)) {
    MyDebug("Message", "Closing existing open " HistDataWindow " window", false, false)
    WinClose(HistDataWindow)
    Sleep SleepBetweenActions
}

if (WinExist("Control Center")) {
    MyDebug("Message", "Found Control Center window", false, false)

    WinActivate
    Sleep SleepBetweenActions / 2

    /* Click Tools menu item */
    MouseClick("Left", XTools, YTools)
    Sleep SleepBetweenActions

    /* Select Historical Data menu item */
    SendInput "{Down}{Down}{Down}{Down}{Down}{Enter}"

    if (WinWait(HistDataWindow, , 5)) {
        MyDebug("Message", "Opened " HistDataWindow " window", false, false)
        WinActivate

        /* Get current Historical Data window size and position */
        WinGetPos(&XCurrentHDWindow, &YCurrentHDWindow, &WCurrentHDWindow, &HCurrentHDWindow, HistDataWindow)

        /* Resize Historical Data window to fixed values to ensure correct mouse click positions */
        WinMove(XFixedSizeHDWindow, YFixedSizeHDWindow, WFixedSizeHDWindow, HFixedSizeHDWindow, HistDataWindow)

        /* Expand the rotating triangle for Get Market Replay data */
        MouseClick("Left", XRotatingTriangle, YRotatingTriangle)
        Sleep SleepBetweenActions

        /* Create a progress window with status bar */
        if (ShowProgressWindow) {
            MyGui := Gui(, "Download Progress")
            MyProgress := MyGui.Add("Progress", DownloadWindowSize)
            MyProgressStatusBar := MyGui.Add("StatusBar", , "")
            MyGui.Show
        }

        /* Loop through instruments */
        Loop Parse, InstrumentList, "," {

            Instrument := A_LoopField                   ; Process each instrument in list
            ProcessDate := StartDate                    ; Start date to be processed for each instrument
            LoopCnt := NumberofDaysToDownload           ; Number of days to download for each instrument

            /* Loop through download dates for each instrument */
            While (LoopCnt > 0) {

                ; Skip weekend days based on user configuration
                if ((SkipSaturday and !StrCompare(FormatTime(ProcessDate, "WDAY"), "7")) or (SkipSunday and !StrCompare(FormatTime(ProcessDate, "WDAY"), "1"))) {
                    MyDebug("Skipping", Instrument " for date " FormatTime(ProcessDate, "ShortDate") " as it is a weekend skip date", false, true)
                    ProcessDate := DateAdd(ProcessDate, 1, "Days")
                    if (ShowProgressWindow) {
                        MyProgress.Value += 100 / TotalDownloadItems
                    }
                    continue
                }

                if (WinExist(HistDataWindow)) {
                    WinActivate

                    MyDebug("Processing", Instrument " for date " FormatTime(ProcessDate, "ShortDate"), false, true)

                    /* Select Instrument Field */
                    MouseClick("Left", XInstrument, YInstrument)

                    /* Clear Instrument and Date fields and then fill them in */
                    SendInput "^a{Del}" Instrument "{Tab}^a{Del}" FormatTime(ProcessDate, "ShortDate")

                    /* Get colour of a download button pixel before presssing enter as this pixel color will be checked to see if download has finished */
                    BeforeColor := PixelGetColor(XDownloadButton, YDownloadButton)

                    SendInput "{Tab}{Enter}"

                    Sleep SleepBetweenActions * 6

                    if (WinExist("Error")) {
                        WinActivate
                        SendInput "{Enter}"
                        MyDebug("Error", Instrument " for date " FormatTime(ProcessDate, "ShortDate") " NinjaTrader responded with an Error window", false, true)

                        Sleep SleepBetweenActions
                    }
                    else {
                        loop {
                            Sleep SleepBetweenActions * 10
                            if WinExist(HistDataWindow)
                                WinActivate(HistDataWindow)
                            else {
                                MyDebug("Error", "Exiting script as either Historical Data window closed", true, true)

                                /* Close download progress window */
                                if (ShowProgressWindow && WinExist(DownloadWindow)) {
                                    MyGui.Destroy
                                }

                                return
                            }
                        } Until (!StrCompare(BeforeColor, PixelGetColor(645, 625)))
                    }

                    ProcessDate := DateAdd(ProcessDate, 1, "Days")
                    if (ShowProgressWindow) {
                        MyProgress.Value += 100 / TotalDownloadItems
                    }
                    LoopCnt -= 1
                }
                else {
                    MyDebug("Message", "Closing " HistDataWindow " window", false)
                }
            } ; Loop Instruments
        } ; Loop InstrumentList

        /* Close download progress window */
        if (ShowProgressWindow && WinExist(DownloadWindow)) {
            MyGui.Destroy
        }

        if (WinExist(HistDataWindow)) {
            /* Revert to original Historical Window size and position */
            WinMove(XCurrentHDWindow, YCurrentHDWindow, WCurrentHDWindow, HCurrentHDWindow, HistDataWindow)

            MyDebug("Message", "Closing " HistDataWindow " window", false, false)

            WinClose(HistDataWindow)
        }
    }
    else {
        MyDebug("Error", "Could not find " HistDataWindow " window", true, false)
        return
    }
}
else {
    MyDebug("Error", "Could not find Control Center window", true, false)
    return
}

MyDebug("Complete", "Script Historical Market Replay Data Download Finished", true, false)

return

Reply With Quote
Thanked by:




Last Updated on June 18, 2023


© 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