Add To Position Code
Author: andyk364
Creation Date: 4/20/2009 5:31 AM
profile picture

andyk364

#1
Hello,

Lets say I've entered a long position on a MA crossover and wish to add to my position as the price increases -

1.Is it possible to express the following in wealthscript code?

Add to my position every time the price goes up by, say, 10% of the entry price, up to a maximum number of, say, 4 times.
eg. entry @ 100
add to position @ 110
add to position @ 120
etc. (maximum 2 more times)

2. Continuing on from the above, is it possible to express the following in wealthscript code?

Lets say I have a StopLoss in place of 5% below entry price, move this StopLoss up 10% every time I add to my position.
eg. entry @ 100
stop @ 95
add to position @ 110
move stop up to 105

3. Finally, would it be possible to choose the size of the position added?
eg. same position size as orignal entry
or, say, 50% of previous position size

If someone could provide the code for any of the above scenario's, I would be most grateful.

profile picture

Eugene

#2
QUOTE:
3. Finally, would it be possible to choose the size of the position added?

Sorry, that's an enhancement for one of the future builds of WL5 (like 5.5 - Robert will correct me).
QUOTE:
1.Is it possible to express the following in wealthscript code?

CODE:
Please log in to see this code.
profile picture

andyk364

#3
Hi,
Thanks for the code.
I'm trying to 'decipher' it and have a couple of questions.
1. Should it run as it is or would I insert the relevant sections into my strategy? - at the moment I'm getting a Runtime Error even though it's triggering buy/sell signals.
2. The code triggers an initial Buy order after every 100 bars (and exits the entire position after every 100 bars) , however, the 3 additional orders generally all seem to occur roughly within a few bars of each other - I'm not understanding what criteria is actually triggering the additional positions?

I hope I've explained my concept properly - just to recap,
eg
Entry @ 100
Add @ 110
Add @ 120
Add @ 130

Excuse my ignorance, and many thanks for your help.


profile picture

Eugene

#4
1. Whenever you get an error, please post its details.

2. Oops, now I see what you mean. Here's the amended code:
CODE:
Please log in to see this code.

The code is only an example.
profile picture

andyk364

#5
Hi,
Still getting the runtime error (tried to copy & paste the long message but couldn't), however, I found the following adjusted code works without errors and also gives me much better entry signals:
CODE:
Please log in to see this code.


As you will see I have changed the BuyAtLimit to BuyAtClose orders & removed the "+ 1" and "limitPrice" from within the brackets.

A couple more questions please -
1. At the moment, a buy order is created at the close of the bar where the price has gone up 10% - ideally I would want to enter at the exact price of the 10% gain. Is this possible? (I'm guessing this is what you was trying to achieve with the limit order but it wasn't working in that way)
2. Referring back to my original post (Question 2), is it posible to code the stoploss scenario described?

Thank you very much for your help this far.
profile picture

andyk364

#6
Hello,
Continueing from above, I have tried to incorporate the relevant code into my strategy (simple MA crossover with stoploss) but failed miserably.
Please could you show me how its done?
CODE:
Please log in to see this code.
profile picture

Eugene

#7
I got your point.

Entries are made now when the price has gone up 10%, and the trailing stop scenario has been integrated:

CODE:
Please log in to see this code.
profile picture

andyk364

#8
PERFECT!
That seems to do exactly what I was after.
Eugene, thank you very much.
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).