Parabolic stops for Multiple Positions
Author: sedelstein
Creation Date: 1/13/2012 6:49 PM
profile picture

sedelstein

#1
I've written some code that uses parabolic like stops for multiple position strategies.

If a new high is hit, then like the Wilder stop, a new stop is calculated and the acceleration factor is increased

stop(t+1) = stop (t) + acceleration factor (t) * (High(t) - stop(t))

I wanted each active position to have its own set of stops. The only way I could see to do it was to keep track of each position's unique stop and acceleration factor in the .Tag property of the position.

I am new to C# and WLP. I would appreciate anyone looking at it and see if there is a more elegant solution.

Thanks for the comments

Steve

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

Eugene

#2
Nice try. First thing that hits the eye is that you're assigning a Tag to a Position that is being closed:
CODE:
Please log in to see this code.
profile picture

sedelstein

#3
Well, Like I said, I'm new to this but isn't the position only closed if the stop is hit on the next (bar+1) bar?. At this point in the loop, you are at bar. Am I fundamentally not understanding something about how WLP trades?
profile picture

Eugene

#4
Your understanding is correct, I didn't understand the logic behind that assignment at first but now am seeing it (it changes on each bar).

Here's a couple of cosmetic changes thrown in:
CODE:
Please log in to see this code.


1. ATR is an unstable indicator (WealthScript Guide > Indicators), hence:
CODE:
Please log in to see this code.

2. Parsing a string with sar and increment has been replaced with a new SAR class for better readability and ease of use.
3. Assigning a SAR to a newly created Position after verifying that it exists:
CODE:
Please log in to see this code.
profile picture

sedelstein

#5
Thanks Eugene

So a Tag can be assigned to an object. No more need for parsing.

When would
CODE:
Please log in to see this code.
not lead to a position?

Do all entries need to be qualified as in (3) in your last post?
profile picture

Eugene

#6
QUOTE:
not lead to a position?

Lack of funds in the first place.

But in your case, your code is re-assigning a new sar on each bar simply because ActivePositions.Count is less than the max_number_of_positions. It's up to you to decide if it's acceptable or not.
profile picture

sedelstein

#7
Well then I guess I am fundamentally missing something. I want to create parabolic stop for each active position. Not because I have less than the maximum number of positions allowed.

I thought I was doing it correctly because the loop is for the active positions
CODE:
Please log in to see this code.

In that loop, if a new high is hit, the acceleration factor, af, is increased for the next bar's recalculation of the stop

Additional positions are created below that loop
CODE:
Please log in to see this code.




profile picture

Eugene

#8
QUOTE:
Additional positions are created below that loop

Right, and unless you've completely loaded with positions (< 3), you're also adjusting that stop on each bar.
profile picture

sedelstein

#9
Then I guess I'm ok because that is what the code is supposed to do

1) Adjust the stop for each position for each and every bar
2) Add positions if you are not at the max

In actual testing, I'll be creating some less naive entry rules


Thanks for the help
profile picture

sedelstein

#10
Being new to C# I was wondering if there is a way to make this into a method so that I wouldn't need to include a lot of this code into each and every strategy I run.

thanks for the hint
profile picture

Eugene

#11
There are classes and methods designed to do their job. Now comes your job to wrap what's required by your own project and pack it into a class, method or custom library which you can reference in any of your strategies.
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).