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.
Size:
Color:
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.
Size:
Color:
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
Size:
Color:
Yes there is: make both AtMarket or AtClose orders.
Size:
Color:
Will that ensure that there is enough capital for both trades and not just one?
I want to ensure that both are executable
Size:
Color:
Ensuring there's enough capital is not a strategy's prerogative. Your position sizing is ultimatively responsible for that. Hope that helps.
Size:
Color:
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.
Size:
Color:
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.
Size:
Color:
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.
Size:
Color: