Jump to content

Auto scroll watchlist in Amibroker - (Moved)


Go to solution Solved by Luke94,

Recommended Posts

  • Replies 43
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

Whoops! Try this:

#include <GuiListView.au3>

Global $g_hWnd
Global $g_hListView
Global $g_iCount
Global $g_iIndex

$g_hWnd = WinGetHandle('AmiBroker') ; Get AmiBroker window handle
If IsHWnd($g_hWnd) = 1 Then ; Check the window handle is valid
    If WinActive($g_hWnd) = 0 Then ; Check if AmiBroker is NOT active
        WinActivate($g_hWnd) ; If it's NOT active, activate it
        WinWaitActive($g_hWnd, '', 5) ; Wait for the handle to become active
    EndIf
    While 1 ; Loop forever
        $g_hListView = ControlGetHandle($g_hWnd, '', '[CLASS:SysListView32; INSTANCE:5]') ; Get the ListView handle
        $g_iCount = (_GUICtrlListView_GetItemCount($g_hListView) - 1) ; Get the number of items in the ListView
        $g_iIndex = 0
        Do
            _GUICtrlListView_SetItemSelected($g_hListView, -1, False) ; Deselect all items
            ; _GUICtrlListView_ClickItem($g_hListView, $g_iIndex, 'Left', False, 2, 0) ; Double click the ListView Item
            _GUICtrlListView_SetItemSelected($g_hListView, $g_iIndex)
            _GUICtrlListView_EnsureVisible($g_hListView, $g_iIndex) ; Scrolls the ListView to the given index - which we're increasing by one below
            $g_iIndex += 1
            Sleep(2000) ; Wait 2000ms (2 seconds)
        Until $g_iIndex > $g_iCount ; Loop until we've reached the end of the ListView
        _GUICtrlListView_EnsureVisible($g_hListView, 0) ; Once we've reached the end of the ListView above, move back to the top of the ListView
        Sleep(15000) ; Wait 15000ms (15 seconds) - once we've waited, the While loop will restart
    WEnd
EndIf

 

Link to comment
Share on other sites

Its highlighting one stock at a time and moving in background also. But its not selecting stock, as on selection the chart should be shown like it was happening on the click function script. In this its highlighting the stock name and moving to next without chart changing.

Normally i click 1st chart and then use arrow key to move down, and as we move through the arrow keys the charts/stocks keep changing.

 

Edited by LearningEW
Link to comment
Share on other sites

Try this:

#include <GuiListView.au3>

Global $g_hWnd
Global $g_hListView
Global $g_iCount
Global $g_iIndex

$g_hWnd = WinGetHandle('AmiBroker') ; Get AmiBroker window handle
If IsHWnd($g_hWnd) = 1 Then ; Check the window handle is valid
    If WinActive($g_hWnd) = 0 Then ; Check if AmiBroker is NOT active
        WinActivate($g_hWnd) ; If it's NOT active, activate it
        WinWaitActive($g_hWnd, '', 5) ; Wait for the handle to become active
    EndIf
    While 1 ; Loop forever
        $g_hListView = ControlGetHandle($g_hWnd, '', '[CLASS:SysListView32; INSTANCE:5]') ; Get the ListView handle
        $g_iCount = (_GUICtrlListView_GetItemCount($g_hListView) - 1) ; Get the number of items in the ListView
        $g_iIndex = 0
    _GUICtrlListView_SetItemSelected($g_hListView, -1, False)
    _GUICtrlListView_SetItemSelected($g_hListView, $g_iIndex)
        Do
            ; _GUICtrlListView_SetItemSelected($g_hListView, -1, False) ; Deselect all items
            ; _GUICtrlListView_ClickItem($g_hListView, $g_iIndex, 'Left', False, 2, 0) ; Double click the ListView Item
            ; _GUICtrlListView_SetItemSelected($g_hListView, $g_iIndex)
            _GUICtrlListView_EnsureVisible($g_hListView, $g_iIndex) ; Scrolls the ListView to the given index - which we're increasing by one below
        ControlSend($g_hWnd, '', '[CLASS:SysListView32; INSTANCE:5]', '{DOWN}')
            $g_iIndex += 1
            Sleep(2000) ; Wait 2000ms (2 seconds)
        Until $g_iIndex > $g_iCount ; Loop until we've reached the end of the ListView
        _GUICtrlListView_EnsureVisible($g_hListView, 0) ; Once we've reached the end of the ListView above, move back to the top of the ListView
        Sleep(15000) ; Wait 15000ms (15 seconds) - once we've waited, the While loop will restart
    WEnd
EndIf

That'll de-select all items and select the first item. Then use the down arrow key to circle through.

I'm not sure if ControlSend will work without focus though.

Link to comment
Share on other sites

15 hours ago, Luke94 said:

 

Hi Luke,

 

The script has stopped working, its not doing any thing after system went to sleep and relogged in , both the double click and and arrow.  Have not changed the code

 

Update it started working, but after it goes to last stock/chart then it moves to top but then doesnt select the stock, just moves the list.

Edited by LearningEW
Update
Link to comment
Share on other sites

Try this:

#include <GuiListView.au3>

Global $g_hWnd
Global $g_hListView
Global $g_iCount
Global $g_iIndex

While 1 ; Loop forever
    $g_hWnd = WinGetHandle('AmiBroker') ; Get AmiBroker window handle
    If IsHWnd($g_hWnd) = 1 Then ; Check the window handle is valid
        If WinActive($g_hWnd) = 0 Then ; Check if AmiBroker is NOT active
            WinActivate($g_hWnd) ; If it's NOT active, activate it
            WinWaitActive($g_hWnd, '', 5) ; Wait for the handle to become active
        EndIf
        $g_hListView = ControlGetHandle($g_hWnd, '', '[CLASS:SysListView32; INSTANCE:5]') ; Get the ListView handle
        $g_iCount = (_GUICtrlListView_GetItemCount($g_hListView) - 1) ; Get the number of items in the ListView
        $g_iIndex = 0
        _GUICtrlListView_SetItemSelected($g_hListView, -1, False)
        _GUICtrlListView_SetItemSelected($g_hListView, $g_iIndex)
        ControlFocus($g_hWnd, '', '[CLASS:SysListView32; INSTANCE:5]')
        Do
            ; _GUICtrlListView_SetItemSelected($g_hListView, -1, False) ; Deselect all items
            ; _GUICtrlListView_ClickItem($g_hListView, $g_iIndex, 'Left', False, 2, 0) ; Double click the ListView Item
            ; _GUICtrlListView_SetItemSelected($g_hListView, $g_iIndex)
            _GUICtrlListView_EnsureVisible($g_hListView, $g_iIndex) ; Scrolls the ListView to the given index - which we're increasing by one below
            ControlSend($g_hWnd, '', '[CLASS:SysListView32; INSTANCE:5]', '{DOWN}')
            $g_iIndex += 1
            Sleep(2000) ; Wait 2000ms (2 seconds)
        Until $g_iIndex > $g_iCount ; Loop until we've reached the end of the ListView
        _GUICtrlListView_EnsureVisible($g_hListView, 0) ; Once we've reached the end of the ListView above, move back to the top of the ListView
        Sleep(15000) ; Wait 15000ms (15 seconds) - once we've waited, the While loop will restart
    EndIf
WEnd

It may have stopped working as expected because the window handle was lost when the computer slept. The above script will get the window handle every 15 second loop, rather than once on startup.

Also, it'll focus the ListView before entering the loop to scroll down it. I'm not sure if that'll help though as the window may need to be active.

Edited by Luke94
Spelling
Link to comment
Share on other sites

25 minutes ago, LearningEW said:

Pls note all scripts have stopped working ....have restarted the system still not working. This had happed today morning also but after some time suddenly started working.

 

Were you running the script in SciTE Editor? Do you have an error/exit code?

Link to comment
Share on other sites

I assume that's telling you the current line been executed. The script waits for 15 seconds once it reaches the end of the ListView.

The fact that the TrayIcon is still there tells me the script was still running.

I'm guessing like I said before, the window handle is lost/changed when the computer sleeps. The latest script I posted should avoid that - however I'm sure you'll run into more problems if the computer sleeps.

Can you not prevent the computer from sleeping?

Link to comment
Share on other sites

Computer sleeping can be stopped.

 

But this script is also not working. Every few seconds its bringing Amibroker to foreground that's it. No stock/chart selection or scrolling. 

All scripts have stopped.

I will send the Autoit window info again...has anything changed?

 

 

image.png.23cdcc1ae00e8565e1e9c5a74aeb78f1.png

 

on scroll bar

 

image.png.0d9a936be0900c78c6420137c7a566d5.png

Link to comment
Share on other sites

My bad, I moved all the outer code inside the While loop. Try this:

#include <GuiListView.au3>

Global $g_hWnd
Global $g_hListView
Global $g_iCount
Global $g_iIndex

$g_hWnd = WinGetHandle('AmiBroker') ; Get AmiBroker window handle
If IsHWnd($g_hWnd) = 1 Then ; Check the window handle is valid
    If WinActive($g_hWnd) = 0 Then ; Check if AmiBroker is NOT active
        WinActivate($g_hWnd) ; If it's NOT active, activate it
        WinWaitActive($g_hWnd, '', 5) ; Wait for the handle to become active
    EndIf
    While 1 ; Loop forever
        If IsHWnd($g_hWnd) = 1 Then
            $g_hListView = ControlGetHandle($g_hWnd, '', '[CLASS:SysListView32; INSTANCE:5]') ; Get the ListView handle
            $g_iCount = (_GUICtrlListView_GetItemCount($g_hListView) - 1) ; Get the number of items in the ListView
            $g_iIndex = 0
            _GUICtrlListView_SetItemSelected($g_hListView, -1, False)
            _GUICtrlListView_SetItemSelected($g_hListView, $g_iIndex)
            Do
                ; _GUICtrlListView_SetItemSelected($g_hListView, -1, False) ; Deselect all items
                ; _GUICtrlListView_ClickItem($g_hListView, $g_iIndex, 'Left', False, 2, 0) ; Double click the ListView Item
                ; _GUICtrlListView_SetItemSelected($g_hListView, $g_iIndex)
                _GUICtrlListView_EnsureVisible($g_hListView, $g_iIndex) ; Scrolls the ListView to the given index - which we're increasing by one below
                ControlSend($g_hWnd, '', '[CLASS:SysListView32; INSTANCE:5]', '{DOWN}')
                $g_iIndex += 1
                Sleep(2000) ; Wait 2000ms (2 seconds)
            Until $g_iIndex > $g_iCount ; Loop until we've reached the end of the ListView
            _GUICtrlListView_EnsureVisible($g_hListView, 0) ; Once we've reached the end of the ListView above, move back to the top of the ListView
            Sleep(15000) ; Wait 15000ms (15 seconds) - once we've waited, the While loop will restart
        Else
            $g_hWnd = WinGetHandle('AmiBroker')
            Sleep(1000) ; Wait 1000ms
        EndIf
    WEnd
EndIf

It'll check the AmiBroker window handle is valid on each loop and if it isn't it'll try and obtain it again.

Link to comment
Share on other sites

Two things

 

1) 

[CLASS:SysListView32; INSTANCE:5]')   here if i change to 1 then it selects and scrolls , if i keep 5 then it doesnt slect and scroll. Pls see the new Autoinfo shared it shows instance as 1 instead of 5 yesterday.

 

2) with [CLASS:SysListView32; INSTANCE:1]  same issue that after it has reached the last stock then it moves to 1st stocks and scrolls but without selecting them

Link to comment
Share on other sites

Try changing all occurrences of that line to:

'[CLASS:SysListView32; ID:903]'

The Instance changes but ID remains the same. See if that works.

When the ListView reaches the last stop and returns to the first, then scrolls without selecting them - Does that only happen when AmiBroker is in the background? Try running the script with AmiBroker active and leave it active, see if it does what it's supposed to.

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...