PosSizer: Limit number of positions depending on indicator value
Author: Mockasino
Creation Date: 6/30/2013 2:34 AM
profile picture

Mockasino

#1
Hello all,
Is there a possibility to limit dynamically the number of short/long trades dependig on Indicator value of a symbol, maybe an index?
Is it possible with .Tag property in the strategy code but without programming an own custom positionsizer?
Does anybody has an idea?

Thanks a lot
profile picture

Eugene

#2
Hi Christian,

It might be possible with the Priority Adjustment PosSizer. You could reject trades with Position.Priority above/below some threshold (set Position Size = 0%) or choose some normal position size for the rest.

If it doesn't seem to do the trick, please clarify your position sizing rules in greater detail (with an example).
profile picture

Mockasino

#3
Hi Eugene,
Thanks a lot for the answer.
I am not sure if that solve my problem. I will check it.
Concretely i d like to do the following:
During the strategy i want to check the RSI of the DowJones.
If this reaches certain values i would limit the position size or number of trades
in short/long direction.
For example: if the rsi is over a certain level i want to limit the allowed number of trades to 2 in short
and maybe just 1 in long direction.
So 2 short entries ( from all relevant entries with highest priority) and 1 long entry should be done.

Maybe At other RSI values, just the number of trades should be limited, doesnt matter if all trades are in the same
direction.
I hope it is more clear to you.

Regards
Mockasino
profile picture

Eugene

#4
Thanks, it's clear now. I don't think it's directly possible without a PosSizer. It's quite easy to control the position size with the Priority Adjustment: as I've said, just assign 0% to entries with particular priority thresholds you want to filter out when the RSI gets above/below some level.

However, limiting the number of trades based on an indicator value in a mult-symbol portfolio backtest doesn't seem possible using off-the-shelf PosSizers. It boils down to assigning the RSI value to the Position.Tag property in your Strategy, reading that value in PosSizer, and acting accordingly. Here's a quick & dirty incomplete example of coding the heart of the PosSizer (SizePosition method) on-the-fly:

CODE:
Please log in to see this code.


If you're not fluent with extension development, perhaps I could think of adding it to MS123 PosSizers. Let me know if assistance is required.
profile picture

Mockasino

#5
Hi Eugene,

thanks a lot for your great support.
I havent implemented a custom possizer until now, but i will try that.

When i have problems, i feel free to ask you.
Is that ok for you?

But never the less maybe this kind of position sizing can be interested also to other users.
With the TAG-property the user has the possibility to define any value in his Strategy-code
and depending on that he is able to set the possible number of trades in short and/or long direction.
So with the TAG-logic the user is independent of a special indicator (like RSI) . He can create his own logic.

So if you think of adding it to MS2123,what would that mean regarding timeline.
i suspect i need it earlier. So i will try the development.

Thanks a lot

Mockasino
profile picture

Eugene

#6
Since your idea is a filter, not some new position sizing, the ideal slot in MS123 PosSizers would be Position Options. But it'd certainly take some time to integrate it into the existing design.

Considering this and your time pressure, building a ready-made PosSizer might be a solution. Let me work on it next week, compile it and attach to a forum post. When it's ready, you'd clear the "Downloaded From the Internet" bit from the downloaded file (or Wealth-Lab will never load it), place the DLL into Wealth-Lab's main folder under Program Files, and restart. And after you play with it, you tell me if it fits the bill or some enhancement is required.
profile picture

Mockasino

#7
That would be great.
Yes i think in Positions Options it would be the right place.
Important is the relation between the Tag-value and the combination of number of short/long trades
For example: if tag-value is > 10. ==> number of long : 2, number of short entries: 3

By the way i just managed it to implement a custom possizer and included your code from above.
The problem is now,that i get Alerts, but no trades are generated
So there is no trade., just open Alerts.
The size of alerts is defined in my own Sizer, so i see that the coding is working.
When i change to another MS123.PosSizer trades are generated.



Do you have an idea?

Regards
Mockasino

P.S. Im working with ShardDevelop,but i dont jump in the breakpoits when i want to debug it.
Is this issue mybe known to you?
profile picture

Eugene

#8
QUOTE:
So there is no trade., just open Alerts.

I don't know what you're doing wrong but my code works correctly. As you can see on the picture, a dummy long-only system in a multi-symbol backtest never goes above 2 open positions. I'm attaching the complete VS2012 solution for you to experiment with.



QUOTE:
P.S. Im working with ShardDevelop,but i dont jump in the breakpoits when i want to debug it.
Is this issue mybe known to you?

Sure. At least 3 reasons come to mind:

1. First and foremost, you've not attached to process: What does it mean to attach to process
2. You did not place the companion PDB files into the Wealth-Lab main folder.
3. Another (less likely but still possible) cause might be an error in PDB files or a mismatch between DLL and PDB. Just rebuild for Debug and place all the files in the WL6 main folder.

On a related note, I recommend Visual Studio 2012 Express for Desktop.
profile picture

Mockasino

#9
Hi Eugene,
thanks a lot. I forgot copying the PDB-file into the WL folder.
Now i jump into my possizer.
The next days i will play around and implement the logic i need.

I will give you feedback.

Regards
Mockasino
profile picture

Mockasino

#10
Hi Eugene,

i have tested the coding and enhanced to my requirements.

i would like to implement also the logic,that there is just one trade for a symbol at the same time.
Is it right, that i can reach this oover the possizer too?

Additionally i have an idea to let the current equity take influence on the sizer.

Is there maybe a coding example for that?

Thanks a lot in advance.

...by the way one question: are there any new WL PosSizers planned in future?

Christian
profile picture

Eugene

#11
Hi Christian,

QUOTE:
i would like to implement also the logic,that there is just one trade for a symbol at the same time.
Is it right, that i can reach this oover the possizer too?

It's easily possible. Just set up another counter, similar to int activeLong , that will count the number of open positions in a given symbol. When the Bars object of the position "p" is equal to the Bars object currently processed (it's passes as "bars" to SizePosition by Wealth-Lab), increment that counter. Down in the code when you return the size, check if the counter is >= 1 and assign size = 0.

CODE:
Please log in to see this code.


QUOTE:
Additionally i have an idea to let the current equity take influence on the sizer.

What do you have in mind?
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).