Binary (intermarket) trading strategy help
Author: seannieboy71
Creation Date: 5/9/2014 1:48 PM
profile picture

seannieboy71

#1
I am trying to create a trading strategy that swaps between long positions in two symbols based upon a signal. When the signal is positive, the strategy should sell the long position in symbol A and take a long position in symbol B. When the signal is negative, the strategy should sell the long position in symbol B and take a long position in symbol A.

I have created a system that I thought should accomplish this, but it does not always take the long position in stock A when it sells stock B and vice versa.

My code is shown below. Any help would be appreciated.

seannieboy71

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

Eugene

#2
By looking at the familiar lines at the beginning of your code, I see that for some reason you took the original "Pairs Trading" strategy from the Intermarket folder...
CODE:
Please log in to see this code.

...and edited it to the extent that it broke, removing all calls to SetContext etc. Pair trading is typically accomplished through making a call to SetContext. Restore the script's skeleton as it originally was, execute it in Single Symbol mode, and it should work.
profile picture

seannieboy71

#3
I actually just copied those few lines because I liked setting up the symbols as variables. The rest was written from scratch, so it just started out broken.

The write up for "Pairs Trading" says that it takes a long position in one stock and a short position in the other stock simultaneously. I just want to flip back and forth between two stocks.
profile picture

Eugene

#4
QUOTE:
I actually just copied those few lines because I liked setting up the symbols as variables. The rest was written from scratch,

Okay, then I take my words back. Please give this a try:

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

seannieboy71

#5
Eugene, Thanks for the help. It does a much better job now.