How to exit 33% of all open positions?
Author: Mouravyev
Creation Date: 11/1/2012 1:42 PM
profile picture

Mouravyev

#1
Hi!

Sorry if there has already been similiar question. I didn't manage to find such topic.

Is it possible to use partial exits in percent?
For instance,

Entries:
first position is opened after crossing over Price Channel
All further position are opened when the price goes up by 3000 points
Exits:
Once the price goes 3000 points down we should close 30% of all active positions

Here's the code:

CODE:
Please log in to see this code.


It is clear how to close all positions.
But how is it possible to close 33% of all positions?

Thank you in advance!
profile picture

Eugene

#2
Considering that your system opens multiple positions, makes sense to not complicate things with SplitPosition.

What is 33% of all open positions? Simply
CODE:
Please log in to see this code.

This gives you the number of positions to exit, or to retain:
CODE:
Please log in to see this code.


Consequently, finish your loop not before you reach the last one (0) -- but before you reach the index of the first position to retain:
CODE:
Please log in to see this code.
profile picture

Mouravyev

#3

Eugene,
QUOTE:

What is 33% of all open positions? Simply


Pardon, I forgot to mention that every new position means a specific fixed number of contracts.

For example, every time we buy 30 contracts.

Thus, for instance, we've opened 4 positions. It means that we have 120 contracts. Every time the price goes 3000 points down we sell 30% of all active positions. i.e. 40 contracts. If the price continues to go down we sell 40 contracts again. And if the price goes down one more time, we sell all the remaining contracts.


Thank you for the prompth reply!
profile picture

Eugene

#4
Kirill,

You can either use SetShareSize() in your Strategy code (which is easier), or use a PosSizer (e.g. FAQ: How to pass a value from Strategy to PosSizer for Alert sizing?).
profile picture

Mouravyev

#5
Eugene, everything's clear now!

Thank you for your help!
profile picture

pubx101

#6
I want to exit all open positions with the codes:

CODE:
Please log in to see this code.
and trades are included in the attached screenshot. When I want to sell All open positions, only positions on one symbol is sold, there still are open positions (on other stocks) left, For example, when ticker 'PCLN' is sold with 'SellAll" on 11/16/2015, the position on 'TXN' which was bought on 9/9/15 is still open until 1/8/2016. why?

profile picture

pubx101

#7
the screen shot is attached.
profile picture

Eugene

#8
QUOTE:
I want to exit all open positions

This topic is rather about exiting "33% of all open positions" which is a different subject. Position.AllPositions is a shortcut to exit all positions. If a Position isn't sold it doesn't meet the exit criteria (i.e. the CrossUnder).
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).