I have also tested to include this code in my strategy signal as a condition:
Portfolio_CurrentEntries < 10
Unfortunately when several signals appear at the same day the strategy applies them all (if it is less than 10 signals in market the day before) - which means that in reality it can be a lot more positions than 10 iin the market simultaneously.
you will likely have to evaluate the number of signals that want to enter at the current date within the Money Management signal and block those that you don't want to get filled. Otherwise there wouldn't be a way to stop the entries anymore.
Something along the line of the below should work, but it will require some programming:
1. When the entry conditions in your signal are true, send a value (+1 for example) to the money management signal.
2. If the conditions are not true, send a value of 0 for example.
3. In the money management signal you'd block all entries first. Then you
can loop over all symbols in the portfolio and check how many individual signals want to enter.
One thing to decide here for you would be how to handle situations where more signals want to enter than the number of open positions you want to allow i.e. do you deal with that on a first come first serve basis or do you want to apply a ranking. If it's a ranking, the ranking would have to be computed in the individual signal and the result send to the money management, too.
4. Depending on the above method you choose, you'd either allow the entries for the symbols until you allowed number of positions is reached. If you apply a ranking you'd gather the ranking values for all symbols that want to enter in step 3.. Once you have all, sort them and let only the top (or bottom or what ever your ranking is) X symbols pass. Where X is the number of positions that can still be filled i.e. Max allowed positions - current open positions.
When I say send to the money management this involves the special portfolio reserved words that start with pmm_ and pmms_ and the help files provide a good start on these. You might also want to explore the three build in money management signals together with the PDF that explains them in depth. This will help a lot.
The following user says Thank You to ABCTG for this post:
The issue is how to get the variable to change - so that it adds "1" to the "pmm_set_my_named_num" everytime a new position enters the market and at the same time subtracts "1" from the "pmm_set_my_named_num" everytime a position closes.
How do I do that?
Thanks in advance.
The following user says Thank You to Gabriel123 for this post:
you are welcome. By the way you can show your appreciation for a post on futures.io by clicking the "Thanks" button next to it.
As a general tip and in case you don't do that already, I'd suggest to start commenting your code. This will make your life a lot simpler down the road. Imagine going back to a code you wrote month or years ago - without comments it will take you so much longer to find your way around again. This can also help you finding errors in your code, when your comment says this part should do xyz and when you compare the code you find that it does in fact uvw.
I don't understand why you'd want to add or subtract values to a variable that you send with pmm_set... - in my opinion it would be less error prone to only have the signal code change this value and have the money management signal read those values only.
Why did you add this code snippet, that blocks all further entries when you are in at least one position?
From your MM code it appears you might want to add the following:
1. Before you loop over all signals, check how many are in positions already. Your code already contains the array
for that, but it seems you strapped this part. You can look into the three build in Portfolio Trader examples in Multicharts, at least one of them demonstrates how to do that.
2. Now you can compute how many positions you have and arrive at a number of how many you still want to allow.
3. You will most likely need two loops here. During the first loop check the symbols that want to enter (you already do that) and check if they are already in a position (you'd need to add that part). If they want to enter and are not yet in a position, save the strategy index number in an array (which you need to create, and clear each time before you start the loop).
4. In you second array you need to loop through the array that holds the symbols that want to enter and only allow the number of positions that are still free (which is what you computed under 2.). If there are less symbols to enter in the array than allowed positions, there would be no need to filter them. If there are more symbols than "free spots" you need to come up with code to handle this situation i.e. only allow X out of the total number that wants to enter - for example either allow them on a first come, first served base or apply a ranking so you can decide which to prefer.
The following 2 users say Thank You to ABCTG for this post:
The part I have added in the code since last post should do this I think.
I have checked throught all three example MM codes in Multicharts but I still have a hard time trying to create code for these steps:
the task you are trying to accomplish is definitely a bit more complex and depending on your level of programming experience can give you "a hard time" for sure.
You are dealing with "advanced" concepts in Multicharts here and someone without a solid foundation of the basics (speaking in general terms here and not geared towards
you, as I don't know your programming experience in Multicharts) might run into problems here easily.
Regarding the points, you already have the most part for 2. covered (although only for long positions).
Doesn't the variable inLong hold the number of long positions you are in at the moment?
If that is the case and as you know you want to enter 10 positions at max (which I'd suggest to make an input), you should be able to compute how many spots are still left.
Now you can start with 3.. Create the array that holds the strategy index numbers for the symbols to enter and build
the first loop as described:
Last edited by ABCTG; August 4th, 2016 at 04:57 AM.