Multiple lots in a strategy
Author: sedelstein
Creation Date: 1/28/2011 12:43 PM
profile picture

sedelstein

#1
2 questions

1) This is probably a simple question

Why does the prepackaged strategy in WL (counter trend - ten-liner) below
CODE:
Please log in to see this code.



produce multiple positions and the following does not

CODE:
Please log in to see this code.



2) How would I add a MAE protective stop to the ten-liner code for each position entered

CODE:
Please log in to see this code.


profile picture

sedelstein

#2
Just to add,

How in general are multiple positions allowed? The scond bit of code just says add every day while above an ma and dont close them until below another one. what if I wanted to add (as an extreme example) a new position every bar while over the moving average?
profile picture

Cone

#3
The second strategy has this logic, which is mutually exclusive for processing entries and exits.
CODE:
Please log in to see this code.
In other words, if a Position is active, you're only looking to exit and the entry logic is not processed ELSE you're only looking to enter a position if none are active.

For multiple positions, entry logic is allowed to be processed even while positions are active. So if you wanted to do what you say, you have to remove the mutually-exclusive logic and add the logic you desire (which definitely should not be to add a Position for EVERY bar above a moving average, but you can do it if you really want to).
profile picture

sedelstein

#4
>>(which definitely should not be to add a Position for EVERY bar above a moving average, but you can do it if you really want to).

Yes of course, I just wanted to ensure I could generate multiple positions for the example.

so for the exits, just loop though each for my MAE stop as per the WL programming guide if I wanted to get out at no worse that 8% (in this example)

Correct?


CODE:
Please log in to see this code.



Thanks for the help and the quick response. Greatly appreciated

profile picture

sedelstein

#5
oops, key stuck

Runtime error with index out of range. Do I need to test if I have an active position first?
CODE:
Please log in to see this code.
profile picture

sedelstein

#6
I still get an error if I start the loop with
CODE:
Please log in to see this code.


Index was out of range, Must be non-negative and less than the size of the collection but I am checking to see that it's > 0 so not sure what's going on.

I'm new to c# as well but is there any way to step through the code like a traditional debugger? I'm using lots of PrintDebug statements but that's not doing the trick either
profile picture

Cone

#7
You're already looping through all the ActivePositions, so don't use Positions.AllPositions here. When you do, you're essentially setting the ActivePosition list to 0 positions, and then on the next iteration of the loop, when ActivePositions[pos] is executed, there is no "pos" left in the list to assign to Position p, which is an error.

Since you are already looping through "All Active Positions", just replace Position.AllPositions with p.
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).