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.
Size:
Color:
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.
Size:
Color:
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.
Size:
Color:
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.
Size:
Color:
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?
Size:
Color:
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
Size:
Color:
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.
Size:
Color: