|
Indicator quản lý danh mục đầu tư trên Ami: _SECTION_BEGIN("quanlydanhmuc"); // NHAP VAO DANH MUC CUA BAN THEO FORMAT : TICKER, SHARES, DAYBUY, PRICE BUY // CHU Y : KHONG CO KHOANG TRANG SAU DAU PHAY. H1 =ParamStr("Tick1","SSI,1500,17/12/09,90"); H2 = ParamStr("Tick2","LCG,2000,17/12/09,62"); H3 = ParamStr("Tick3","REE,3000,17/12/09,36"); H4 = ParamStr("Tick4","REE,3000,17/12/09,36"); H5 = ParamStr("Tick5","REE,3000,17/12/09,36");
TotalSymbolCount = Param("NoTicker",5,0,20);
Title = ""; CellHeight = Param("CellHeight", 20, 10, 30, 1); CellWidth = Param("CellWidth", 90, 70, 110,1); PlotSpace = Param("PlotSpace", 50, 20, 80, 1);
ShowPlot = ParamToggle("GIATRIDANHMUC","No|Yes"); SymList = ""; ShrList = ""; DatList = ""; BuyList = "";
for( i=1; i < totalSymbolCount+1; i++ ) { list = VarGetText( "H" + NumToStr(i, 1.0, 0)); if(i==1){comma = "";} else{comma = ",";} SymList += comma + StrExtract( list , 0); ShrList += comma + StrExtract( list, 1); DatList += comma + StrExtract( list, 2); BuyList += comma + StrExtract( list, 3); }
Title = "";
function PrintInCell( string, row, Col,TxtColor ) { GfxSetTextColor(TxtColor); GfxDrawText( string, Col * CellWidth, row * CellHeight, ( Col + 1 ) * CellWidth, ( row + 1 ) * CellHeight, 0 ); }
function DateToDateNum(dat) { firstbreak = StrFind(dat, "/"); mont = StrToNum(StrLeft(StrLeft(dat, firstbreak) , firstbreak - 1)); fragment = StrRight(dat, StrLen(dat) - firstbreak); secbreak = StrFind(fragment, "/"); daa = StrToNum(StrLeft(StrLeft(fragment, secbreak) , secbreak - 1)); yeer = StrToNum(StrRight(fragment, StrLen(fragment) - secbreak)); yerr = IIf(yeer <= 99 AND yeer > 25, yeer + 1900, IIf(yeer <= 25, yeer + 2000, yeer)); DatNum = (yerr - 1900)*10000 + mont*100 + daa; return DatNum; }
function DateToBar(dn) { return LastValue(ValueWhen(DateNum()==dn, BarIndex())); }
// ===================== Gfx Printing of Title ============================== GfxSelectFont( "Courior New", CellHeight/2 ); GfxSetBkMode(1);
// ===================== Headers for columns ================================ CellWidth = 400; DateSelect = NumToStr(SelectedValue(DateTime()),formatDateTime); TopHL = " PORTFOLIO SYSTEM - TODAY: "+ StrFormat(DateSelect); Colorx = colorBlack; PrintInCell( TopHL, 0,0,colorBlue); CellWidth = 75; PrintInCell( "Portfolio", 1,0,colorViolet); PrintInCell( "BuyDate", 1,1,colorViolet); PrintInCell( "BuyPrice", 1,2,colorViolet); PrintInCell( "Shares", 1,3,colorViolet); PrintInCell( "BuyVal", 1,4,colorViolet); PrintInCell( "CurPrice", 1,5,colorViolet); PrintInCell( "CurValue", 1,6,colorViolet); PrintInCell( "% 1Day", 1,7,colorViolet); PrintInCell( "$ 1Day", 1,8,colorViolet); PrintInCell( "Total %", 1,9,colorViolet); PrintInCell( "ROC 4D", 1,10,colorViolet); PrintInCell( "ROC 21D", 1,11,colorViolet);
//------------------ kk = 2; FTot = 0; GainDol1dTot = 0; ValatBuyTot = 0; for( i = 0; ( sym = StrExtract( SymList, i ) ) != ""; i++ ) {// Loop // Set Ticker/Trade Environment. SetForeign(sym);
Dat = StrExtract(DatList,i); Dat1 = StrToDateTime(Dat); BuyDate = DateToDateNum(Dat); BuyBar = DatetoBar(BuyDate); BuyPr = StrExtract(BuyList,i); if (BuyPr != "") { BuyPr2 = StrToNum(BuyPr); } else { BuyPr2 = ValueWhen(DateTime()==Dat1,C,1); } Shr = StrExtract(ShrList,i); ValatBuy = BuyPr2 * StrToNum(Shr); ValToday = C * StrToNum(Shr); GainPC = 100 * (C - BuyPr2)/BuyPr2; GainDol1d = StrToNum(Shr) * (C - Ref(C,-1) ); Ftot = Ftot + ValToday; GainDol1dTot= GainDol1dTot + GainDol1d; ValatBuyTot = ValatBuyTot + ValatBuy; Color1 = colorBlack; if (LastValue(ROC(C,1)>=0)) {Color2 = colorGreen;}else {Color2 = colorRed;} if (LastValue(ROC(C,4)>=0)) {Color3 = colorGreen;}else {Color3 = colorRed;} if (LastValue(ROC(C,21)>=0)) {Color4 = colorGreen;}else {Color4 = colorRed;}
Colorx = colorYellow; PrintInCell( StrFormat(sym), i+kk,0,color1);//Col1:Sym PrintInCell( StrFormat(Dat), i+kk,1,color1);//Col2:BuyDate PrintInCell( StrFormat("$ "+"%01.2f",BuyPr2), i+kk,2,color1);//Col3:BuyPrice PrintInCell( StrFormat("%01.0f",StrToNum(Shr)), i+kk,3,color1);//Col4:Shares PrintInCell( StrFormat("$ "+"%01.0f",ValatBuy), i+kk,4,color1);//Col5:ValatBuy PrintInCell( StrFormat("$ "+"%01.2f", C ), i+kk,5,color1);//Col5:Price //Today PrintInCell( StrFormat("$ "+"%01.0f",ValToday), i+kk,6,color1);//Col6:ValueToday PrintInCell( StrFormat("%01.2f", ROC(C,1))+"%", i+kk,7,color2);//Col6:1dROC PrintInCell( StrFormat("$ "+"%01.0f", GainDol1d), i+kk,8,color2);//Col8:1dGain$ PrintInCell( StrFormat("%01.1f", GainPC)+"%", i+kk,9,color2);//Col7:Tot%Change PrintInCell( StrFormat("%01.2f", ROC(C,4))+"%", i+kk,10,color3);//Col9:21dROC PrintInCell( StrFormat("%01.2f", ROC(C,21))+"%", i+kk,11,color4);//Col9:63dROC
RestorePriceArrays();
}// End Loop FTot1dROC = ROC(Ftot,1); TotChg = 100 * (FTot - ValatBuyTot)/ValatBuyTot; FTot4 = ROC(Ftot,4); Ftot21 = ROC(Ftot,21);
if (LastValue(Ftot1dROC>=0)) {Color5 = colorGreen;}else {Color5 = colorRed;} if (LastValue(GainDol1dTot>=0)) {Color6 = colorGreen;}else {Color6 = colorRed;} if (LastValue(TotChg>=0)) {Color7 = colorGreen;}else {Color7 = colorRed;} if (LastValue(Ftot4>=0)) {Color8 = colorGreen;}else {Color8 = colorRed;} if (LastValue(Ftot21>=0)) {Color9 = colorGreen;}else {Color9 = colorRed;}
PrintInCell(StrFormat("Rate Return ",ValatBuytot), i+kk+0,0,colorViolet); PrintInCell(StrFormat("Of Tran Bau :",ValatBuytot), i+kk+0,1,colorViolet); PrintInCell(StrFormat("$ "+"%01.0f",ValatBuytot), i+kk+0,4,color1); PrintInCell(StrFormat("$ "+"%01.0f",Ftot), i+kk+0,6,color1); PrintInCell(StrFormat("%01.1f",FTot1dROC)+"%", i+kk+0,7,color5); PrintInCell(StrFormat("$ "+"%01.0f",GainDol1dTot), i+kk+0,8,color6); PrintInCell(StrFormat("%01.1f",TotChg)+"%", i+kk+0,9,color7); PrintInCell(StrFormat("%01.1f",Ftot4)+"%", i+kk+0,10,color8); PrintInCell(StrFormat("%01.1f",Ftot21)+"%", i+kk+0,11,color9);
if (ShowPlot != 0) {Plot(Ftot,"",colorBlue,styleLine); } Plot(FTot21,"",colorBlue,styleLine|styleThick); Plot(ROC(Foreign("VNINDEX", "C"),21),"",colorRed,1|styleThick);
GraphXSpace = PlotSpace; SetChartOptions(0,chartShowArrows|chartShowDates); SetChartBkGradientFill( ParamColor("Inner panel color upper half",colorBlack),ParamColor("Inner panel color lower half",colorBlack)); _SECTION_END();
|
|
Indicator so sánh nhiều cổ phiếu với nhau: _SECTION_BEGIN("Compare Stocks Explorer"); Cl0=colorBlue; Cl1=colorRed; Cl2=colorOrange; Cl3=colorGreen ; Cl4=colorTurquoise; Cl5=colorLime; Cl6=colorBlueGrey; Cl7=colorYellow; Cl8=colorBrightGreen; Cl9=colorPink;
//Set Variables barvisible = Status("barvisible"); FVB = barvisible AND NOT Ref( barvisible, -1 ); CVB = ValueWhen( FVB,C) ; Leftbar=ValueWhen(Ref(barvisible,-1)==0 AND barvisible,DateTime() ); Rightbar=LastValue(DateTime() ); DateSpan = EndValue(BarIndex()) - BeginValue(BarIndex()); Range = DateSpan ; StartDate = BeginValue(BarIndex()); EndDate = EndValue(BarIndex());
//Select Tickers Fn0=ParamStr( "Fund0", "VNINDEX"); Fn1=ParamStr( "Fund1", "HNXINDEX"); Fn2=ParamStr( "Fund2", ""); Fn3=ParamStr( "Fund3", ""); Fn4=ParamStr( "Fund4", ""); Fn5=ParamStr( "Fund5", ""); Fn6=ParamStr( "Fund6", ""); Fn7=ParamStr( "Fund7", ""); Fn8=ParamStr( "Fund8", ""); Fn9=ParamStr( "Fund9", "");
//Normalized to left edge Fa0=Prec(100*(Foreign(Fn0,"C")/ValueWhen(FVB,Foreign(Fn0,"C"))-1),2.2); Fa1=Prec(100*(Foreign(Fn1,"C")/ValueWhen(FVB,Foreign(Fn1,"C"))-1),2.2); Fa2=Prec(100*(Foreign(Fn2,"C")/ValueWhen(FVB,Foreign(Fn2,"C"))-1),2.2); Fa3=Prec(100*(Foreign(Fn3,"C")/ValueWhen(FVB,Foreign(Fn3,"C"))-1),2.2); Fa4=Prec(100*(Foreign(Fn4,"C")/ValueWhen(FVB,Foreign(Fn4,"C"))-1),2.2); Fa5=Prec(100*(Foreign(Fn5,"C")/ValueWhen(FVB,Foreign(Fn5,"C"))-1),2.2); Fa6=Prec(100*(Foreign(Fn6,"C")/ValueWhen(FVB,Foreign(Fn6,"C"))-1),2.2); Fa7=Prec(100*(Foreign(Fn7,"C")/ValueWhen(FVB,Foreign(Fn7,"C"))-1),2.2); Fa8=Prec(100*(Foreign(Fn8,"C")/ValueWhen(FVB,Foreign(Fn8,"C"))-1),2.2); Fa9=Prec(100*(Foreign(Fn9,"C")/ValueWhen(FVB,Foreign(Fn9,"C"))-1),2.2);
//Plot Normalized Graphs Plot(Fa0,Fn0,Cl0,4); Plot(Fa1,Fn1,Cl1,4); Plot(Fa2,Fn2,Cl2,4); Plot(Fa3,Fn3,Cl3,4); Plot(Fa4,Fn4,Cl4,4); Plot(Fa5,Fn5,Cl5,4); Plot(Fa6,Fn6,Cl6,4); Plot(Fa7,Fn7,Cl7,4); Plot(Fa8,Fn8,Cl8,4); Plot(Fa9,Fn9,Cl9,4);
//Calculate % Change between markers Fv0=IIf(startdate==0,Fa0,100*(EndValue(Foreign(Fn0,"C")-BeginValue(Foreign(Fn0,"C"))))/BeginValue(Foreign(Fn0,"C"))); Fv9=IIf(startdate==0,Fa9,100*(EndValue(Foreign(Fn9,"C")-BeginValue(Foreign(Fn9,"C"))))/BeginValue(Foreign(Fn9,"C"))); Fv8=IIf(startdate==0,Fa8,100*(EndValue(Foreign(Fn8,"C")-BeginValue(Foreign(Fn8,"C"))))/BeginValue(Foreign(Fn8,"C"))); Fv7=IIf(startdate==0,Fa7,100*(EndValue(Foreign(Fn7,"C")-BeginValue(Foreign(Fn7,"C"))))/BeginValue(Foreign(Fn7,"C"))); Fv6=IIf(startdate==0,Fa6,100*(EndValue(Foreign(Fn6,"C")-BeginValue(Foreign(Fn6,"C"))))/BeginValue(Foreign(Fn6,"C"))); Fv5=IIf(startdate==0,Fa5,100*(EndValue(Foreign(Fn5,"C")-BeginValue(Foreign(Fn5,"C"))))/BeginValue(Foreign(Fn5,"C"))); Fv4=IIf(startdate==0,Fa4,100*(EndValue(Foreign(Fn4,"C")-BeginValue(Foreign(Fn4,"C"))))/BeginValue(Foreign(Fn4,"C"))); Fv3=IIf(startdate==0,Fa3,100*(EndValue(Foreign(Fn3,"C")-BeginValue(Foreign(Fn3,"C"))))/BeginValue(Foreign(Fn3,"C"))); Fv2=IIf(startdate==0,Fa2,100*(EndValue(Foreign(Fn2,"C")-BeginValue(Foreign(Fn2,"C"))))/BeginValue(Foreign(Fn2,"C"))); Fv1=IIf(startdate==0,Fa1,100*(EndValue(Foreign(Fn1,"C")-BeginValue(Foreign(Fn1,"C"))))/BeginValue(Foreign(Fn1,"C")));
Title= //Right Bar Date WriteIf(EndValue(DateTime() )==rightbar, "Stocks Comparation - "+Date(), " "+WriteVal(Range,1)+" days "+WriteVal(EndValue(Month()),1.0) +"/" + WriteVal(EndValue(Day()),1.0) + "/20" + StrRight( WriteVal(EndValue(Year()),1.0),2))
//List of Funds +" \n"+EncodeColor(Cl0)+Fn0+ WriteIf(IsTrue(fa0)," ["+WriteVal(fv0,1.2)+ "] ","") +EncodeColor(Cl1)+Fn1+ WriteIf(IsTrue(fa1)," ["+WriteVal(fv1,1.2)+"] ","")+EncodeColor(Cl2)+Fn2 + WriteIf(IsTrue(fa2)," ["+ WriteVal(fv2,1.2)+"] ","")+"\n"+EncodeColor(Cl3)+fn3 + WriteIf(IsTrue(fa3)," ["+WriteVal(fv3,1.2)+"] ","")+ EncodeColor(Cl4)+Fn4 + WriteIf(IsTrue(fa4)," ["+WriteVal(fv4,1.2)+"] ","")+EncodeColor(Cl5)+Fn5 + WriteIf(IsTrue(fa5)," ["+WriteVal(fv5,1.2)+"] ","")+"\n"+EncodeColor(Cl6)+Fn6 + WriteIf(IsTrue(fa6)," ["+WriteVal(fv6,1.2)+"] ","")+ EncodeColor(Cl7)+Fn7 + WriteIf(IsTrue(fa7)," ["+WriteVal(fv7,1.2)+"] ","")+EncodeColor(Cl8)+Fn8 + WriteIf(IsTrue(fa8)," ["+ WriteVal(fv8,1.2)+"] ","")+EncodeColor(Cl9)+Fn9 + WriteIf(IsTrue(fa9)," ["+WriteVal(fv9,1.2)+"] ",""); _SECTION_END();
|