[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: pair trading chart



PureBytes Links

Trading Reference Links

--- In amibroker@xxxxxxxxxxxxxxx, "Mike" <sfclimbers@xxx> wrote:
>
> Hi,
> 
> Your message is a bit confusing since what you are asking for is completely different from the example graphs that you have provided. 
> 
> I believe that the example graphs are showing the performance to date of each symbol on a single chart (i.e. two independent lines), whereas you appear to be asking for a single line showing performance of one symbol relative to the other.
> 
> That being the case, here's an example:
> 
> DIAClose = Foreign("DIA", "Close");
> IWMClose = Foreign("IWM", "Close");
> Diff = (DIAClose - IWMClose)/IWMClose;	// Expressed as a percentage.
> 
> Plot(Diff, "Diff", colorRed, styleLine);
> 
> Mike
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "Alexander  Shelupinin" <shelupinin@> wrote:
> >
> > Hi !
> > I want to explore the opportunitie of pair trading, i.e. to trade 2 instruments with very high correlation, if , say, the difference in 2 instruments increased over it's historic value than put a trade with a bet that their difference will come to lower value, close to historic value. I gonna trade index ETFs.
> > Here is an idea what I mean:
> > http://finance.yahoo.com/q/bc?t=1d&s=DIA&l=on&z=l&q=l&c=iwm
> > http://finance.yahoo.com/q/bc?s=dia&t=1d&l=on&z=l&q=l&p=&a=&c=spy
> > http://finance.yahoo.com/q/bc?t=1d&s=QQQQ&l=on&z=l&q=l&c=iwm
> > http://finance.yahoo.com/q/bc?t=1d&s=QQQQ&l=on&z=l&q=l&c=dia
> > 
> > So the question: Could someone help and write a simple code that will draw a chart of difference between mentioned ETFs: IWM, SPY, QQQQ, DIA. I mean not a chart of symbol, but chart of 2 symbol difference, say {DIA} minus {IWM} or {QQQQ} minus {DIA}
> > 
> > thanks a lot for any help !!!
> > 
> > Alex
> >
this will do what you want.............

//
SetChartBkGradientFill( ParamColor("BgTop", colorBlack),
ParamColor("BgBottom", colorDarkGreen)); 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Tickers= ParamStr("Short Ticker", "W2___2008Z");//short stock
tickersc=Foreign( tickers, "C");//Short stock
/////////////////////////////////////
/////////////////////////////////////////////////////////////////
Longt=Param("Long Stock",1,1,5000,0.5);//no shares etc for dollar neutral
Shortt=Param("Short Stock",1,1,5000,0.5);//no shares etc for dollar neutral

//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
spreadc=((Longt)*(C))-((Shortt)*(tickersc));
///////////////////////////////////////////////////////////////////
Cc1=EMA(spreadc,2);
Plot( spreadc,""+Tickers,colorGold,styleDashed);
Plot(Cc1,"",colorBrightGreen,5);
/////////////////////////////////////////////
x1=MA(spreadc,13);
x2=Ref(x1,-3);
Plot(x2,"3 displaced 13 MA ",0,5);
///////////////////////////////////////////////////////
bb=2*(StDev( Cc1, 13 )) ;
Plot(Cc1+bb,"",54,styleDashed);
Plot(Cc1-bb,"",54,styleDashed);
////

and here is one for  the CCI
///

ticker= ParamStr("Short ticker", "type in ticker");//short stock

tickersc=Foreign( ticker, "C");//Short stock
tickerso=Foreign( ticker, "O");//Short stock
tickersh=Foreign( ticker, "H");//Short stock
tickersl=Foreign( ticker, "L");//Short stock

/////////////////////////////////////////////////////////////////
Longt=Param("Long Stock",1,1,5000,0.5);
Shortt=Param("Short Stock",1,1,5000,0.5);
//////////////////////////////////////////////////////////////////
spreadC=((Longt)*(C))-((Shortt)*(tickersc));
spreadO=((Longt)*(O))-((Shortt)*(tickerso));
spreadH=((Longt)*(H))-((Shortt)*(tickersh));
spreadL=((Longt)*(L))-((Shortt)*(tickersl));
////////////////////////////////////////////////////////////////
aaa=(spreado+spreadh+spreadl+spreadc)/4;


CCIi=Param("cci",34,2,100,1);

Color=IIf(CCIa(aaa,CCIi)<=0,4,5);
///////////////////////////////////////////////////////////////////
Plot(0,"",5,5);
Plot(CCIa(aaa,CCIi),"",Color,styleHistogram+styleThick);
Plot(CCIa(aaa,CCIi),"",Color,styleDots+styleThick);




------------------------------------

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to 
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/