Pairs Trading system: adding exit, plotting both symbols
Author: SimhaD04
Creation Date: 1/7/2014 4:41 PM
profile picture

SimhaD04

#1
1. I am modifying the WL supplied Pairs Trading program. Among changes, I modified the way the trade exits and that's apparently where the problem is. Specifically I wanted to enter trades when Deltanorm is either above or below up- downThreshold, respectively (as in the original program). I wanted to exit the trade entered on >upthreshold when DeltaNorm <0 and the trade entered on <downThreshold, when Deltanorm is >0. Here's the trading portion of the relevant code:

CODE:
Please log in to see this code.


How to fix the exit rules to do what I want? Thanks,

2. The chart for the strategy contains three panels. The two top panels are explicitly set up in the software and are clear how to work with. The bottom panel always plots one ETF from the pair, IWM. It is not specified explicitly anywhere that I can see. I tried switching
QUOTE:
stock1, stock2
to SPY vs IWM, but the plot does not change. I would prefer to see both stocks from the pair plotted, i.e. both IWM and SPY. This is not a very important item, but I wanted to learn about chart controls. Here's the relevant portion of the code:

CODE:
Please log in to see this code.


Thank you.
profile picture

Eugene

#2
QUOTE:
The bottom panel always plots one ETF from the pair, IWM.

The built-in primary ChartPane a.k.a. PricePane, or "the bottom panel" as you called it, always displays the clicked symbol. You can plot another symbol's OHLC with the help of PlotSymbol (or PlotSyntheticSymbol() if the symbol is synthetic):

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

SimhaD04

#3
thanks, Eugene, that worked for plotting, except that it does not show any buy/sell etc symbols on the new chart. How do I display them?

I look forward to your comments on my 1st question above.

profile picture

Eugene

#4
QUOTE:
thanks, Eugene, that worked for plotting, except that it does not show any buy/sell etc symbols on the new chart. How do I display them?

It's in the FAQ: Is there a way to see the trades on secondary symbols?
profile picture

SimhaD04

#5
I inserted the code:

CODE:
Please log in to see this code.


compiled it with no problems, but nothing changed on the chart...

Thanks.
profile picture

Eugene

#6
Yes, that usually happens when making random edits. Does the FAQ say "here's an illustration"? If you wish to learn WealthScript, a little more effort is required than making a simple copy/paste.

Take a look in the QuickRef and ask:
* What does AnnotateBar is used for?
* Where would it make sense to insert these directives based on the logic of the Strategy code?

I'll give you one more working example, now a complete one: "ActiveTrader 2011-05 | Inverse ETF switching system". Follow Instructions for Script Download (don't forget to uncheck "Published since"), look it up under the "Intermarket" folder, and you'll see AnnotateBar() in action, plotting trades on secondary symbol.
profile picture

SimhaD04

#7
ok, works now. The illustration was pretty useless for someone who does not know the script - the only audience for FAQ, as the ones who know don't need it.

Any news on Q1 in my original post? thanks
profile picture

Cone

#8
Here's a nice modification with StrategyParameters added (it should have been published that way). If you're a customer and have installed the Community.Components extensions, you can uncomment the last statement (PlotSymbolTrades) and the trades will be plotted in your pair symbol too.

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

SimhaD04

#9
Thanks a lot, it works!
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).