IsLastPositionActive doesn't work in Auto-Trading
Author: kazuna
Creation Date: 5/5/2009 10:15 PM
profile picture

kazuna

#1
I have a simple test code below and it works fine in backtest mode as expected. However, if I run it in Auto-Trading mode, it places buy order at every single bar but no sell order at all. Apparently IsLastPositionActive is reset to false every time when new streaming data comes in and this code is executed. I also looked at LastPosition but it is also reset to null. Have anyone ever seen any problem like this? I tested this code with paper account in one minute scale.

CODE:
Please log in to see this code.

profile picture

Cone

#2
The problem is the logic in your script, which is to buy on the last bar (only), and that's changing each time a bar is added.

Look, it's fine to trigger a test using bar numbers, but a repeatable Trading Strategy can't be based on bar numbers alone.
profile picture

kazuna

#3
Probably I got mixed up with the screener sample in the document.
Now I understand much better how WL5 manages the positions.
Thanks for your quick reply.
profile picture

Cone

#4
Yes, a Screen signals if a filter is "true" on the current (last) bar only, and that's different from a Trading Strategy which processes trading signals for all bars in the chart.
profile picture

kazuna

#5
I got one additional question.

I fixed the strategy and restarted it during market session. It ran fine but it never generated a buy alert and kept generating a sell alert even if the buy order wasn't placed early in the trading session because the strategy was not running at that time when the buy order was supposed to happen.

What's the best way to deal with this ghost buy order?
profile picture

Eugene

#6
An alert not generated could be a sign of using bar (instead of bar+1) for order placement. Is this the case?

For more details: Bars, Loops, and Bar + 1
profile picture

kazuna

#7
Never mind. I just figured out that the ghost buy order is gone once the next sell order is placed even if there is no position in the account so that the next real buy order is placed correctly.
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).