Making sure a hedge is executed
Author: sedelstein
Creation Date: 9/29/2012 5:05 PM
profile picture

sedelstein

#1
I have a pairs trading strategy I'm working on

the strategy looks for buy signals for a long position and then if able, executes a short position.
I want to make sure that I execute a long if and only if there is enough equity to also execute the short side as well.
I'm unsure how to do this. I think my code below isn't quite right.

Suggestions appreciated.

CODE:
Please log in to see this code.
profile picture

Eugene

#2
Yes, the code is not quite right because it's impossible to go back a few hours in time and purchase at market open after your limit order has triggered during the day.
profile picture

sedelstein

#3
Okay

Is there a way to make the short order trigger at the same time and also ensure there is sufficient capital for both trades.
Can you offer a suggestion other than "it won't work"?
Thanks
profile picture

Eugene

#4
Yes there is: make both AtMarket or AtClose orders.
profile picture

sedelstein

#5
Will that ensure that there is enough capital for both trades and not just one?

I want to ensure that both are executable
profile picture

Eugene

#6
Ensuring there's enough capital is not a strategy's prerogative. Your position sizing is ultimatively responsible for that. Hope that helps.
profile picture

sedelstein

#7
I had thought that when testing to see if a trade was null or not
CODE:
Please log in to see this code.


that it was checking to see if it was possible to execute the trade

I want to make sure that both are not null. Will a simple "and" do that? it's not clear to me it would because either might be possible and an "and" would return TRUE. It's not quite the same as both.
profile picture

Eugene

#8
This way your Strategy is checking that the position has been created.

As an alternative, you can enter the hedge position at close of bar+1 because it's also possible in real life:
CODE:
Please log in to see this code.

profile picture

sedelstein

#9
Ok that could work. I'll test it.

Just to make sure it actually wold work in real life, the alerts are generated for just the limit long buy.
In actual trading, will WL execute the short at close? I know there are some posts about how to do this and whether WL needs to "wake up" 1 minute or so before the close.
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).