Hello,
with the "MathIndOpInd"-Indicator I can
add / subtract /multiply / divide
two indicators. Would it be possible to add a "power" operator in order to calculate one indicator to the power of another one?
Might it be possible to have a simple "value" indicator which is just a fixed value. Wherever an indicator has to be chosen, a fixed value could be chosen as well with this "value indicator".
Kind regards
Werner
with the "MathIndOpInd"-Indicator I can
add / subtract /multiply / divide
two indicators. Would it be possible to add a "power" operator in order to calculate one indicator to the power of another one?
Might it be possible to have a simple "value" indicator which is just a fixed value. Wherever an indicator has to be chosen, a fixed value could be chosen as well with this "value indicator".
Kind regards
Werner
Rename
QUOTE:
to add a "power" operator in order to calculate one indicator to the power of another
As a numerical analysis guy, this is a bad idea. The indicator governing the power is going to cause the result to blow up big time on occasion. Don't do it!
However, it would be reasonable to raise an indicator to a real number power. I've never done that in stock trading, but there might be some application for it.
Another real possibility would be to do something like this:
(indicator1)*(indicator2^2) as well as . . . (indicator1)*(indicator2)
That works because their product(s) is(are) orthogonal to the individual indicators, so we include such independent terms in empirical models. We call these interaction terms in statistical modeling.
You need to pick up an advanced statistics book and read the chapter on multi-linear regression modeling. I think you would find it very interesting.
I'm not here to judge, and adding a Power argument is trivial so we can certainly do it. Regarding a "value" can you use MathIndOpValue instead of MathIndOpInd?
Ok thats good
Hi Superticker & Glitch,
Thank you for your replies. Yes, it is a good point that you can use MathIndOpInd to multiply an indicator with itself, thus creating the indicator raised to the second power.
But you could not create something like:
Transaction Weight = RSI ^ 0.7 * ROC ^ 0.3
with the 0.7 and the 0.3 being optimizable. (I don't know if that can lead to something, I just want to test it.)
Glitch: Thanks for the hint. Yes, with the MathIndOpValue you practically can generate each value you want. First you take MathIndOpInd to divide an RSI by one million, getting to a very small value - almost zero. And then using this in an MathIndOpValue and add each value you want practically results in that value.
Thanks both for your help!
Thank you for your replies. Yes, it is a good point that you can use MathIndOpInd to multiply an indicator with itself, thus creating the indicator raised to the second power.
But you could not create something like:
Transaction Weight = RSI ^ 0.7 * ROC ^ 0.3
with the 0.7 and the 0.3 being optimizable. (I don't know if that can lead to something, I just want to test it.)
Glitch: Thanks for the hint. Yes, with the MathIndOpValue you practically can generate each value you want. First you take MathIndOpInd to divide an RSI by one million, getting to a very small value - almost zero. And then using this in an MathIndOpValue and add each value you want practically results in that value.
Thanks both for your help!
QUOTE:
But you could not create something like:
Transaction Weight = RSI ^ 0.7 * ROC ^ 0.3
with the 0.7 and the 0.3 being optimizable.
I think I misunderstood you. I thought you were trying to do something like
(indicator1)^(indicator2), which I would definitely not recommend.
But there's nothing wrong with raising an indicator to some real number power as I mentioned before, and I now "think" that's what you are actually trying to do.
I don't use blocks, so I can't say whether the real number, used as a power, could be optimized. Of course, if you coded this in C#, then anything is possible.
Transaction weights only play a role if the backtester must pick between to possible valid trades, which rarely happens. I don't think your weight values are going to affect your results that much. Maybe what you really want to do is use "ranks" instead of weights to merit rank stocks in your dataset for trading. Start a new topic if that's where this is going.
Hello, my strategy usually comes up with a lot of signals. So, Transaction Weight becomes decisive in chosen the stocks to buy. What do you mean by "ranks"? Like excluding some stocks altogether from trading?
QUOTE:
What do you mean by "ranks"? Like excluding some stocks altogether from trading?
I don't use Blocks, but there is some kind of Block that allows you to "rank stocks" within a dataset by some kind of merit variable. Then your strategy will let you pick the higher ranked stocks from your dataset to do your trading with. You might want to search the forum for a Block example. Or search the Help docs for the Block that does this ranking.
For C# coding, we use the PreExecute{block} for sorting (ranking) stocks in a dataset. We then cherry pick these highest ranked stocks for trading in the Execute{block}.
What the "weights" metric is for is to break ties between two equally qualified stocks to make a trade. But your intent (I think) is to select on merit, and ranking is better for that.
Hi Superticker,
thank you for your answer. It seems there is nothing like "PreExecute" when you are working with building blocks. We only have the transaction weight to decide which stock to buy should there be more candidates than slots. And the transaction weight normally allows only for one indicator, however by using the "MathIndOpXXX" functions, you can create something with several indicators.
I read that "PreExecute" is very powerful. That you can make it buy stocks from different sectors, so that you are not stuck in one sector, should bad news come up regarding this sector.
I also read that you can do dynamic position sizing with it. So, if your calculation results in a higher likelihood that a trade will succeed, you can invest more (on margin maybe), while if a trade meets the criteria but the calculated likelihood that it will be successful is not so high, you just use your normal budget.
I would really like to try out these things. And something more:
Like, whenever you buy a stock - because it meets the criteria of your strategy, at the same time you short other stocks from the same sector. The idea would be to be immune against general ups and downs which concern this sector.
I hope I am intelligent enough to realize such a strategy in the future. I would really be interested if that can work out...
thank you for your answer. It seems there is nothing like "PreExecute" when you are working with building blocks. We only have the transaction weight to decide which stock to buy should there be more candidates than slots. And the transaction weight normally allows only for one indicator, however by using the "MathIndOpXXX" functions, you can create something with several indicators.
I read that "PreExecute" is very powerful. That you can make it buy stocks from different sectors, so that you are not stuck in one sector, should bad news come up regarding this sector.
I also read that you can do dynamic position sizing with it. So, if your calculation results in a higher likelihood that a trade will succeed, you can invest more (on margin maybe), while if a trade meets the criteria but the calculated likelihood that it will be successful is not so high, you just use your normal budget.
I would really like to try out these things. And something more:
Like, whenever you buy a stock - because it meets the criteria of your strategy, at the same time you short other stocks from the same sector. The idea would be to be immune against general ups and downs which concern this sector.
I hope I am intelligent enough to realize such a strategy in the future. I would really be interested if that can work out...
QUOTE:
It seems there is nothing like "PreExecute" when you are working with building blocks.
That is correct. Moreover, I believe PreExecute is the most powerful feature in WL because it allows you to cherry pick the best stocks (based on a criteria) in a given dataset.
I searched the forum for a topic that employs dataset stock Rank with a block strategy. The link is below. There is a block condition called Symbol Ranking by Indicator; look it up in the Help docs. Apparently, you can only perform the ranking against a single indicator, so if you want something more complicated you're going to have to create an indicator for it. And yes that requires some C# coding. https://www.wealth-lab.com/Discussion/Rotation-Strategy-buy-lowest-RSI-symbols-sell-when-no-longer-in-bottom-30-12875#post4
I would start simple and use an existing indicator initially to see if it works for you. The forum may be able to help you with some C# coding when the time comes.
I think very few block users employ this ranking condition, so you might uncover a few WL bugs in the process. Those interest in ranking stocks within a dataset most likely employ C# and PreExecute because you can do more tricks with that approach.
---
I have zero experience with Blocks, but I can help with PreExecute and C# coding.
Glitch: Thanks for having realized the Power operator in version 169's MathIndOpXXX functions!
Superticker: Thank you very much for the information and the motivation!
Superticker: Thank you very much for the information and the motivation!
Hello, I now tried out "PreExecute" for a very simple strategy (based on just one RSI) as a test. So, instead of verifying if the criterion (only consisting of an RSI) is matched in the "Execute" method, I check that in "PreExecute" and then save "1" or "0" in the "UserData" field. "Execute" then just looks into this "UserData" field and just considers the strategy if it finds "1" there.
Is this the correct approach? I have to say that optimization is much slower with this than before. But wouldn't such a step be required, because if I only have all the possible symbols in "PreExecute" without knowing which one would match the strategy criteria, a ranking would not make much sense, right?
Is this the correct approach? I have to say that optimization is much slower with this than before. But wouldn't such a step be required, because if I only have all the possible symbols in "PreExecute" without knowing which one would match the strategy criteria, a ranking would not make much sense, right?
QUOTE:
So, instead of verifying if the criterion (only consisting of an RSI) is matched in the "Execute" method, I check that in "PreExecute" and then save "1" or "0" in the "UserData" field.
Doing this reduces the PreExecute approach to work like using Weights so the trade is all or nothing. The whole point of PreExecute is to sort all the stocks by their trading opportunities (merit metrics) on a bar-by-bar basis, then pick the top contenders to trade out of that sort until your capital (cash) runs out so you're fully invested with the top merit metrics for that specific trading bar. If you're not willing to do that, then just stick to Weights like you were doing. As you pointed out, Weights executes faster and you avoid all that PreExecute comparison/sorting for each individual bar.
I'm confused why you just don't use the approach cited in Post #9 for ranking. Then you don't have to worry about coding PreExecute in C#.
UPDATE
QUOTE:
... if I only have all the possible symbols in "PreExecute" without knowing which one would match the strategy criteria,...
So we are selecting stocks from the dataset using two (not one) unrelated criteria. The PreExecute ranking criteria is only selecting based on how one stock compares with all others in the dataset--nothing more. That doesn't mean, however, this is a good time (or bar) to buy that specific stock.
Now when we get to the Execute{block}, we answer that second question. Is this bar a good time to buy this highly ranked stock?
So what's going on in PreExecute is a separate issue from what's going on in Execute. The answer to both these criteria has to be "yes" before we pull the trigger in Execute with a PlaceTrade.
Hi Superticker,
thank you for your answer. I understand, the real checking if the strategy criteria are fulfilled happens in "Execute()".
"PreExecute()" can be used to compare the shares beforehand, rank them, or sort them (out).
So, once you created your strategy and you have her logic ready in "Execute()", you try to set up some sorting / ranking criteria which improve the performance. I guess that would be an approach, I would take (on learning this).
As I see it, the difference is that in "PreExecute()" you can access all the stocks which could be bought while in "Execute()" you are checking the criteria only for a single stock. For sure you can set a weight there, but you cannot say something like: "I want to buy this only, if all other stocks I buy are from different sectors." But I don't know if I am right (or if there is also a way to do this in "Execute()").
Thank you also for showing me this ranking feature which only uses building blocks!
As for me: The goal I want to achieve now is - and I think it can be done solely in "Execute()": To not only decide there, if a stock meets the criteria or not (TRUE or FALSE). I would like to generate a score - e.g. 1 = "meets the criteria", 2 = "not only meets the criteria, but shows especially good prospects".
And then, if the score is 2, I invest more into that purchase - maybe on margin. That is what I want to go for now and the goal would be to achieve a higher APR while the maximum drawdown stays the same.
But I am super interested in all the C# opportunities (for the future) and thus very happy to have learned from you the additional possibilities which "PreExecute()" offers.
Thank you and best regards!
Werner
thank you for your answer. I understand, the real checking if the strategy criteria are fulfilled happens in "Execute()".
"PreExecute()" can be used to compare the shares beforehand, rank them, or sort them (out).
So, once you created your strategy and you have her logic ready in "Execute()", you try to set up some sorting / ranking criteria which improve the performance. I guess that would be an approach, I would take (on learning this).
As I see it, the difference is that in "PreExecute()" you can access all the stocks which could be bought while in "Execute()" you are checking the criteria only for a single stock. For sure you can set a weight there, but you cannot say something like: "I want to buy this only, if all other stocks I buy are from different sectors." But I don't know if I am right (or if there is also a way to do this in "Execute()").
Thank you also for showing me this ranking feature which only uses building blocks!
As for me: The goal I want to achieve now is - and I think it can be done solely in "Execute()": To not only decide there, if a stock meets the criteria or not (TRUE or FALSE). I would like to generate a score - e.g. 1 = "meets the criteria", 2 = "not only meets the criteria, but shows especially good prospects".
And then, if the score is 2, I invest more into that purchase - maybe on margin. That is what I want to go for now and the goal would be to achieve a higher APR while the maximum drawdown stays the same.
But I am super interested in all the C# opportunities (for the future) and thus very happy to have learned from you the additional possibilities which "PreExecute()" offers.
Thank you and best regards!
Werner
QUOTE:
"PreExecute()" can be used to compare the shares beforehand, rank them, or sort them (out).
PreExecute is used the compare stocks with each other on a bar-by-bar basis. For example, you may only want to consider high movers in Execute, so you sort out all the high Volume stocks in PreExecute on a bar-by-bar basis so the stocks presented in Execute are only these high movers. The goal in this example is to put your cash where it's going to make the biggest difference quickly (i.e. minimizing long term drawdown).
I think you'll find C# will give you much more capability, but there is a steep learning curve initially.
OK, thanks for your support. It is interesting that you are writing you want to cut out the high volume stocks as I made the experience that high volume stocks perform better with my strategy than low volume stocks. Or do you mean stocks which recently have a higher volume?
Best regards
Werner
Best regards
Werner
QUOTE:
I made the experience that high volume stocks perform better
That's correct. We want PreExecute is target and select high volume stocks in this example because they are movers.
It's that selection (that sorted List<BarHistory> of stocks created in PreExecute) that's then examined closer for trading by Execute. If the price is going up with high volume, then Execute should Buy. If the price is going down with high volume, then Execute should Sell. Stocks with low volume are not included in the trading List<BarHistory> passed on to Execute for trading.
QUOTE:
do you mean stocks which recently have a higher volume?
You can play it either from the most recent bar or the last couple bars for volume. That all depends on how you write your PreExecute sorting criteria. Trend is important.
There are a number of PreExecute/Execute C# code examples posted to the forum you can study that do different and interesting things. Search for them.
---
I get the impression that the documentation for PreExecute is not clear. But I think it is if you study the PreExecute code examples and you understand the program flow of C#, then you'll understand the PreExecute process better.
Thank you very much, Superticker!
Your Response
Post
Edit Post
Login is required