VBA to run analysis and select stock to add to watchlist

#1
I have an analysis of AFL which run explorer will give out 52Week Hi, Low, and 3 months Hi and Low and some basic quotations and moving averages. If today it have 52week Hi, then it shows 1, so does the 52 week Low, 3 months hi low. I am using VBA to run the explore and then export the results.

However, I want to select some stocks based on the results and create a watchlists, i.e. "add selected stocks to watchlists"

1. How to write the selected part of the stocks based on some criteria and add to watchlists? Say, the criteria, is 52WeekHi = 1 or 3monthsHi= 1
2. How can I put the stocks that matches the criteria into a watchlists, which I want newly created with the watchlist name specified, say by the date and time of creation)

I am using VBA, but either jscript or VBA are very welcome, even jscript, I would try my best to convert to VBA and this already provides good guidance.

Many thanks
 

mastermind007

Well-Known Member
#2
I have an analysis of AFL which run explorer will give out 52Week Hi, Low, and 3 months Hi and Low and some basic quotations and moving averages. If today it have 52week Hi, then it shows 1, so does the 52 week Low, 3 months hi low. I am using VBA to run the explore and then export the results.

However, I want to select some stocks based on the results and create a watchlists, i.e. "add selected stocks to watchlists"

1. How to write the selected part of the stocks based on some criteria and add to watchlists? Say, the criteria, is 52WeekHi = 1 or 3monthsHi= 1
2. How can I put the stocks that matches the criteria into a watchlists, which I want newly created with the watchlist name specified, say by the date and time of creation)

I am using VBA, but either jscript or VBA are very welcome, even jscript, I would try my best to convert to VBA and this already provides good guidance.

Many thanks
You can manipulate all of that thru COM Interface (any scripting language C#, VB etc ... ). I do not have any sample code that manipulates watch-list but I do know that it is possible.
 

trash

Well-Known Member
#3
I have an analysis of AFL which run explorer will give out 52Week Hi, Low, and 3 months Hi and Low and some basic quotations and moving averages. If today it have 52week Hi, then it shows 1, so does the 52 week Low, 3 months hi low. I am using VBA to run the explore and then export the results.

However, I want to select some stocks based on the results and create a watchlists, i.e. "add selected stocks to watchlists"

1. How to write the selected part of the stocks based on some criteria and add to watchlists? Say, the criteria, is 52WeekHi = 1 or 3monthsHi= 1
2. How can I put the stocks that matches the criteria into a watchlists, which I want newly created with the watchlist name specified, say by the date and time of creation)

I am using VBA, but either jscript or VBA are very welcome, even jscript, I would try my best to convert to VBA and this already provides good guidance.

Many thanks


Code:
your condition = .... ;

if( LastValue( your condition ) )
    CategoryAddSymbol( "", categoryWatchlist, 0 );
 

mastermind007

Well-Known Member
#4
Code:
your condition = .... ;

if( LastValue( your condition ) )
    CategoryAddSymbol( "", categoryWatchlist, 0 );
Wonderfull... this is lot better than having to use COM based script
 

trash

Well-Known Member
#6
If last siganl is not true anymore then

Code:
wlnum = 0;

Filter = ... ;

if ( NOT LastValue( Filter ) )
        CategoryRemoveSymbol( "", category, wlnum );
 

trash

Well-Known Member
#7
with the watchlist name specified, say by the date and time of creation)
Code:
wlnumber = 0; // define watchlist

Filter = .... ; 

if( LastValue( Filter ) ) 
    CategoryAddSymbol( "", categoryWatchlist, wlnumber );


if ( Status( "action" ) == actionExplore AND InWatchList( wlnumber ) )
{
    AB = CreateObject( "Broker.Application" );
    st = AB.Stocks( Name() );
    st.FullName = CategoryGetName( categoryWatchlist, wlnumber ) + " " + Now( 0 ); 
}


SetOption( "RefreshWhenCompleted", True );
Well or

Code:
wlnumber = 0; // define watchlist

Filter = .... ; 

if ( Status( "action" ) == actionExplore AND LastValue( Filter ) )
{
    CategoryAddSymbol( "", categoryWatchlist, wlnumber );

    AB = CreateObject( "Broker.Application" );
    st = AB.Stocks( Name() );
    st.FullName = CategoryGetName( categoryWatchlist, wlnumber ) + " " + Now( 0 ); 
}

SetOption( "RefreshWhenCompleted", True );
untested

But it's using OLE. So .... http://www.traderji.com/amibroker/88502-old-analysis-vs-new-analysisdocs-ole.html
 
Last edited:
#8
Code:
wlnumber = 0; // define watchlist

Filter = .... ; 

if( LastValue( Filter ) ) 
    CategoryAddSymbol( "", categoryWatchlist, wlnumber );


if ( Status( "action" ) == actionExplore AND InWatchList( wlnumber ) )
{
    AB = CreateObject( "Broker.Application" );
    st = AB.Stocks( Name() );
    st.FullName = CategoryGetName( categoryWatchlist, wlnumber ) + " " + Now( 0 ); 
}


SetOption( "RefreshWhenCompleted", True );
Well or

Code:
wlnumber = 0; // define watchlist

Filter = .... ; 

if ( Status( "action" ) == actionExplore AND LastValue( Filter ) )
{
    CategoryAddSymbol( "", categoryWatchlist, wlnumber );

    AB = CreateObject( "Broker.Application" );
    st = AB.Stocks( Name() );
    st.FullName = CategoryGetName( categoryWatchlist, wlnumber ) + " " + Now( 0 ); 
}

SetOption( "RefreshWhenCompleted", True );
untested

But it's using OLE. So .... http://www.traderji.com/amibroker/88502-old-analysis-vs-new-analysisdocs-ole.html
Yes, but if I want to use excel as my control panel, then seems OLE is the only way to control AB...

I have some confused with the function "status(" xxxx")" what does it used for? return the status of the AB? or ask AB to run the NEW analysis?

ref: http://www.amibroker.com/guide/afl/status.html

thanks
 

trash

Well-Known Member
#10
I have some confused with the function "status(" xxxx")" what does it used for? return the status of the AB? or ask AB to run the NEW analysis?

ref: http://www.amibroker.com/guide/afl/status.html

thanks
There are different status options as seen in your link

Status( "action" ) == actionExplore means that the code is only getting executed if clicking Explore button.

while in wlnumber = 0 <- does this means the index of the watchlist?
Yes, it's the watchlist number.


Yes, but if I want to use excel as my control panel, then seems OLE is the only way to control AB...
What does that mean practically? What do you need it for? Control AB from Excel for doing what?
 

Similar threads