Limit nr of positions in portfolio! - MultiCharts | futures.io
futures io futures trading


Limit nr of positions in portfolio!
Started: by Gabriel123 Views / Replies:379 / 8
Last Reply: Attachments:0

Welcome to futures io.

Welcome, Guest!

This forum was established to help traders (especially futures traders) by openly sharing indicators, strategies, methods, trading journals and discussing the psychology of trading.

We are fundamentally different than most other trading forums:
  • We work extremely hard to keep things positive on our forums.
  • We do not tolerate rude behavior, trolling, or vendor advertising in posts.
  • We firmly believe in openness and encourage sharing. The holy grail is within you, it is not something tangible you can download.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.


You'll need to register in order to view the content of the threads and start contributing to our community. It's free and simple, and we will never resell your private information.

-- Big Mike

Reply
 
Thread Tools Search this Thread
 

Limit nr of positions in portfolio!

  #1 (permalink)
Elite Member
Stockholm
 
Futures Experience: Intermediate
Platform: ProRealTime
Favorite Futures: DAX
 
Posts: 39 since Jul 2015
Thanks: 6 given, 3 received

Limit nr of positions in portfolio!

Hi!

I am looking for a very simple Money Management script that limits the number of open positions simultaneously in a portfolio to max 10.

This is for a swing trading portfolio of stocks, meaning the resolution is daily bars, not intraday.

Let's just say the strategy code is:
_________________

If RSI(c,2) < 5 AND C > Average(C,200)
then buy next bar at open;

If RSI(c,2) > 65
then sell next bar at open;
_________________

What would the money management signal be and what additions need to be done in the strategy signal?

Thanks in advance!

Reply With Quote
 
  #2 (permalink)
Elite Member
Stockholm
 
Futures Experience: Intermediate
Platform: ProRealTime
Favorite Futures: DAX
 
Posts: 39 since Jul 2015
Thanks: 6 given, 3 received

I read this post: https://futures.io/multicharts/35935-portfolio-trader-set-max-open-position-4.html#post523433
But it doesn't work at all for me.

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.

Reply With Quote
 
  #3 (permalink)
Elite Member
Hamburg Germany
 
Futures Experience: Advanced
Platform: Multicharts, Tradestation, Multicharts.NET, NinjaTrader, MetaTrader
Broker/Data: DTN IQ
Favorite Futures: ES
 
Posts: 1,260 since Apr 2013
Thanks: 201 given, 711 received



Gabriel123 View Post
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.

Gabriel123,

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.

Regards,

ABCTG

Reply With Quote
The following user says Thank You to ABCTG for this post:
 
  #4 (permalink)
Elite Member
Stockholm
 
Futures Experience: Intermediate
Platform: ProRealTime
Favorite Futures: DAX
 
Posts: 39 since Jul 2015
Thanks: 6 given, 3 received

Thanks a lot for your reply, ABCTG.

I have been able to come up with a signal base and MM signal that limits the number of position simultaneously to 1. But not to 10. Most of the help I got from this thread: https://futures.io/multicharts/35935-portfolio-trader-set-max-open-position.html

Signal base:
 
Code
                            
input:arg(true);

If 
RSI(c,2) < AND Average(C,200then begin

if (arg truethen pmm_set_my_named_num("test",1);

buy next bar at open;

end;

If 
RSI(c,2) > 65 then begin

if (arg truethen pmm_set_my_named_num("test",0);

sell next bar at open;

end
MM signal:
 
Code
                            
var:idx(0),count(0);

array:
strategyIndexes[](0);

count 0;

    
pmms_strategies_deny_entries_all;

for 
idx 0 to pmms_strategies_count -1 begin

    
if ( pmms_get_strategy_named_num(idx,"test") = and count 0then begin

    count 
1;

    
pmms_strategy_allow_entries(idx);

    
pmms_set_strategy_named_num(idx,"test",0);

    
end;

end;

if 
pmms_strategies_in_positions_count(strategyIndexes) >= 1 then

pmms_strategies_deny_entries_all


Reply With Quote
 
  #5 (permalink)
Elite Member
Stockholm
 
Futures Experience: Intermediate
Platform: ProRealTime
Favorite Futures: DAX
 
Posts: 39 since Jul 2015
Thanks: 6 given, 3 received

Futures Edge on FIO

What value do you place on the webinars on FIO?

 
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.

Reply With Quote
The following user says Thank You to Gabriel123 for this post:
 
  #6 (permalink)
Elite Member
Hamburg Germany
 
Futures Experience: Advanced
Platform: Multicharts, Tradestation, Multicharts.NET, NinjaTrader, MetaTrader
Broker/Data: DTN IQ
Favorite Futures: ES
 
Posts: 1,260 since Apr 2013
Thanks: 201 given, 711 received

Gabriel123,

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?
 
Code
if pmms_strategies_in_positions_count(strategyIndexes) >= 1 then

pmms_strategies_deny_entries_all;

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.

Regards,

ABCTG

Reply With Quote
The following 2 users say Thank You to ABCTG for this post:
 
  #7 (permalink)
Elite Member
Stockholm
 
Futures Experience: Intermediate
Platform: ProRealTime
Favorite Futures: DAX
 
Posts: 39 since Jul 2015
Thanks: 6 given, 3 received

Thanks for your response ABCTG.

This was not simple.

This is my MM code at the moment:

 
Code
                            
var:
idx(0),
count(0);

array:
strategyIndexes[](0);

pmms_strategies_deny_entries_all;

variablesinLong(0);
arraysstrategiesLong[](-1);
inLong pmms_strategies_in_long_count(strategiesLong);

count 0;

    
pmms_strategies_deny_entries_all;

for 
idx 0 to pmms_strategies_count -1 begin

    
if ( pmms_get_strategy_named_num(idx,"test") = and count 0then begin

    count 
1;

    
pmms_strategy_allow_entries(idx);

    
pmms_set_strategy_named_num(idx,"test",0);

    
end;

end;

if 
pmms_strategies_in_positions_count(strategyIndexes) >= 10 then

pmms_strategies_deny_entries_all


Reply With Quote
 
  #8 (permalink)
Elite Member
Stockholm
 
Futures Experience: Intermediate
Platform: ProRealTime
Favorite Futures: DAX
 
Posts: 39 since Jul 2015
Thanks: 6 given, 3 received


ABCTG View Post
Gabriel123,
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.

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:


ABCTG View Post
Gabriel123,
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.


Reply With Quote
 
  #9 (permalink)
Elite Member
Hamburg Germany
 
Futures Experience: Advanced
Platform: Multicharts, Tradestation, Multicharts.NET, NinjaTrader, MetaTrader
Broker/Data: DTN IQ
Favorite Futures: ES
 
Posts: 1,260 since Apr 2013
Thanks: 201 given, 711 received

Gabriel123,

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).
 
Code
inLong = pmms_strategies_in_long_count(strategiesLong);
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:

Quoting 
3. 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).

Regards,

ABCTG


Last edited by ABCTG; August 4th, 2016 at 03:57 AM.
Reply With Quote

Reply



futures io > > > > Limit nr of positions in portfolio!

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)
 

Spring Grains Outlook w/Sean Lusk @ Walsh Trading

Elite only

FIO Video Journal Challenge featuring NinjaTrader ($2,000+ of prizes)

April

Process above all else w/Anthony Crudele @ Futures Radio Show

Elite only

Machine Learning - Quantitative Trading w/Martin Froehler @ Quantiacs

Elite only

Market Dynamics w/Peter Davies @ Jigsaw Trading

Elite only

Ask Me Anything w/Patrick Rooney @ Trading Technologies

Apr 18

Ask Me Anything w/FuturesTrader71

Apr 19

Machine Learning w/Kris Longmore

Elite only

Market Analysis w/Dave Forss

Apr 25

Introducing iSystems with Stage 5 Trading

Apr 27
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple strategies / limit positions hawks67 NinjaTrader Programming 2 January 18th, 2015 11:28 PM
Hedging currency risk in short stock positions (any different from long positions?) ikeaboy Currency Futures 9 May 15th, 2014 04:00 PM
Limit Up Limit Down Question MV007 Traders Hideout 19 April 6th, 2014 05:46 AM
OCO orders, set Limit and Stop Limit automatically rice0721 ThinkOrSwim 4 January 12th, 2014 12:02 PM
Flatten All Positions togier NinjaTrader Programming 11 October 13th, 2012 01:55 AM


All times are GMT -4. The time now is 02:49 AM.

no new posts
Page generated 2017-03-27 in 0.16 seconds with 19 queries on phoenix via your IP 54.159.145.68