2 questions
1) This is probably a simple questionWhy 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.
Size:
Color:
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?
Size:
Color:
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).
Size:
Color:
>>(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
Size:
Color:
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.
Size:
Color:
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
Size:
Color:
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.
Size:
Color: