- ago
Hello,

I'm new to WL, and writing my 1st program,

I have several long position, for each, I entered a stop loss transaction,
"Transaction t = PlaceTrade(bars, TransactionType.Sell, OrderType.Stop, slVal, "sl");"
and then set the Quantity, "t.Quantity = double.MaxValue;"

But the stop-loss only close the last long position rather then all long positions.

What can be the problem ?

Thanks shenitz
0
261
Solved
7 Replies

Reply

Bookmark

Sort
- ago
#1
Why would you set .Quantity to double.MaxValue, and what it has to do with closing a position? .Quantity is usually set when you open a position. You should close each position. What's the full code?
0
Glitch8
 ( 11.36% )
- ago
#3
This is for closing a position not opening one.

The strategy holds multiple long positions and the poster wants to close them all at once.
1
Cone8
 ( 5.94% )
- ago
#4
Tried it.
It appears that sometimes there's a problem exiting multiple positions with a single order in a backtest. We'll call it a bug.

fwiw, you can assign the open position quantity precisely like this -
CODE:
t.Quantity = GetOpenPositionQuantity(bars.Symbol, PositionType.Long);

But if it weren't for the bug, double.MaxValue would work too.
0
Cone8
 ( 5.94% )
- ago
#5
The bug is that if you assign Transaction.Quantity for an exit signal, the stop will not trigger properly unless it is first placed on the bar that would trigger the order.

We'll work on that for Build 67.
0
- ago
#6
Thanks for the replies.

The GetOpenPositionQuantity didn't help for the stop-loss transaction,
but I used it for my work around, by manage the stop-loss directly in the program and using sell market transaction instead,
its not expertly same results but close enough for work around.
0
Cone8
 ( 5.94% )
- ago
#7
It's all fixed for Build 67. When that's available (next week?) you'll be able use your original code. Sorry for the trouble and thanks for reporting!
0
Best Answer

Reply

Bookmark

Sort