Pairs trading issues

I'm running this code on a Watchlist with 2 symbols. It will not buy the second symbol with the "else" section. Any ideas? I'm using Weekly Periodicity if that matters.

OpeningTrade = Cross(MA(C,x1),MA(C,x2)) OR Status("FirstBarInRange");
ClosingTrade = Cross(MA(C,x2),MA(C,x1));

if( Name() == "GLD")
{
Buy = OpeningTrade;
Sell = ClosingTrade;

}
else
{
Buy = ClosingTrade;
Sell = OpeningTrade;
}

Search for "Status(“stocknum”) == 0" might give you some ideas

Thanks awilson I appreciate the help.

I discovered my problem and I'd like to share it for the sake of others. I needed to add the following before and after my Buy/Sell lines. Otherwise the signals were being calculated differently for each symbol.

SetForeign("GLD");
// Buy & Sell statements
RestorePriceArrays();
1 Like

Good, but next time you can elaborate in detail what you intend code to do.

Even you read the first post, code is fine doing what you wrote it to.
According to me, it appeared originally, that you wanted to take trade in other symbol with opposite signal which could be a strategy.

You can still explain your whole logic behind taking the trades in a Pair.

Yes you are correct. I started with a trading system developed for one symbol. I was looking for a way to invest in a 2nd symbol using opposite signals for the purpose of make additional gains when the system was not invested. In other words, I wanted to bring Exposure to 100% with the 2 symbols combined.

What I failed to see was that when I introduced a 2nd symbol using a Watchlist, the signals were changing based on the symbol because the signal formula did not specify a symbol. I hope this is helpful.

1 Like