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


Limit nr of positions in portfolio!
Updated: Views / Replies:506 / 8
Created: by Gabriel123 Attachments:0

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • 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.

-- Big Mike, Site Administrator

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, 4 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, 4 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)
Market Wizard
Hamburg Germany
 
Futures Experience: Advanced
Platform: Multicharts, Tradestation, Multicharts.NET, NinjaTrader, MetaTrader
Broker/Data: DTN IQ
Favorite Futures: ES
 
Posts: 1,404 since Apr 2013
Thanks: 220 given, 799 received
Forum Reputation: Legendary



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, 4 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, 4 received

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)
Market Wizard
Hamburg Germany
 
Futures Experience: Advanced
Platform: Multicharts, Tradestation, Multicharts.NET, NinjaTrader, MetaTrader
Broker/Data: DTN IQ
Favorite Futures: ES
 
Posts: 1,404 since Apr 2013
Thanks: 220 given, 799 received
Forum Reputation: Legendary

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, 4 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, 4 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)
Market Wizard
Hamburg Germany
 
Futures Experience: Advanced
Platform: Multicharts, Tradestation, Multicharts.NET, NinjaTrader, MetaTrader
Broker/Data: DTN IQ
Favorite Futures: ES
 
Posts: 1,404 since Apr 2013
Thanks: 220 given, 799 received
Forum Reputation: Legendary

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)

July Journal Challenge w/$1100 in prizes from TopstepTrader

July
 

An Afternoon with FIO member Softsoap

Elite only

Battlestations: Show us your trading desks and win $750 in prizes

August
 

Extended Ask Me Anything w/Brett Steenbarger

Elite only

Prototyping Python Strategies (part 3) w/Ran Aroussi

Elite only

Brannigan Barrett w/Axia Futures

Elite only

Introduction to Phillip Capital futures brokerage services

Aug TBD

How Monte Carlo Analysis Can Help Your Trading w/Kevin Davey

Elite only
     

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 12:56 PM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts
Page generated 2017-07-24 in 0.19 seconds with 19 queries on phoenix via your IP 23.20.218.77