Selling increments of position
Author: giorgos
Creation Date: 2/7/2009 6:49 PM

#### giorgos

#1
I understand that I can control buying size by setting the percentage to buy. However when the sell condition is met each time I would like to sell 1/5 of the position held. Can you please help with how to code this. Thanks

CODE:

#### Cone

#2
Note that you can't just exit 20% of the remaining position each time (try the math). Instead, the percentage rises with each subsequent exit to get rid of a fixed position 20% of the original position as an example with 100 shares shows...

100 * 0.2 = 20
80 * 0.25 = 20
60 * 0.333 = 20
40 * 0.5 = 20
20 - last lot

Anyway, there are a few ways to do this, but here's one that uses SplitPosition to split up the original Position in 5 parts immediately. That makes it easier so that you can simply decide how many of 20% lots you want to exit when the time comes.

CODE:

In your case, you need only to exit the "LastActivePosition" in the exit logic -
CODE:

#### giorgos

#3
You are right actually every time the buy condition is met I would buy one lot (its just happens I have set each purchase at 20% of my trading capital) and if the buying condition is met with no sells I will keep adding a lot. Now if a sell condition is met I only want to sell one lot each time.

Here is my entry and exit code

CODE: