Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Cointegration Map
//Bug with the code Amibroker Crashes
//Unhandled exception
//Type: COleException
//Out of present range.
//Code for Simple Co-Integration map can be found here
//written by Rajandran R
SetChartOptions(0,chartShowArrows | chartShowDates);
MyObj=CreateObject("PyCoint"); // link to python com server
Title = "";
WLNum = Param("WatchList Number",0,0,64,1);
list = GetCategorySymbols( categoryWatchlist, WLNum);
Filter = Status("LastBarInTest");
symbol1 = ParamStr("Symbol1", "NIFTY-I"); //Enter Symbol1 can be control from External Parameters
symbol2 = ParamStr("Symbol2", "BANKNIFTY-I");//Enter Symbol1 can be control from External Parameters
Color1 = ParamColor("Color1",colorGreen);
Color2 = ParamColor("Color2",coloryellow);
SetSortColumns( 1 );
Ticker1 = Name();
for( Col=0; (Ticker2=StrExtract( List, Col))!= ""; Col++)
//Get the Foreign Price values
symC2 = Close;
RestorePriceArrays( True );
// COM object interface cannot deal with null value, set to zero to be sure
symC1 = c;
symC2 = Nz(symC2);
// use Cointegration method in com server to calculate smoothed value
coint = MyObj.COINT(symC1,symC2);
Color = IIf(coint<0.1, colorBrightGreen, IIf(coint>0.5, colorRed,colorWhite));
Color = IIf(Ticker1==Ticker2, 1, Color);
AddColumn( coint, Ticker2, 1.3, 1, Color);
//Plot Correlation and CoIntegration in a Dashboard
GfxSetBkMode( 0 );
GfxSelectFont( "Tahoma", 13, 100 );
GfxSetTextColor( colorWhite );
GfxSelectPen( colorGreen, 2 );
GfxSelectSolidBrush( colorgreen );
GfxRectangle( 10, 10, 200, 100 );
GfxTextOut( "Cointegration : " + NumToStr(coint,1.2,separator=false),13,13);
GfxTextOut( "Correlation : " + NumToStr(Correlation(symC1,SymC2,22)),13,43);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.