Two strategies place exactly same order
Author: kazuna
Creation Date: 5/19/2009 5:10 PM
profile picture

kazuna

#1
I had two different strategies running on paper account this morning and both two strategies happened to place the exactly same amount at the exactly same bar for the same stock. Both two orders were placed but only one of them was closed later. Apparently once one strategy closed one position, the other strategy thinks the position was closed even if there is another position is still active.

I guess I had to order different amount so that two strategies can identify its own position?
profile picture

Cone

#2
QUOTE:
I guess I had to order different amount so that two strategies can identify its own position?
Absolutely not.

I'm pretty sure we've discussed this, but Strategies in WL5 don't care about what's in your (or paper) account. They run theoretically, generating Alerts based on theoretical positions picked up during script execution.

So, the statement, "the other strategy thinks the position was closed" doesn't make any sense since it's not possible for a strategy to "think" that way.

Now, if the second script created an exit Alert that was not filled, then it's probably due to one of the limitations (or deficiencies) of the Paper Provider.
profile picture

kazuna

#3
QUOTE:
They run theoretically, generating Alerts based on theoretical positions picked up during script execution.

What if two scripts generated exactly same enter alert and later first script generated an exit alert? The second script can see the theoretical position and can generate an exit alert?

QUOTE:
Now, if the second script created an exit Alert that was not filled

No. The second script didn't generate an exit alert but the position was still active in paper account. It's like if IsLastPositionActive in the second script became false once the first script created an exit alert.
profile picture

Cone

#4
QUOTE:
The second script can see the theoretical position and can generate an exit alert?
Gosh, no. A script can only see what it's doing for the symbol that it's running on. So, clearly it can't generate Alerts based on Positions created from other scripts (unless you really go WAY out of your way to make that happen).

QUOTE:
It's like if IsLastPositionActive in the second script became false once the first script created an exit alert
I hope I've cleared up any doubt that scripts don't crosstalk. If IsLastPositionActive is false, it's because there's no active position at that time.

If you want to pursue it, post the script, identify the data, data loading and sizing setup, and we'll walk through it.
profile picture

kazuna

#5
QUOTE:
So, clearly it can't generate Alerts based on Positions created from other scripts

No no. Both two scripts created the exactly same position at the same bar for each then one script generated an alert but second script didn't generate an alert.

It was like this:

Script 1 - enter position (AA x 1000) at 10:00
Script 2 - enter position (AA x 1000) at 10:00
Script 1 - exit position (AA x 1000) at 11:00
Script 2 - supposed to exit position at 12:00 but didn't generate alert
profile picture

Cone

#6
I can't tell you what your script does or should have done because I don't have its code. (At least I don't think I do.)

I can tell you that programs don't make errors, only their programmers do. However, there's always a possibility of a bug in the WealthScript engine, but it's much more likely the error is yours ;)
profile picture

kazuna

#7
I tested this scenario again today and apparently this issue happens but only when stop loss alert is generated while paper trading.

So I think this is another instance of the paper provider issue that I reported a while ago on the other thread.
profile picture

Cone

#8
If it's not generating an alert, then it can't be the same thing.

Are you saying now that actually the Alert is occurring, the order is placed, the exit shows up in the chart, but it's just not filled in the Paper Account? That's a different story altogether and has nothing to do with the script's logic.
profile picture

kazuna

#9
QUOTE:
Are you saying now that actually the Alert is occurring, the order is placed, the exit shows up in the chart, but it's just not filled in the Paper Account?

I think so. The reason why I thought the Alert was not occurring was because there wasn't "Status = Filled" message logged on the Orders tool. When Alert is generated, previous order is canceled and then new order is activated. However, when this paper provider issue occurs, the active order is just gone without being replaced with filled order. So it looked to me if there wasn't an alert generated. Does this make sense?
profile picture

Cone

#10
Yes it does.

When the script theoretically fills the order, it no longer processes the exit logic. So, when the Orders tool doesn't get a "refresh" of the Alert at the end of the interval, it cancels the order.
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).