Library Coding
Kumpulan contoh script dan logika penulisan coding C++
Saturday, February 28, 2015
Indikator
Indi Portofolio
Indikator Evaluasi Portofolio
//+------------------------------------------------------------------+ //| @ INFO - Portofolio v-2.mq4 | //| Versi : Juli 2014 | //| Trader Pro 2014 | //+------------------------------------------------------------------+ #property copyright "Versi : Feb 2015" #property link "Trader Pro 2015" #property indicator_chart_window //+--------------------------------------------------------------------------+ //| Outsite | //+--------------------------------------------------------------------------+ extern bool Bgrond = FALSE; extern color Warna1 = DarkBlue; string ObjName = "_panel_1"; string Notes = "Calculation of percentage of profit on"; string Note0 = "0 - current balance"; string Note1 = "1 - balance at the beginning of the day"; string Note2 = "2 - balance at the beginning of the week"; string Note3 = "3 - balance at the beginning of the month"; string Note4 = "4 - balance at beginning of the quarter"; string Note5 = "5 - balance at beginning of year"; string Note6 = "eiPercent is your choice"; int eiPercent = 1; // Calculation of percentage of profit on: // 0 - current balance // 1 - balance at the beginning of the day // 2 - balance at the beginning of the week // 3 - balance at the beginning of the month // 4 - balance at beginning of the quarter // 5 - balance at beginning of year //+--------------------------------------------------------------------------+ //| Options positions | //+--------------------------------------------------------------------------+ int eiFontSize = 10; int eiOffsetY = 25; // (Y) Offset text vertically int eiOffsetY2= 100; // (Y) Offset text vertically int eiStepY = 18; // (Y) Step displacements of the text vertically int eiX1Row = 550; // (X) Coordinate of the first column 180 int eiX2Row = 490; // (X) Coordinate of the second column 130 int eiX3Row = 430; // (X) Coordinate third column 65 int eiX4Row = 370; // (X) Coordinate of the fourth column 3 395 int eiX4Row2 = 970; // (X) Coordinate of the fourth column 3 395 //+--------------------------------------------------------------------------+ //| Color Settings | //+--------------------------------------------------------------------------+ color Tulisan = LightSlateGray; // Text Color color Profit_ = Lime; // Color profit color Loss_ = Red; // Color loss //+--------------------------------------------------------------------------+ //| Custom indicator initialization function | //+--------------------------------------------------------------------------+ void init() { if (ObjectFind(ObjName) == -1) { ObjectCreate(ObjName, OBJ_LABEL, 0, 0, 0, 0, 0); ObjectSetText (ObjName,"g",2500, "Webdings", Warna1); ObjectSet (ObjName, OBJPROP_CORNER,0); ObjectSet (ObjName, OBJPROP_XDISTANCE, 0); ObjectSet (ObjName, OBJPROP_YDISTANCE, 0); ObjectSet (ObjName, OBJPROP_BACK, Bgrond); } DeleteObjects(); Comment (""); // comment in the upper left corner } //+--------------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+--------------------------------------------------------------------------+ void deinit() { ObjectDelete("_panel_1"); DeleteObjects(); Comment (""); // comment in the upper left corner } //+--------------------------------------------------------------------------+ //| Custom indicator iteration function | //+--------------------------------------------------------------------------+ void start() { // label(); datetime d0, d1, d2, d3, d4, d5, d6, d7, d8; //+--------------------------------------------------------------------------+ d0=StrToTime(TimeToStr(TimeCurrent(), TIME_DATE)); while (TimeDayOfWeek(d0)<1 || TimeDayOfWeek(d0)>5) d0-=24*60*60; d1=d0-24*60*60; while (TimeDayOfWeek(d1)<1 || TimeDayOfWeek(d1)>5) d1-=24*60*60; d2=d1-24*60*60; while (TimeDayOfWeek(d2)<1 || TimeDayOfWeek(d2)>5) d2-=24*60*60; d3=d2-24*60*60; while (TimeDayOfWeek(d3)<1 || TimeDayOfWeek(d3)>5) d3-=24*60*60; d4=d3-24*60*60; while (TimeDayOfWeek(d4)<1 || TimeDayOfWeek(d4)>5) d4-=24*60*60; d5=DateOfMonday(); d6=StrToTime(Year()+"."+Month()+".01"); d7=DateBeginQuarter(); d8=StrToTime(Year()+".01.01"); //+--------------------------------------------------------------------------+ double tu=GetProfitOpenPosInPoint (); double u0=GetProfitFromDateInPoint ("", -1, -1, d0); double u1=GetProfitFromDateInPoint ("", -1, -1, d1)-u0; double u2=GetProfitFromDateInPoint ("", -1, -1, d2)-u1-u0; double u3=GetProfitFromDateInPoint ("", -1, -1, d3)-u2-u1-u0; double u4=GetProfitFromDateInPoint ("", -1, -1, d4)-u3-u2-u1-u0; double u5=GetProfitFromDateInPoint ("", -1, -1, d5); double u6=GetProfitFromDateInPoint ("", -1, -1, d6); double u7=GetProfitFromDateInPoint ("", -1, -1, d7); double u8=GetProfitFromDateInPoint ("", -1, -1, d8); //+--------------------------------------------------------------------------+ double tb=AccountBalance(), tp=AccountProfit(); double p0=GetProfitFromDateInCurrency ("", -1, -1, d0); double p1=GetProfitFromDateInCurrency ("", -1, -1, d1)-p0; double p2=GetProfitFromDateInCurrency ("", -1, -1, d2)-p1-p0; double p3=GetProfitFromDateInCurrency ("", -1, -1, d3)-p2-p1-p0; double p4=GetProfitFromDateInCurrency ("", -1, -1, d4)-p3-p2-p1-p0; double p5=GetProfitFromDateInCurrency ("", -1, -1, d5); double p6=GetProfitFromDateInCurrency ("", -1, -1, d6); double p7=GetProfitFromDateInCurrency ("", -1, -1, d7); double p8=GetProfitFromDateInCurrency ("", -1, -1, d8); //+--------------------------------------------------------------------------+ string st; switch (eiPercent) { case 0 : st="current"; break; case 1 : tb-=p0; st="at the beginning of the day"; break; case 2 : tb-=p5; st="at the beginning of the week"; break; case 3 : tb-=p6; st="at the beginning of the month"; break; case 4 : tb-=p7; st="at the beginning of the quarter"; break; default: tb-=p8; st="at beginning of year"; break; } double tr=tp*100/tb; double r0=p0*100/tb; double r1=p1*100/tb; double r2=p2*100/tb; double r3=p3*100/tb; double r4=p4*100/tb; double r5=p5*100/tb; double r6=p6*100/tb; double r7=p7*100/tb; double r8=p8*100/tb; double blc=AccountBalance(); double eqt=AccountEquity(); //+--------------------------------------------------------------------------+ //| HEADERS | //+--------------------------------------------------------------------------+ SetLabel ("iProfit05", "WAKTU", Blue, eiX1Row+30,eiOffsetY); SetLabel ("iProfit06", "POIN", Blue, eiX2Row-2, eiOffsetY); SetLabel ("iProfit07", "DOLAR", Blue, eiX3Row-2, eiOffsetY); SetLabel ("iProfit08", "PERSEN", Blue, eiX3Row-75,eiOffsetY); //+--------------------------------------------------------------------------+ //| separator | //+--------------------------------------------------------------------------+ SetLabel ("iProfit09", "===================================",Tulisan, eiX4Row-1,eiOffsetY+1*eiStepY); //+--------------------------------------------------------------------------+ //| position | //+--------------------------------------------------------------------------+ SetLabel ("iProfit11", ":: Sekarang ", Tulisan, eiX1Row, eiOffsetY+2*eiStepY); SetLabel ("iProfit21", ":: Hari Ini ", Tulisan, eiX1Row, eiOffsetY+3*eiStepY); SetLabel ("iProfit31", ""+TimeToStr(d1, TIME_DATE), Tulisan, eiX1Row, eiOffsetY+4*eiStepY); SetLabel ("iProfit41", ""+TimeToStr(d2, TIME_DATE), Tulisan, eiX1Row, eiOffsetY+5*eiStepY); SetLabel ("iProfit51", ""+TimeToStr(d3, TIME_DATE), Tulisan, eiX1Row, eiOffsetY+6*eiStepY); SetLabel ("iProfit61", ""+TimeToStr(d4, TIME_DATE), Tulisan, eiX1Row, eiOffsetY+7*eiStepY); SetLabel ("iProfit101", ":: Minggu Ini ", Tulisan, eiX1Row, eiOffsetY+8*eiStepY); SetLabel ("iProfit81", ":: Bulan Ini ", Tulisan, eiX1Row, eiOffsetY+9*eiStepY); SetLabel ("iProfit91", ":: 6 Bulan Ini ", Tulisan, eiX1Row, eiOffsetY+10*eiStepY); SetLabel ("iProfit01", ":: Tahun Ini ", Tulisan, eiX1Row, eiOffsetY+11*eiStepY); //SetLabel ("iProfit01", ""+":: "+AccountName(), Tulisan, eiX1Row, eiOffsetY+15*eiStepY); //SetLabel ("iProfit71", ""+":: "+AccountNumber(), Tulisan, eiX1Row+20, eiOffsetY+16*eiStepY); //+--------------------------------------------------------------------------+ //| POINTS | //+--------------------------------------------------------------------------+ SetLabel ("iProfit12", DoubleToStr (tu, 0), ColorOnSign(tp), eiX2Row, eiOffsetY+2*eiStepY); SetLabel ("iProfit22", DoubleToStr (u0, 0), ColorOnSign(u0), eiX2Row, eiOffsetY+3*eiStepY); SetLabel ("iProfit32", DoubleToStr (u1, 0), ColorOnSign(u1), eiX2Row, eiOffsetY+4*eiStepY); SetLabel ("iProfit42", DoubleToStr (u2, 0), ColorOnSign(u2), eiX2Row, eiOffsetY+5*eiStepY); SetLabel ("iProfit52", DoubleToStr (u3, 0), ColorOnSign(u3), eiX2Row, eiOffsetY+6*eiStepY); SetLabel ("iProfit62", DoubleToStr (u4, 0), ColorOnSign(u4), eiX2Row, eiOffsetY+7*eiStepY); SetLabel ("iProfit72", DoubleToStr (u5, 0), ColorOnSign(u5), eiX2Row, eiOffsetY+8*eiStepY); SetLabel ("iProfit82", DoubleToStr (u6, 0), ColorOnSign(u6), eiX2Row, eiOffsetY+9*eiStepY); SetLabel ("iProfit92", DoubleToStr (u7, 0), ColorOnSign(u7), eiX2Row, eiOffsetY+10*eiStepY); SetLabel ("iProfit02", DoubleToStr (u8, 0), ColorOnSign(u8), eiX2Row, eiOffsetY+11*eiStepY); //+--------------------------------------------------------------------------+ //| MONEY | //+--------------------------------------------------------------------------+ SetLabel ("iProfit13", DoubleToStr (tp, 2), ColorOnSign(tp), eiX3Row, eiOffsetY+2*eiStepY); SetLabel ("iProfit23", DoubleToStr (p0, 2), ColorOnSign(p0), eiX3Row, eiOffsetY+3*eiStepY); SetLabel ("iProfit33", DoubleToStr (p1, 2), ColorOnSign(p1), eiX3Row, eiOffsetY+4*eiStepY); SetLabel ("iProfit43", DoubleToStr (p2, 2), ColorOnSign(p2), eiX3Row, eiOffsetY+5*eiStepY); SetLabel ("iProfit53", DoubleToStr (p3, 2), ColorOnSign(p3), eiX3Row, eiOffsetY+6*eiStepY); SetLabel ("iProfit63", DoubleToStr (p4, 2), ColorOnSign(p4), eiX3Row, eiOffsetY+7*eiStepY); SetLabel ("iProfit73", DoubleToStr (p5, 2), ColorOnSign(p5), eiX3Row, eiOffsetY+8*eiStepY); SetLabel ("iProfit83", DoubleToStr (p6, 2), ColorOnSign(p6), eiX3Row, eiOffsetY+9*eiStepY); SetLabel ("iProfit93", DoubleToStr (p7, 2), ColorOnSign(p7), eiX3Row, eiOffsetY+10*eiStepY); SetLabel ("iProfit03", DoubleToStr (p8, 2), ColorOnSign(p8), eiX3Row, eiOffsetY+11*eiStepY); //+--------------------------------------------------------------------------+ //| INTEREST | //+--------------------------------------------------------------------------+ SetLabel ("iProfit14", DoubleToStr (tr, 2)+" %", ColorOnSign(tr), eiX4Row, eiOffsetY+2*eiStepY); SetLabel ("iProfit24", DoubleToStr (r0, 2)+" %", ColorOnSign(r0), eiX4Row, eiOffsetY+3*eiStepY); SetLabel ("iProfit34", DoubleToStr (r1, 2)+" %", ColorOnSign(r1), eiX4Row, eiOffsetY+4*eiStepY); SetLabel ("iProfit44", DoubleToStr (r2, 2)+" %", ColorOnSign(r2), eiX4Row, eiOffsetY+5*eiStepY); SetLabel ("iProfit54", DoubleToStr (r3, 2)+" %", ColorOnSign(r3), eiX4Row, eiOffsetY+6*eiStepY); SetLabel ("iProfit64", DoubleToStr (r4, 2)+" %", ColorOnSign(r4), eiX4Row, eiOffsetY+7*eiStepY); SetLabel ("iProfit74", DoubleToStr (r5, 2)+" %", ColorOnSign(r5), eiX4Row, eiOffsetY+8*eiStepY); SetLabel ("iProfit84", DoubleToStr (r6, 2)+" %", ColorOnSign(r6), eiX4Row, eiOffsetY+9*eiStepY); SetLabel ("iProfit94", DoubleToStr (r7, 2)+" %", ColorOnSign(r7), eiX4Row, eiOffsetY+10*eiStepY); SetLabel ("iProfit04", DoubleToStr (r8, 2)+" %", ColorOnSign(r8), eiX4Row, eiOffsetY+11*eiStepY); //+--------------------------------------------------------------------------+ //| HEADERS | //+--------------------------------------------------------------------------+ SetLabel ("iProfit65", " "+AccountCompany(), Yellow, eiX4Row-235,eiOffsetY2+2*eiStepY); SetLabel ("iProfit66", " "+AccountName(), Yellow, eiX4Row-166,eiOffsetY2+3*eiStepY); SetLabel ("iProfit67", " "+AccountNumber(), Yellow, eiX4Row-146,eiOffsetY2+4*eiStepY); SetLabel ("iProfit68", " 1: "+AccountLeverage(),Yellow, eiX4Row-126,eiOffsetY2+5*eiStepY); SetLabel ("iProfit788", "============", Blue, eiX4Row-188, eiOffsetY2+6*eiStepY); SetLabel ("iProfit69", "Equity : "+ "$ "+DoubleToStr(eqt,2),Magenta, eiX4Row-190,eiOffsetY2+7*eiStepY); SetLabel ("iProfit79", "Balance : "+"$ "+DoubleToStr (blc,2), White, eiX4Row-207, eiOffsetY2+8*eiStepY); //+--------------------------------------------------------------------------+ //| separator | //+--------------------------------------------------------------------------+ SetLabel ("iProfit15", "===================================",Tulisan, eiX4Row-1,eiOffsetY+12*eiStepY); SetLabel ("iProfit17", " www.simple-book.blogspot.com ",Blue, eiX4Row-1,eiOffsetY+13*eiStepY); SetLabel ("iProfit16", "===================================",Tulisan, eiX4Row-1,eiOffsetY+14*eiStepY); } //+--------------------------------------------------------------------------+ color ColorOnSign(double nu) { color lcColor=Tulisan; if (nu>0) lcColor=Profit_; if (nu<0) lcColor=Loss_; return (lcColor); } //+--------------------------------------------------------------------------+ datetime DateBeginQuarter(int nk=0) { int ye=Year()-MathFloor(nk/4); nk=MathMod(nk, 4); int mo=Month()-MathMod(Month()+2, 3)+3*nk; if (mo<1) { mo+=12; ye--; } if (mo>12) { mo-=12; ye++; } return (StrToTime(ye+"."+mo+".01")); } //+--------------------------------------------------------------------------+ datetime DateOfMonday(int no=0) { datetime dt=StrToTime(TimeToStr(TimeCurrent(), TIME_DATE)); while (TimeDayOfWeek(dt)!=1) dt-=24*60*60; dt+=no*7*24*60*60; return (dt); } //+--------------------------------------------------------------------------+ void DeleteObjects() { string st="iProfit"; int i, j; for (i=0; i<10; i++) { for (j=1; j<8; j++) ObjectDelete(st+i+j); } } //+--------------------------------------------------------------------------+ double GetProfitFromDateInCurrency(string sy="", int op=-1, int mn=-1, datetime dt=0) { double p=0; int i, k=OrdersHistoryTotal(); if (sy=="0") sy=Symbol(); for (i=0; i
Gambar
0 comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
"Join Us on Facebook!
"Join Us on Facebook!
"Join Us on Facebook!
Contact
DAFTAR ISI :
Powered by
Blogger
.
Latest Tweets
;
0 comments:
Post a Comment