Program Trading: Strong/Weak Stock Selection

Charlton

Experienced member
Messages
1,501
Likes
326
Over the months Iraj has shown us how to use FINVIZ and N minute change to choose strong and weak stocks for both swing trading and intraday trading.

For programmed trading there are different approaches that could be used, and I am particularly thinking about intraday at present:

- Manually choose a basket of 3 or 4 strong stocks and 3 or 4 weak stocks. These would be input into the auto-trading engine at the start of the session and used throughout

- Automatically choose the 3 or 4 strongest/weakest stocks according to the prevailing market conditions i.e. the basket would be variable

We may decide to allow the auto-trading engine to allow both approaches (or have 2 similar engines).

The manual stock selection can be performed, at present, using the current tools.

For auto-stock selection there is a problem using N min change. This requires changing data compression during the session. I have been investigating whether it is possible to automate this. You can set up a macro to change data compression in a chart and it is possible to run a macro from within an indicator or showme, although I have done the latter. You cannot run a macro to change data compression in radar screen however.

For this reason it is necessary to avoid the need to change data compression. For this reason I am proposing that we use a different function for automated strong/weak stock selection . One choice would be Comparative Relative Strength. This is the ratio of the change in price of the stock compared to market over a period.

StockFetcher: Comparative Relative Strength

We can build an indicator that performs this calculation from the market open to the current time and use a fixed 1 minute data compression.

If anyone has ideas for better measures of relative strength then please provide your suggestions.

Charlton
 
Charlton,

I think you have the right idea regarding the intraday approach. I use a relative strength ranking to sort stocks and it corresponds broadly with the ranking from my lash up of Iraj's N min Change (for Neoticker), which I run in parallel.

I don't think sorting out strong and weak in advance will give the hoped for result intraday as a stock which is strong one day may well be weak the next even though it may be persistently strong or weak on a longer timeframe. However, in a similar way I don't think that taking the current RS as measured from the open will give the desired result as the RS of a stock typically rises and falls throughout the day. So it may be relatively strong measured from the open but be weaking over, say, the last 30 min. Is it preferable to go for the stock that has the overall higher RS but is clearly weakening or for a slightly weaker stock that is maintaining that strength? I have to say that I'm not clear how the N min change reflects this but I do see the stocks moving up or down the list - sometimes quite rapidly. Maybe the requirement for a "quick" scalp system is going to be different than that for a "slow" scalp system. I try to cater for this by watching the strength change over, for example, 5, 15, 30 min, and so on. Too much information!!!!!?????:confused:

Al
 
Charlton,

I think you have the right idea regarding the intraday approach. I use a relative strength ranking to sort stocks and it corresponds broadly with the ranking from my lash up of Iraj's N min Change (for Neoticker), which I run in parallel.

I don't think sorting out strong and weak in advance will give the hoped for result intraday as a stock which is strong one day may well be weak the next even though it may be persistently strong or weak on a longer timeframe. However, in a similar way I don't think that taking the current RS as measured from the open will give the desired result as the RS of a stock typically rises and falls throughout the day. So it may be relatively strong measured from the open but be weaking over, say, the last 30 min. Is it preferable to go for the stock that has the overall higher RS but is clearly weakening or for a slightly weaker stock that is maintaining that strength? I have to say that I'm not clear how the N min change reflects this but I do see the stocks moving up or down the list - sometimes quite rapidly. Maybe the requirement for a "quick" scalp system is going to be different than that for a "slow" scalp system. I try to cater for this by watching the strength change over, for example, 5, 15, 30 min, and so on. Too much information!!!!!?????:confused:

Al
There are some good points you have raised and here are my thoughts:

(a) You have confirmed that relative strength (and I refered specifically to Comparative Relative Strength, rather than RSI) is a suitable candidate
(b) as comparative RS will be measured compared to INDU, then INDU itself wil have a value of 1. Stronger stocks will have value greater than 1 and weaker will be less than 1.
(c) The comparative RS has a period input and if we work on data compression = 1 min, then this will measure the movement in stock price compared to INDU price over that number of minutes. The question is how many minutes and gut feeling for me would be 30 mins. This would show which stocks are performing stronger/weaker over the last 30 mins.
(d) we then want to know which stocks within that strong population are growing in strength, so we could bring in a second time frame of say 10 mins. So for a long position we choose to buy the top 3 stocks in terms of an RS above 1 based on 30 mins, further sorted to choose by the highest RS over the last 10 mins.

or something like that :cheesy:

Charlton
 
Over the months Iraj has shown us how to use FINVIZ and N minute change to choose strong and weak stocks for both swing trading and intraday trading.

For programmed trading there are different approaches that could be used, and I am particularly thinking about intraday at present:

- Manually choose a basket of 3 or 4 strong stocks and 3 or 4 weak stocks. These would be input into the auto-trading engine at the start of the session and used throughout

- Automatically choose the 3 or 4 strongest/weakest stocks according to the prevailing market conditions i.e. the basket would be variable

We may decide to allow the auto-trading engine to allow both approaches (or have 2 similar engines).

The manual stock selection can be performed, at present, using the current tools.

For auto-stock selection there is a problem using N min change. This requires changing data compression during the session. I have been investigating whether it is possible to automate this. You can set up a macro to change data compression in a chart and it is possible to run a macro from within an indicator or showme, although I have done the latter. You cannot run a macro to change data compression in radar screen however.

For this reason it is necessary to avoid the need to change data compression. For this reason I am proposing that we use a different function for automated strong/weak stock selection . One choice would be Comparative Relative Strength. This is the ratio of the change in price of the stock compared to market over a period.

StockFetcher: Comparative Relative Strength

We can build an indicator that performs this calculation from the market open to the current time and use a fixed 1 minute data compression.

If anyone has ideas for better measures of relative strength then please provide your suggestions.

Charlton

hi Charlton,

Do you know what stockfetchers formula is for RS is it rate of change based?

have you looked into log returns?
 
hi Charlton,

Do you know what stockfetchers formula is for RS is it rate of change based?

have you looked into log returns?
Moreagr

The link I gave is all that I have. That site has a downloadable pdf file on all of their indicators, but it doesn't give much more detail for comparative RS, probably because it is so simple i.e. divide one price by another price. There are of course variations on this looking at the movement over a period of time.

Fortunately there is already TS code available on the TS forum

https://www.tradestation.com/Discus...=comparative relative strength&txtExactMatch=

I am also pasting here links to some tricks of the trade we may need to use to handle multiple data coding specifically in radar screen, such as dividing one price by another !
Globalvariable.dll will be a likely candidate for this task.

https://www.tradestation.com/Discus...IC SYMBOL USED IN RADAR SCREEN&txtExactMatch=

https://www.tradestation.com/Discus...m=open charts from radarscreen&txtExactMatch=

I haven't looked at log returns - that is until you mentioned them. Can you enlighten us about how they are calculated and whether they are applicable for intraday, because my brief searches on google suggest they are more applicable longer term.

Charlton
 
I think we should select not only strong/weak stocks by momentum but stocks that "show less oscillatory behaviour while trending". I like Iraj PATH OF LEAST RESISTANCE approach.

http://www.trade2win.com/boards/technical-trader/8448-path-least-resistance-advanced-ta.html

Are you able to elaborate on this, because I can't really get a feel for what defines these stocks, based on the brief discussion in that thread. Anything that we code needs to have clear measurable characteristics that are capable of being codified, so we need to identify specific conditions that are met by these stocks.

Charlton
 
Why don't we just change the data compression manually, perhaps every 14 minutes, as long as we have an indicator telling/reminding us to change it in RS. That indicator would calculate what should be the current interval/data compression. We should stick to Iraj N-minute change indicator as it is supposed to be our edge.
 
Why don't we just change the data compression manually, perhaps every 14 minutes, as long as we have an indicator telling/reminding us to change it in RS. That indicator would calculate what should be the current interval/data compression. We should stick to Iraj N-minute change indicator as it is supposed to be our edge.
Leovirgo

We have an indicator that tells us what the data compression should be already. It is the MISC indicator so you can continue to do as you suggest, but the purpose of these threads is to auto-trade, as Iraj indicated in the last seminar.

The edge comes from 3 aspects :
- multi timeframe analysis
- cycle analysis
- weak and strong stock selection

As I said in my first post on this thread, you can continue to use N min change to manually feed a basket of 3 or 4 stocks into the rest of the auto-trading engine. This could be done at the start of the session if you did not want to change it potentially every 14 mins. This is the reason why the auto-engine will have a modular design, so that you either slot in different indicators or manual processes if you prefer.

However the ultimate goal of this exercise is to try to achieve maximum automation yielding maximum profit and minimum risk - to further explore the 3 aspects above to see if we can improve on them. Iraj has already challenged us to find more adaptive indicators than MACCi for the cycle analysis.

We cannot get into the code behind Iraj N min change because it is proprietary code belonging to Iraj and he quite understandably wishes to protect it. For that reason we are exploring other indicators of strength and weakness, so that we can build code around this that can be slotted into the other modules.


Charlton
 
Leovirgo

We have an indicator that tells us what the data compression should be already. It is the MISC indicator so you can continue to do as you suggest, but the purpose of these threads is to auto-trade, as Iraj indicated in the last seminar.

The edge comes from 3 aspects :
- multi timeframe analysis
- cycle analysis
- weak and strong stock selection

Hi Charlton

It's understandable that we want to automate and improve the system. I was just raising my concerns about possible diversions. It would be better to get a better indicator than MACCI but I feel that MACCI or CG is not that important. To me, the diffucult part is auto execution such as connecting IB and TS through API. If you need someone to test/back testing the modules please let me know.
 
Hi Charlton

It's understandable that we want to automate and improve the system. I was just raising my concerns about possible diversions. It would be better to get a better indicator than MACCI but I feel that MACCI or CG is not that important. To me, the diffucult part is auto execution such as connecting IB and TS through API. If you need someone to test/back testing the modules please let me know.
Have you tried the auto execution in IB yet ? If so have you hit problems with it ?

In the past I set up Amibroker to auto-connect to IB, but it was just for testing purposes. It should be fairly simple. I have both IB and TS, so if you want any assistance with that I might be able to draw on my past knowlege, even though I have not specifically attempted it between the latter 2 platforms.

Charlton
 
Are you able to elaborate on this, because I can't really get a feel for what defines these stocks, based on the brief discussion in that thread. Anything that we code needs to have clear measurable characteristics that are capable of being codified, so we need to identify specific conditions that are met by these stocks.

Charlton


Path of least resistance is referred to stocks that trend along side the market momentum with MINIMUM pull back or oscialltions when market weakens..
http://www.trade2win.com/boards/technical-trader/8448-path-least-resistance-advanced-ta.html#post78402


We can use some kind of ATR trailing to measure pullbacks.

attachment.php


When the market is oversold and exhausted (1) and the stock is strong (2) and its pullback less than ~ 2 ATR (3) we will buy this stock.
 

Attachments

  • WAR Trailing.png
    WAR Trailing.png
    20.7 KB · Views: 173
For auto-stock selection there is a problem using N min change. This requires changing data compression during the session. I have been investigating whether it is possible to automate this. You can set up a macro to change data compression in a chart and it is possible to run a macro from within an indicator or showme, although I have done the latter. You cannot run a macro to change data compression in radar screen however.

For this reason it is necessary to avoid the need to change data compression. For this reason I am proposing that we use a different function for automated strong/weak stock selection . One choice would be Comparative Relative Strength. This is the ratio of the change in price of the stock compared to market over a period.


Charlton

Charlton,

Blu-Ray produced code which could be added to 'Iraj N-Minute Change' that automatically changes the data compression, take a look at post #16 in the following thread,

http://www.trade2win.com/boards/technical-trader/29739-tt-toolbox-2.html

We could integrate this with our own version of 'Iraj N-Minute Change'?

Regards

TMM
 
Strength/Weakness compared to market indicator

Charlton,

Blu-Ray produced code which could be added to 'Iraj N-Minute Change' that automatically changes the data compression, take a look at post #16 in the following thread,

http://www.trade2win.com/boards/technical-trader/29739-tt-toolbox-2.html

We could integrate this with our own version of 'Iraj N-Minute Change'?

Regards

TMM
TMM

Thanks very much for the link - the real issue is that we do not have the internal code behind N min change and Iraj is not able to give it to us. I have already asked him and he has his own good reasons for not making it public. So I should make it clear that we are not building a version of 'Iraj N minute change', but we are building our own relative strength indicator based on our own research.

For that reason, if we wish to fully automate selection of our basket of stocks and to incorporate that into the overall trading engine we need to build our own strength/weakness indicator. This may need to include within its own code a way of altering data compression, (but not necessarily) and which can generate global variable values that can be passed out to the rest of the auto-trading engine e.g. the cycle analysis that will provide the buy/sell signals on the provided basket of stocks.

It will be within that code that we could incorporate the code provided by Blu-Ray with, if changing data compression is a requirement for the indicator we choose to use.


Charlton
 
TMM

Thanks very much for the link - the real issue is that we do not have the internal code behind N min change and Iraj is not able to give it to us. I have already asked him and he has his own good reasons for not making it public. So I should make it clear that we are not building a version of 'Iraj N minute change', but we are building our own relative strength indicator based on our own research.

For that reason, if we wish to fully automate selection of our basket of stocks and to incorporate that into the overall trading engine we need to build our own strength/weakness indicator. This may need to include within its own code a way of altering data compression, (but not necessarily) and which can generate global variable values that can be passed out to the rest of the auto-trading engine e.g. the cycle analysis that will provide the buy/sell signals on the provided basket of stocks.

It will be within that code that we could incorporate the code provided by Blu-Ray with, if changing data compression is a requirement for the indicator we choose to use.


Charlton

Charlton,

I was not suggesting we copy Irajs's indicator in anyway, just that Blu-Rays code could be useful for our own purposes. Apologies for not making myself very clear!

Regards

TMM
 
Charlton,

I was not suggesting we copy Irajs's indicator in anyway, just that Blu-Rays code could be useful for our own purposes. Apologies for not making myself very clear!

Regards

TMM

All

I think I might go for something similar to the approach on the entry thread. I will say that the actual method of sorting may not matter to the code. It's a plug in so we can develop the rest of the code whilst mulling over the best way to assign a value for strength/weakness.

There's some technical issues to overcome but here's what I'd do....

1 - Put the stocks in radar screen, inlcuding $INDU
2 - Have an indicator that we call to set a value by which we'll sort
3 - If the stock is $INDU - set that as the baseline
4 - Depending on long bias or short bias, we take the top n stocks
5 - Let's say we want to choose 3 stocks - we will pick the top 6
6 - From the top 6 - we will look at the sectors & see if we can pick 3 from different sectors, not purely just by their relation to the $INDU, that gives us our 3 stocks.
7 - stick the 3 stocks names in a global var
8 - I dont think global var supports arrays, so maybe we just have a set of 10 fixed names.

Also on radar screen we'll have a final ESL to manage the trades. This will take inputs from TT_ENTRY as well as the ESL above.

It will say...

1 - If TT_ENTRY is a buy/sell
2 - If this stock is in the strong/weak list
3 - position size & entry
4 - Trade managememt - b/e stop loss, get out at 75% if the 10 min turns, get out remaining 25% 10 mins b4 market close.

Note - position size will probably also be a function which we can tweak.

What's probably the best way forward is the thing we did on the entry ESL - I'll design/write the framework into which we can plug indicators (for sorting) and then let Charlton & all optimise it.

The idea is that someone needs to get something down for others to look at & improve, I can do that, no problem.

Thoughts on the outline design ?
 
All

I think I might go for something similar to the approach on the entry thread. I will say that the actual method of sorting may not matter to the code. It's a plug in so we can develop the rest of the code whilst mulling over the best way to assign a value for strength/weakness.

There's some technical issues to overcome but here's what I'd do....

1 - Put the stocks in radar screen, inlcuding $INDU
2 - Have an indicator that we call to set a value by which we'll sort
3 - If the stock is $INDU - set that as the baseline
4 - Depending on long bias or short bias, we take the top n stocks
5 - Let's say we want to choose 3 stocks - we will pick the top 6
6 - From the top 6 - we will look at the sectors & see if we can pick 3 from different sectors, not purely just by their relation to the $INDU, that gives us our 3 stocks.
7 - stick the 3 stocks names in a global var
8 - I dont think global var supports arrays, so maybe we just have a set of 10 fixed names.
I concur with the general principles outlined above.

The main issue with radar screen is that I have not found a way to pass a ranking into ESL and therefore choosing the top or bottom 6 candidates. I think this may require some external dll to be written.


Also on radar screen we'll have a final ESL to manage the trades. This will take inputs from TT_ENTRY as well as the ESL above.

It will say...

1 - If TT_ENTRY is a buy/sell
2 - If this stock is in the strong/weak list
3 - position size & entry
4 - Trade managememt - b/e stop loss, get out at 75% if the 10 min turns, get out remaining 25% 10 mins b4 market close.

Note - position size will probably also be a function which we can tweak.
Again - this looks good and relatively straightforward because 1 and 3 have already been defined in your existing TT_MTL_CYCLE code and the existing MISC code. We have just discussed 2 above. 4 is fairly straightforward.

A further complication is how to handle susbsequent trades after the first set have taken place. I assume for the time being that we will not allow a basket that exceeds our maximum number or the allowed portfolio size. After a stock is sold from a long basket any further trades would then only be allowed if the cost fell within the unused allowed portfolio size remaining. I also assume that we should not add to trades, so the stock selection should exclude any symbols in open positions.

What's probably the best way forward is the thing we did on the entry ESL - I'll design/write the framework into which we can plug indicators (for sorting) and then let Charlton & all optimise it.

The idea is that someone needs to get something down for others to look at & improve, I can do that, no problem.

Thoughts on the outline design ?
Generally though I am overawed by the amount of progress and the momentum that has occurred with this project. I think the TT forum should be very proud of what it has achieved in such a short time since Iraj suggested that we look into this.

I am currently running the TT_CYCLE results out to the print log, so others can view the signals minute by minute. On the weekend I will see how this runs through the optimiser and also try to investigate the radar screen ranking requirement.

Thanks

Charlton
 
************
The main issue with radar screen is that I have not found a way to pass a ranking into ESL and therefore choosing the top or bottom 6 candidates. I think this may require some external dll to be written.
****************


Hi Charlton,

Forgive me if this is a 'dumb' thing to say but (kinda thinking outloud) is it not possible for the Weak/Strong indicator we end up with to output a GlobalVariable containing the stock name and its 'value' (currently we use a value under the ATR Change colum to sort for example) and a seperate piece of code then identifies the top/bottom three stocks by 'collecting the GlobalVariables and analysing them? I hope I have explained what I actually mean!

Cheers
Steve
 
************
The main issue with radar screen is that I have not found a way to pass a ranking into ESL and therefore choosing the top or bottom 6 candidates. I think this may require some external dll to be written.
****************


Hi Charlton,

Forgive me if this is a 'dumb' thing to say but (kinda thinking outloud) is it not possible for the Weak/Strong indicator we end up with to output a GlobalVariable containing the stock name and its 'value' (currently we use a value under the ATR Change colum to sort for example) and a seperate piece of code then identifies the top/bottom three stocks by 'collecting the GlobalVariables and analysing them? I hope I have explained what I actually mean!

Cheers
Steve
Steve

In fact you have led me down a path that might prove fruitful making use of some of the GET functions, both for this purpose and other ones. I am investigating at present and will report back. One of the functions allows me to create named global variables where the name of the variable is actually the name of the equity, without me having to define it in advance.

Thanks

Charlton
 
Steve

In fact you have led me down a path that might prove fruitful making use of some of the GET functions, both for this purpose and other ones. I am investigating at present and will report back. One of the functions allows me to create named global variables where the name of the variable is actually the name of the equity, without me having to define it in advance.

Thanks

Charlton

OK - I had a stab at this....

#TT_RATE_WEAKSTRONG : This is just a 'placeholder' we will do 3 things in this ESL
1 - call a function to get a strength value (to be decided later)
2 - Call a function TT_SET_ARRAY to store that value see next ESL
3 - Plot the indicator value

Code:
Vars : ReturnCode(0),RelativeStrength(0);
// Call a function to analyze the strength/weakness of a stock and produce a value
	
RelativeStrength = getappinfo(aiRow);

// Now call a function to put this data away for use at trade time

ReturnCode = TT_SET_ARRAY(RelativeStrength);

//Plot the relative strength

Plot1(RelativeStrength,"Strength");


Note - the line "RelativeStrength = getappinfo(aiRow);" is just a dummy line & needs to be replaced with a real calculator for strength/weakness.

TT_SET_ARRAY :
1 - accepts the strength indicator value from the caller
2 - puts the symbol name into a list of symbols that we'll use at order time
3 - stores the strength value in a named global variable who's name is "TTList + symbol name"
4 - stores the number of symbols in a global variable called "SymbolListCount"

Code:
inputs : SortIndicatorValue(Numeric);
vars : SymbolListCount(0), ListPosition(""), ReturnCode(0);

// has symbol already been defined in the symbol list ?
if GVGetNamedString(getsymbolname + "defined","N") <> "Y" then begin
   ReturnCode = GVSetNamedString(getsymbolname + "defined","Y");
// Get next position number 
	SymbolListCount = GVGetNamedInt("SymbolListCount",0);
	SymbolListCount = SymbolListCount + 1;
// Put the name of the symbol in the symbol list at the new position
	ReturnCode = GVSetString(SymbolListCount,getsymbolname);
	ReturnCode = GVSetNamedInt("SymbolListCount",SymbolListCount);
print(SymbolListCount, " ",getsymbolname);
end;
ReturnCode = GVSetNamedFloat("TTList" + getsymbolname,SortIndicatorValue);
TT_SET_ARRAY = 1;

So at the end of this, we have a list of symbols and a value for each symbol that we can load into an array for sorting later.

Capiche ???

I may do the load later on - it'll make more sense then. For now - just test this out on your n min change radar screen to see the print statements. The print statements are just the list of symbols, not their strength. If you add another symbol to radar screen you'll see another entry. This list will stay until you close tradestation.

My image is we have a TT_GET_ARRAY that gets the list of symbol names & strength values then puts them in an array so we can sort them get the list of stocks to trade.

This is just the start but the array processing to store & sort the weak/strong values is a technical hurdle we needed to overcome.

Let me know if you think you can improve on this. ESL Attached.

Cheers

Pete
 

Attachments

  • TT_RATE_WEAKSTRONG.ELD
    9.9 KB · Views: 24
Last edited:
Top