//+------------------------------------------------------------------+ //| Hamyar.mq4 | //| Copyright © 2010, Farshad | //| http://www.vizhish.com | //+------------------------------------------------------------------+ #property copyright "Copyright © 2010, Farshad Saremifar" #property link "farshad.saremifar@gmail.com" #define TITLE 0 #define COUNTRY 1 #define DATE 2 #define TIME 3 #define IMPACT 4 #define FORECAST 5 #define PREVIOUS 6 #property indicator_chart_window #property indicator_buffers 7 #property indicator_color1 Snow #property indicator_style1 STYLE_DASH #property indicator_width1 1 #property indicator_color2 Red #property indicator_width2 4 #property indicator_color3 DodgerBlue #property indicator_width3 4 #property indicator_color4 Crimson #property indicator_width4 1 #property indicator_style4 STYLE_DOT #property indicator_color5 SteelBlue #property indicator_width5 1 #property indicator_style5 STYLE_DOT #property indicator_color6 Magenta #property indicator_style6 STYLE_DASHDOTDOT #property indicator_width6 1 #property indicator_color7 Aqua #property indicator_style7 STYLE_DASHDOTDOT #property indicator_width7 1 extern int NumberOfDays=10; extern int ATR_Period=25; extern int ATRTimeframe=5; extern bool English=true; extern bool alert=false; extern bool Email_Alert=false; extern int LocalTimeZone = 0; extern bool Display=true; extern bool ShowPivots = false; extern bool ShowFibos= false; extern bool ShowYesterdayHighLow = false; extern bool ShowMidPitvot = false; extern bool ShowCamarilla = false; extern string Part1 ="Sessions"; extern bool ShowSessions=false; extern string SydneyBegin = "00:00"; extern string SydneyEnd = "06:00"; color SydneyColor = Gray; extern string AsiaBegin = "01:00"; extern string AsiaEnd = "07:00"; color AsiaColor = Yellow; extern string EurBegin = "06:00"; extern string EurEnd = "14:00"; color EurColor = Crimson; extern string LondonBegin = "07:00"; extern string LondonEnd = "15:00"; color LondonColor = Lime; extern string USABegin = "12:00"; extern string USAEnd = "20:00"; color USAColor = Sienna; extern string Part2 ="News"; extern bool ShowNews=false; extern bool ShowHigh = true; extern bool ShowMedium = true; extern bool ShowLow = true; extern bool ShowSpeaks = true; // news items with "Speaks" in them have different characteristics bool IsEA_Call = false; int OffsetHours = 0; bool AllowWebUpdates = true; // Set this to false when using in another EA or Chart, so that the multiple instances of the indicator dont fight with each other int Alert1MinsBefore = -1; // Set to -1 for no Alert int Alert2MinsBefore = -1; // Set to -1 for no Alert bool ReportAllForUSD = false; bool EnableLogging = false; // Perhaps remove this from externs once its working well bool ShowNextTwoEvents = true; bool ShowVertNews = true; int TxtSize = 10; color TxtColorTitle = Yellow; color TxtColorNews = Yellow; color TxtColorImpact = Red; color TxtColorPrevious = Peru; color TxtColorForecast = Lime; int VertTxtShift = 21; // How far away below the ask line we want to place our vertical news text int VertLeftLineShift = 900; // How far away to the left of the line we want to place our vertical news text int VertRightLineShift = 200; // How far away to the left of the line we want to place our vertical news text color VertLineColor = Peru; // Color of our vertical news line color VertTxtColor = Peru; // Color of our vertical text color int VertTxtSize = 8; extern bool ShowNewsOnChart=true; int NewsWindow =0; // Color of our vertical text int NewsCorner = 0; // Choose which corner to place headlines 0=Upper Left, 1=Upper Right, 2=lower left , 3=lower right bool SaveXmlFiles = false; // If true, this will keep the daily XML files int DebugLevel = 5; string noteBox = "Box Parameters"; bool Newsbox_on = true; color BoxColor = DimGray; color BoxColor2 = C'35,35,35'; double ExtMapBuffer0[]; // Contains (minutes until) each news event double ExtMapBuffer1[]; // Contains only most recent and next news event ([0] & [1]) double ExtMapBuffer2[]; // Contains impact value for most recent and next news event string sUrl = "http://cdn.forexfactory.com/ffcal_week_this.xml"; int xmlHandle; int logHandle = -1; int BoEvent, finalend, end, i; int begin; string mainData[100][7]; int minsTillNews; string sData, csvoutput; string commentStr; int tmpMins; int idxOfNext; int dispMinutes[2]; string dispTitle[2], dispCountry[2], dispImpact[2], dispForecast[2], dispPrevious[2]; string sTags[7] = { "", "<country>", "<date>", "<time>", "<impact>", "<forecast>", "<previous>" }; string eTags[7] = { "", "", "", "", "", "", "" }; static bool NeedToGetFile = false; static int PrevMinute = -1; static int RefreshMin = 0; static int RefreshHour = 0; datetime LastTimeAlert1 = 0; // Used to make sure we only draw something once per annoucement. Added by MN string xmlFileName; // Made global. added by MN int BarForLabels= 10; double Res3[], Res2[], Res1[], Pivot[], Sup1[], Sup2[], Sup3[]; double thresholdBuffer[]; double vol_m[]; double vol_t[]; double ind_c[]; double PDayHigh, PDayLow; string ThisSymbol; datetime BarTime, PivotDayStartTime; string txtv; static datetime LastTradeBarTime; int VisibleBars, DayStartBar, LeftMostBar, RightMostBar; int multiply; int MyPoint; int pip,pip2,pip3,pipd; int shiftx = 1; int shifty = 1; string NAME= "Hamyar System Version 2.0"; string BS1, BS2, BS3, TpB1, TpB2, TpB3, StB1, StB2, StB3; string SS1, SS2, SS3, TpS1, TpS2, TpS3, StS1, StS2, StS3; string Tp1, Tp2, Tp3, Tp4, St1, St2, St3, St4, PRICE; color PriceColor; //-------------------------------------------------------------------- // Initialization //-------------------------------------------------------------------- int init() { if( ShowNewsOnChart) { NewsWindow =0; // Color of our vertical text NewsCorner = 0; } else { NewsWindow =1; // Color of our vertical text NewsCorner = 3; } DeleteObjects(); for (int i=0; i 0) Print("In Init()...\n"); MathSrand(TimeLocal()); RefreshMin = (MathRand() % 60); RefreshHour = (MathRand() % 6); if (DebugLevel > 0) { Print("RefreshMin == ", RefreshMin); Print("RefreshHour == ", RefreshHour); } SetIndexBuffer( 0, Pivot); SetIndexBuffer( 1, Sup1); SetIndexBuffer( 2, Res1); SetIndexBuffer( 3, Sup2); SetIndexBuffer( 4, Res2); SetIndexBuffer( 5, Sup3); SetIndexBuffer( 6, Res3); SetIndexStyle(0, DRAW_LINE); SetIndexStyle(1, DRAW_LINE); SetIndexStyle(2, DRAW_LINE); SetIndexStyle(3, DRAW_LINE); SetIndexStyle(4, DRAW_LINE); SetIndexStyle(5, DRAW_LINE,STYLE_DASH); SetIndexStyle(6, DRAW_LINE,STYLE_DASH); SetIndexEmptyValue( 0, EMPTY_VALUE ); SetIndexEmptyValue( 1, EMPTY_VALUE ); SetIndexEmptyValue( 2, EMPTY_VALUE ); SetIndexEmptyValue( 3, EMPTY_VALUE ); SetIndexEmptyValue( 4, EMPTY_VALUE ); SetIndexEmptyValue( 5, EMPTY_VALUE ); SetIndexEmptyValue( 6, EMPTY_VALUE ); SetIndexLabel( 0, "Pivot" ); SetIndexLabel( 1, "SellZone" ); SetIndexLabel( 2, "BuyZone" ); SetIndexLabel( 3, "SellTP1" ); SetIndexLabel( 4, "BuyTP1" ); SetIndexLabel( 5, "SellTP2" ); SetIndexLabel( 6, "BuyTP2" ); if(Digits==3||Digits==5)MyPoint=10; else MyPoint=1; if(Digits==3)multiply=100; if(Digits==2)multiply=100; if(Digits==5)multiply=10000; if(Digits==4)multiply=10000; ThisSymbol = Symbol(); PivotDayStartTime = 0; ArrayResize(vol_m,Bars); ArrayResize(vol_t,Bars); ArrayResize(thresholdBuffer,Bars); ArrayResize(ind_c,Bars); ArrayInitialize(ind_c,0.0); ArrayInitialize(vol_m,0.0); ArrayInitialize(vol_t,0.0); ArrayInitialize(thresholdBuffer,0.0); LastTradeBarTime = Time[1]; return(0); } //-------------------------------------------------------------------- //| De-initialization | //-------------------------------------------------------------------- int deinit() { DeleteObjects(); int i; Comment(""); ObjectDelete ("xAlarm_label4"); ObjectDelete ("xAlarm_label3"); ObjectDelete ("bNewsBox"); ObjectDelete ("bNewsBox2"); ObjectDelete ("aNewsBoxb"); ObjectDelete ("bNewsBox2b"); ObjectDelete ("xAlarm_label"); ObjectDelete ("xAlarm_label2"); ObjectDelete("Sponsor"); ObjectDelete("Minutes"); ObjectDelete("Impact"); ObjectDelete("Previous"); ObjectDelete("Forecast"); ObjectDelete("Minutes2"); ObjectDelete("Impact2"); ObjectDelete("Previous2"); ObjectDelete("Forecast2"); ObjectDelete("aNewsBox"); // Cycle through all the Objects looking for the Vertical Line. //added by MN for(i=ObjectsTotal()-1; i >= 0; i--) { string VerticalLineName = ObjectName(i); if (StringSubstr(VerticalLineName, 0, 5) != "vLine") continue; ObjectDelete(VerticalLineName); } // Cycle through all the Objects looking for the HeadLine text. //added by MN for (i=ObjectsTotal()-1; i >= 0; i--) { string HeadlineName = ObjectName(i); if (StringSubstr(HeadlineName, 0, 8) != "Headline") continue; ObjectDelete(HeadlineName); } // Fixed one case of divide by zero where multiple charts // indicator is on was trying to overwrite the same file xmlFileName = GetXmlFileName(); xmlHandle = FileOpen(xmlFileName, FILE_BIN|FILE_READ|FILE_WRITE); // File does not exist if FileOpen return -1 or if GetLastError = ERR_CANNOT_OPEN_FILE (4103) if (xmlHandle >= 0) { // Since file exists, Close what we just opened FileClose(xmlHandle); // Delete our news file and redownload a new one to prevent a remainder from zero divide error if (!SaveXmlFiles) FileDelete(xmlFileName); } ObjectDelete("BUYAREAARROW"); ObjectDelete("SELLAREAARROW"); int obj_total= ObjectsTotal(); for (i= obj_total; i>=0; i--) { string name= ObjectName(i); if (StringSubstr(name,0,7)=="[PIVOT]") ObjectDelete(name); } obj_total= ObjectsTotal(); for ( i= obj_total; i>=0; i--) { name= ObjectName(i); if (StringSubstr(name,0,4)=="info") ObjectDelete(name); } obj_total= ObjectsTotal(); ObjectDelete("YesterdayStart"); ObjectDelete("YesterdayEnd"); ObjectDelete("YesterdayStart Label"); ObjectDelete("YesterdayEnd Label"); ObjectDelete("BackGroundA01"); ObjectDelete("BackGroundA02"); ObjectDelete("BackGroundA03"); ObjectDelete("BackGroundA04"); ObjectDelete("BackGroundB01"); ObjectDelete("BackGroundB02"); ObjectDelete("BackGroundB03"); ObjectDelete("BackGroundB04"); ObjectDelete("Pivot Label"); ObjectDelete("Pivot Line"); string types= "RSHLM"; for ( i= 0; i=0; i--) { name= ObjectName(i); if (StringSubstr(name,0,2)=="h2") ObjectDelete(name); } /* string BS1, BS2, BS3, TpB1, TpB2, TpB3, StB1, StB2, StB3; string SS1, SS2, SS3, TpS1, TpS2, TpS3, StS1, StS2, StS3; */ return(0); } //-------------------------------------------------------------------- //| Main iteration | //-------------------------------------------------------------------- int start() { datetime dt=CurTime(); if (ShowSessions){ for (int i=0; i5) dt=decDateTradeDay(dt); } } if (ShowNews)shownews(); datetime startofday=0; datetime endofday=0; int Count; double Range; int first5,first15,first30,first1h,first4h,second5,second15,second30,second1h,second4h; if (Display){ ObjectCreate("SELLAREAARROW", OBJ_ARROW, 0, 0, 0); ObjectSet("SELLAREAARROW",OBJPROP_ARROWCODE,238); ObjectSet("SELLAREAARROW",OBJPROP_COLOR,Red); ObjectSet("SELLAREAARROW",OBJPROP_WIDTH,1); ObjectCreate("BUYAREAARROW", OBJ_ARROW, 0, 0, 0); ObjectSet("BUYAREAARROW",OBJPROP_ARROWCODE,236); ObjectSet("BUYAREAARROW",OBJPROP_COLOR,DodgerBlue); ObjectSet("BUYAREAARROW",OBJPROP_WIDTH,1); } i =NumberOfDays*((60*24)/Period())+1*((60*24)/Period()); startofday=iTime(Symbol(),PERIOD_D1,0)-(LocalTimeZone*60); endofday=startofday+1440*60; while(i >=0) { if( PivotDay( Time[i+1], LocalTimeZone ) != PivotDay( Time[i], LocalTimeZone ) ) { Count = iBarShift( NULL, 0, PivotDayStartTime ) - i; PDayHigh = High[ iHighest( NULL, 0, MODE_HIGH, Count, i+1 ) ]; PDayLow = Low[ iLowest( NULL, 0, MODE_LOW, Count, i+1 ) ]; double pip1=iATR(Symbol(),gettimeframe(ATRTimeframe-2),ATR_Period,iBarShift(Symbol(),gettimeframe(ATRTimeframe-2),PivotDayStartTime,false))*multiply; pip=iATR(Symbol(),gettimeframe(ATRTimeframe-1),ATR_Period,iBarShift(Symbol(),gettimeframe(ATRTimeframe-1),PivotDayStartTime,false))*multiply; pip2=iATR(Symbol(),gettimeframe(ATRTimeframe+1),ATR_Period,iBarShift(Symbol(),gettimeframe(ATRTimeframe+1),PivotDayStartTime,false))*multiply; pip3=iATR(Symbol(),gettimeframe(ATRTimeframe),ATR_Period,iBarShift(Symbol(),gettimeframe(ATRTimeframe),PivotDayStartTime,false))*multiply; Pivot[i] = ( PDayHigh + PDayLow + Close[i+1] ) / 3; Range = PDayHigh - PDayLow; if(Close[i]>iMA(Symbol(),0,ATR_Period,0,1,0,i)) { Res1[i] =Pivot[i]+ (pip)*Point*MyPoint; Res2[i] = Res1[i]+ (pip)*Point*MyPoint; Res3[i] = Pivot[i] + (pip2+pip3-pip1)*Point*MyPoint; Sup1[i] = Pivot[i] - pip3*Point*MyPoint; Sup2[i] = Sup1[i] - pip*Point*MyPoint; Sup3[i] = Pivot[i] - (pip2+pip3)*Point*MyPoint; } if(Close[i]Res1[0]) PriceColor = DeepSkyBlue; if(iMA(Symbol(),0,1,0,MODE_EMA,PRICE_CLOSE,0)Res1[0]) PriceColor = DeepSkyBlue; if(iMA(Symbol(),0,1,0,MODE_EMA,PRICE_CLOSE,0)0) ObjectDelete(lblname); ObjectCreate(lblname, OBJ_LABEL,0, 0, 0); ObjectSet(lblname, OBJPROP_CORNER, 2); ObjectSetText(lblname,txt,9,"Tahoma", txtcolor); ObjectSet(lblname, OBJPROP_XDISTANCE, x); ObjectSet(lblname, OBJPROP_CORNER, 2); ObjectSet(lblname, OBJPROP_YDISTANCE, y); } void clabel3(string lblname,int x,int y,string txt,color txtcolor) { if (ObjectFind( lblname)>0) ObjectDelete(lblname); ObjectCreate(lblname, OBJ_LABEL,0, 0, 0); ObjectSet(lblname, OBJPROP_CORNER, 2); ObjectSetText(lblname,txt,9,"Tahoma", txtcolor); ObjectSet(lblname, OBJPROP_XDISTANCE, x); ObjectSet(lblname, OBJPROP_CORNER, 0); ObjectSet(lblname, OBJPROP_YDISTANCE, y); } void clabel(string lblname,int x,int y,string txt,color txtcolor) { if (ObjectFind( lblname)>0) ObjectDelete(lblname); ObjectCreate(lblname, OBJ_LABEL,0, 0, 0); ObjectSet(lblname, OBJPROP_CORNER, 1); ObjectSetText(lblname,txt,9,"Tahoma", txtcolor); ObjectSet(lblname, OBJPROP_XDISTANCE, x); ObjectSet(lblname, OBJPROP_CORNER, 1); ObjectSet(lblname, OBJPROP_YDISTANCE, y); } */ int volat(int i,int timeframe,int period) { int signal=-1; double vol=0; int Viscosity=MathRound(period/3); int Sedimentation=period; double Threshold_level=1.1; bool lag_supressor=true; double lag_s_K=0.5; double sa=iATR(NULL,gettimeframe(timeframe),Viscosity,i); double t1=ind_c[i+1]; double t3=ind_c[i+3]; double atr=NormalizeDouble(sa,Digits); if(lag_supressor) vol= sa/iATR(NULL,0,Sedimentation,i)+lag_s_K*(t1-t3); else vol= sa/iATR(NULL,0,Sedimentation,i); double anti_thres=iStdDev(NULL,gettimeframe(timeframe),Viscosity,0,MODE_LWMA,PRICE_TYPICAL,i); anti_thres=anti_thres/ iStdDev(NULL,gettimeframe(timeframe),Sedimentation,0,MODE_LWMA,PRICE_TYPICAL,i); double t=Threshold_level; t=t-anti_thres; if (vol>t){vol_t[i]=vol;vol_m[i]=vol; signal=1;} else {vol_t[i]=vol;vol_m[i]=EMPTY_VALUE; signal=2;} ind_c[i]=vol; thresholdBuffer[i]=t; return(signal); } int TextLabel(string lblname, int xOffset, int yOffset,int iCorner, string Text, int FontSize, string FontName, color txtcolor) { if (ObjectFind( lblname)>0) ObjectDelete(lblname); ObjectCreate(lblname,OBJ_LABEL , 0, 0, 0 ); ObjectSet (lblname,OBJPROP_CORNER , iCorner); ObjectSet (lblname,OBJPROP_XDISTANCE , xOffset); ObjectSet (lblname,OBJPROP_YDISTANCE , yOffset); ObjectSet (lblname,OBJPROP_BACK , false ); ObjectSetText( lblname, Text, FontSize, FontName, txtcolor ); } string getpower(int TF1 ,int TF2,int TF3 ,string tr) { int maTrendPeriodv_1 = 5; int maTrendPeriodv_2 = 8; int maTrendPeriodv_3 = 13; int maTrendPeriodv_4 = 21; int maTrendPeriodv_5 = 34; double MaH11v, MaH41v, MaD11v, MaH1pr1v, MaH4pr1v, MaD1pr1v; double MaH12v, MaH42v, MaD12v, MaH1pr2v, MaH4pr2v, MaD1pr2v; double MaH13v, MaH43v, MaD13v, MaH1pr3v, MaH4pr3v, MaD1pr3v; double MaH14v, MaH44v, MaD14v, MaH1pr4v, MaH4pr4v, MaD1pr4v; double MaH15v, MaH45v, MaD15v, MaH1pr5v, MaH4pr5v, MaD1pr5v; string H11v, H41v, D11v; string H12v, H42v, D12v; string H13v, H43v, D13v; string H14v, H44v, D14v; string H15v, H45v, D15v; color co11v , co41v , co61v; color co12v , co42v , co62v; color co13v , co43v , co63v; color co14v , co44v , co64v; color co15v , co45v , co65v; double u1x5v, u1x8v, u1x13v, u1x21v, u1x34v; double u2x5v, u2x8v, u2x13v, u2x21v, u2x34v; double u3x5v, u3x8v, u3x13v, u3x21v, u3x34v; double u1acv, u2acv, u3acv; double d1x5v, d1x8v, d1x13v, d1x21v, d1x34v; double d2x5v, d2x8v, d2x13v, d2x21v, d2x34v; double d3x5v, d3x8v, d3x13v, d3x21v, d3x34v; double d1acv, d2acv, d3acv; MaH11v=iMA(NULL,TF1,maTrendPeriodv_1,0,MODE_SMA,PRICE_CLOSE,0); MaH1pr1v=iMA(NULL,TF1,maTrendPeriodv_1,0,MODE_SMA,PRICE_CLOSE,1); MaH12v=iMA(NULL,TF1,maTrendPeriodv_2,0,MODE_SMA,PRICE_CLOSE,0); MaH1pr2v=iMA(NULL,TF1,maTrendPeriodv_2,0,MODE_SMA,PRICE_CLOSE,1); MaH13v=iMA(NULL,TF1,maTrendPeriodv_3,0,MODE_SMA,PRICE_CLOSE,0); MaH1pr3v=iMA(NULL,TF1,maTrendPeriodv_3,0,MODE_SMA,PRICE_CLOSE,1); MaH14v=iMA(NULL,TF1,maTrendPeriodv_4,0,MODE_SMA,PRICE_CLOSE,0); MaH1pr4v=iMA(NULL,TF1,maTrendPeriodv_4,0,MODE_SMA,PRICE_CLOSE,1); MaH15v=iMA(NULL,TF1,maTrendPeriodv_5,0,MODE_SMA,PRICE_CLOSE,0); MaH1pr5v=iMA(NULL,TF1,maTrendPeriodv_5,0,MODE_SMA,PRICE_CLOSE,1); MaH41v=iMA(NULL,TF2,maTrendPeriodv_1,0,MODE_SMA,PRICE_CLOSE,0); MaH4pr1v=iMA(NULL,TF2,maTrendPeriodv_1,0,MODE_SMA,PRICE_CLOSE,1); MaH42v=iMA(NULL,TF2,maTrendPeriodv_2,0,MODE_SMA,PRICE_CLOSE,0); MaH4pr2v=iMA(NULL,TF2,maTrendPeriodv_2,0,MODE_SMA,PRICE_CLOSE,1); MaH43v=iMA(NULL,TF2,maTrendPeriodv_3,0,MODE_SMA,PRICE_CLOSE,0); MaH4pr3v=iMA(NULL,TF2,maTrendPeriodv_3,0,MODE_SMA,PRICE_CLOSE,1); MaH44v=iMA(NULL,TF2,maTrendPeriodv_4,0,MODE_SMA,PRICE_CLOSE,0); MaH4pr4v=iMA(NULL,TF2,maTrendPeriodv_4,0,MODE_SMA,PRICE_CLOSE,1); MaH45v=iMA(NULL,TF2,maTrendPeriodv_5,0,MODE_SMA,PRICE_CLOSE,0); MaH4pr5v=iMA(NULL,TF2,maTrendPeriodv_5,0,MODE_SMA,PRICE_CLOSE,1); MaD11v=iMA(NULL,TF3,maTrendPeriodv_1,0,MODE_SMA,PRICE_CLOSE,0); MaD1pr1v=iMA(NULL,TF3,maTrendPeriodv_1,0,MODE_SMA,PRICE_CLOSE,1); MaD12v=iMA(NULL,TF3,maTrendPeriodv_2,0,MODE_SMA,PRICE_CLOSE,0); MaD1pr2v=iMA(NULL,TF3,maTrendPeriodv_2,0,MODE_SMA,PRICE_CLOSE,1); MaD13v=iMA(NULL,TF3,maTrendPeriodv_3,0,MODE_SMA,PRICE_CLOSE,0); MaD1pr3v=iMA(NULL,TF3,maTrendPeriodv_3,0,MODE_SMA,PRICE_CLOSE,1); MaD14v=iMA(NULL,TF3,maTrendPeriodv_4,0,MODE_SMA,PRICE_CLOSE,0); MaD1pr4v=iMA(NULL,TF3,maTrendPeriodv_4,0,MODE_SMA,PRICE_CLOSE,1); MaD15v=iMA(NULL,TF3,maTrendPeriodv_5,0,MODE_SMA,PRICE_CLOSE,0); MaD1pr5v=iMA(NULL,TF3,maTrendPeriodv_5,0,MODE_SMA,PRICE_CLOSE,1); if (MaH11v < MaH1pr1v){H11v = " V "; co11v = Red; u1x5v = 0; d1x5v = 1;} if (MaH11v > MaH1pr1v){H11v = " /\\ "; co11v = Blue; u1x5v = 1; d1x5v = 0;} if (MaH11v == MaH1pr1v){H11v = " 0 "; co11v = Green; u1x5v = 0; d1x5v = 0;} if (MaH41v < MaH4pr1v){H41v = " V "; co41v = Red; u2x5v = 0; d2x5v = 1;} if (MaH41v > MaH4pr1v){H41v = " /\\ "; co41v = Blue; u2x5v = 1; d2x5v = 0;} if (MaH41v == MaH4pr1v){H41v = " 0 "; co41v = Green; u2x5v = 0; d2x5v = 0;} if (MaD11v < MaD1pr1v){D11v = " V "; co61v = Red; u3x5v = 0; d3x5v = 1;} if (MaD11v > MaD1pr1v){D11v = " /\\ "; co61v = Blue; u3x5v = 1; d3x5v = 0;} if (MaD11v == MaD1pr1v){D11v = " 0 "; co61v = Green; u3x5v = 0; d3x5v = 0;} if (MaH12v < MaH1pr2v){H12v = " V "; co12v = Red; u1x8v = 0; d1x8v = 1;} if (MaH12v > MaH1pr2v){H12v = " /\\ "; co12v = Blue; u1x8v = 1; d1x8v = 0;} if (MaH12v == MaH1pr2v){H12v = " 0 "; co12v = Green; u1x8v = 0; d1x8v = 0;} if (MaH42v < MaH4pr2v){H42v = " V "; co42v = Red; u2x8v = 0; d2x8v = 1;} if (MaH42v > MaH4pr2v){H42v = " /\\ "; co42v = Blue; u2x8v = 1; d2x8v = 0;} if (MaH42v == MaH4pr2v){H42v = " 0 "; co42v = Green; u2x8v = 0; d2x8v = 0;} if (MaD12v < MaD1pr2v){D12v = " V "; co62v = Red; u3x8v = 0; d3x8v = 1;} if (MaD12v > MaD1pr2v){D12v = " /\\ "; co62v = Blue; u3x8v = 1; d3x8v = 0;} if (MaD12v == MaD1pr2v){D12v = " 0 "; co62v = Green; u3x8v = 0; d3x8v = 0;} if (MaH13v < MaH1pr3v){H13v = " V "; co13v = Red; u1x13v = 0; d1x13v = 1;} if (MaH13v > MaH1pr3v){H13v = " /\\ "; co13v = Blue; u1x13v = 1; d1x13v = 0;} if (MaH13v ==MaH1pr3v){H13v = " 0 "; co13v = Green; u1x13v = 0; d1x13v = 0;} if (MaH43v < MaH4pr3v){H43v = " V "; co43v = Red; u2x13v = 0; d2x13v = 1;} if (MaH43v > MaH4pr3v){H43v = " /\\ "; co43v = Blue; u2x13v = 1; d2x13v = 0;} if (MaH43v ==MaH4pr3v){H43v = " 0 "; co43v = Green; u2x13v = 0; d2x13v = 0;} if (MaD13v < MaD1pr3v){D13v = " V "; co63v = Red; u3x13v = 0; d3x13v = 1;} if (MaD13v > MaD1pr3v){D13v = " /\\ "; co63v = Blue; u3x13v = 1; d3x13v = 0;} if (MaD13v ==MaD1pr3v){D13v = " 0 "; co63v = Green; u3x13v = 0; d3x13v = 0;} if (MaH14v < MaH1pr4v){H14v = " V "; co14v = Red; u1x21v = 0; d1x21v = 1;} if (MaH14v > MaH1pr4v){H14v = " /\\ "; co14v = Blue; u1x21v = 1; d1x21v = 0;} if (MaH14v == MaH1pr4v){H14v = " 0 "; co14v = Green; u1x21v = 0; d1x21v = 0;} if (MaH44v < MaH4pr4v){H44v = " V "; co44v = Red; u2x21v = 0; d2x21v = 1;} if (MaH44v > MaH4pr4v){H44v = " /\\ "; co44v = Blue; u2x21v = 1; d2x21v = 0;} if (MaH44v == MaH4pr4v){H44v = " 0 "; co44v = Green; u2x21v = 0; d2x21v = 0;} if (MaD14v < MaD1pr4v){D14v = " V "; co64v = Red; u3x21v = 0; d3x21v = 1;} if (MaD14v > MaD1pr4v){D14v = " /\\ "; co64v = Blue; u3x21v = 1; d3x21v = 0;} if (MaD14v == MaD1pr4v){D14v = " 0 "; co64v = Green; u3x21v = 0; d3x21v = 0;} if (MaH15v < MaH1pr5v){H15v = " V "; co15v = Red; u1x34v = 0; d1x34v = 1;} if (MaH15v > MaH1pr5v){H15v = " /\\ "; co15v = Blue; u1x34v = 1; d1x34v = 0;} if (MaH15v == MaH1pr5v){H15v = " 0 "; co15v = Green; u1x34v = 0; d1x34v = 0;} if (MaH45v < MaH4pr5v){H45v = " V "; co45v = Red; u2x34v = 0; d2x34v = 1;} if (MaH45v > MaH4pr5v){H45v = " /\\ "; co45v = Blue; u2x34v = 1; d2x34v = 0;} if (MaH45v == MaH4pr5v){H45v = " 0 "; co45v = Green; u2x34v = 0; d2x34v = 0;} if (MaD15v < MaD1pr5v){D15v = " V "; co65v = Red; u3x34v = 0; d3x34v = 1;} if (MaD15v > MaD1pr5v){D15v = " /\\ "; co65v = Blue; u3x34v = 1; d3x34v = 0;} if (MaD15v == MaD1pr5v){D15v = " 0 "; co65v = Green; u3x34v = 0; d3x34v = 0;} double acv = iAC(NULL, TF1, 0); double ac1v = iAC(NULL, TF1, 1); double ac2v = iAC(NULL, TF1, 2); double ac3v = iAC(NULL, TF1, 3); //double ac4 = iAO(NULL, 0, 4); string ach11v; color acco11v; if ((ac1v>ac2v && ac2v>ac3v && acv<0 && acv>ac1v) || (acv>ac1v && ac1v>ac2v && acv>0)) {ach11v = "/\\ " ; acco11v = Blue; u1acv = 3; d1acv = 0;} if ((ac1v0 && acvac1v) || (acv>ac1v && ac1v0))|| (((ac1v>ac2v || ac2v>ac3v) && acv>0 && acvac2v && acv<0))) {ach11v = "0 " ; acco11v = Green; u1acv = 0; d1acv = 0;} double ac03v = iAC(NULL, TF3, 0); double ac13v = iAC(NULL, TF3, 1); double ac23v = iAC(NULL, TF3, 2); double ac33v = iAC(NULL, TF3, 3); //double ac4 = iAO(NULL, 0, 4); string ach13v; color acco13v; if ((ac13v>ac23v && ac23v>ac33v && ac03v<0 && ac03v>ac13v) || (ac03v>ac13v && ac13v>ac23v && ac03v>0)) {ach13v = "/\\ " ; acco13v = Blue; u3acv = 3; d3acv = 0;} if ((ac13v0 && ac03vac13v) || (ac03v>ac13v && ac13v0))|| (((ac13v>ac23v || ac23v>ac33v) && ac03v>0 && ac03vac23v && ac03v<0))) {ach13v = "0 " ; acco13v = Green; u3acv = 0; d3acv = 0;} double ac02v = iAC(NULL, TF2, 0); double ac12v = iAC(NULL, TF2, 1); double ac22v = iAC(NULL, TF2, 2); double ac32v = iAC(NULL, TF2, 3); //double ac4 = iAO(NULL, 0, 4); string ach12v; color acco12v; if ((ac12v>ac22v && ac22v>ac32v && ac02v<0 && ac02v>ac12v) || (ac02v>ac12v && ac12v>ac22v && ac02v>0)) {ach12v = "/\\ " ; acco12v = Blue; u2acv = 3; d2acv = 0;} if ((ac12v0 && ac02vac12v) || (ac02v>ac12v && ac12v0))|| (((ac12v>ac22v || ac22v>ac32v) && ac02v>0 && ac02vac22v && ac02v<0))) {ach12v = "0 " ; acco12v = Green; u2acv = 0; d2acv = 0;} double uitog1v = (u1x5v + u1x8v + u1x13v + u1x21v + u1x34v + u1acv) * 12.5; double uitog2v = (u2x5v + u2x8v + u2x13v + u2x21v + u2x34v + u2acv) * 12.5; double uitog3v = (u3x5v + u3x8v + u3x13v + u3x21v + u3x34v + u3acv) * 12.5; double ditog1v = (d1x5v + d1x8v + d1x13v + d1x21v + d1x34v + d1acv) * 12.5; double ditog2v = (d2x5v + d2x8v + d2x13v + d2x21v + d2x34v + d2acv) * 12.5; double ditog3v = (d3x5v + d3x8v + d3x13v + d3x21v + d3x34v + d3acv) * 12.5; string hr1v, hr2v, hr3v, hr4v, hr5v,hr6v; string dhr1v, dhr2v, dhr3v, dhr4v, dhr5v, dhr6v; if (uitog1v> ditog1v) {hr1v = "Arial Black"; dhr1v = "Arial";} if (uitog1v< ditog1v) {hr1v = "Arial"; dhr1v = "Arial Black";} if (uitog1v == ditog1v) {hr1v = "Arial"; dhr1v = "Arial";} if (uitog2v> ditog2v) {hr2v = "Arial Black"; dhr2v = "Arial";} if (uitog2v< ditog2v) {hr2v = "Arial"; dhr2v = "Arial Black";} if (uitog2v == ditog2v) {hr2v = "Arial"; dhr2v = "Arial";} if (uitog3v> ditog3v) {hr3v = "Arial Black"; dhr3v = "Arial";} if (uitog3v< ditog3v) {hr3v = "Arial"; dhr3v = "Arial Black";} if (uitog3v == ditog3v) {hr3v = "Arial"; dhr3v = "Arial";} if (uitog1v > 50 && uitog2v > 50 && uitog3v > 50) {if (English)txtv = "Looks Good For BUY";else txtv = "تا حدودي براي خريد مناسب است"; } else {if (English)txtv = "WAIT.(Danger!!!)";else txtv = "نامساعد .موقعيت مناسب نميباشد";} if (ditog1v > 50 && ditog2v > 50 && ditog3v > 50) {if (English)txtv = "Look Good For Sell";else txtv = "تاحدودي براي فروش مناسب است";} if (uitog1v >= 75 && uitog2v >= 75 && uitog3v >= 75) {if (English)txtv = "Good Buy";else txtv = "موقعيت خريد مناسب";} if (ditog1v >= 75 && ditog2v >= 75 && ditog3v >= 75) {if (English)txtv = "Good Sell";else txtv = "موقعيت فروش مناسب";} if (tr=="Bullish"||tr=="صعودي") return("%"+DoubleToStr(uitog1v,1)); if (tr=="Bearish"||tr=="نزولي") return("%"+DoubleToStr(ditog1v,1)); } void CreateObjects(string no, color cl) { ObjectCreate(no, OBJ_RECTANGLE, 0, 0,0, 0,0); ObjectSet(no, OBJPROP_STYLE, STYLE_SOLID); ObjectSet(no, OBJPROP_COLOR, cl); ObjectSet(no, OBJPROP_BACK, false); } void DeleteObjects() { for (int i=0; i0&& Alert2MinsBefore>0) { ObjectCreate("xAlarm_label3", OBJ_LABEL, NewsWindow, 0, 0, 0, 0); ObjectSetText("xAlarm_label3", "Alarm : "+ "ON", 9, "Arial"); ObjectSet("xAlarm_label3", OBJPROP_CORNER, NewsCorner); ObjectSet("xAlarm_label3", OBJPROP_XDISTANCE, shiftx+240); ObjectSet("xAlarm_label3", OBJPROP_YDISTANCE, shifty+140); ObjectSet("xAlarm_label3", OBJPROP_COLOR, Green); ObjectSet("xAlarm_label3", OBJPROP_BACK, false); } //NewsBox */ // Added this section to check if the XML file already exists. // If it does NOT, then we need to set a flag to go get it xmlFileName = GetXmlFileName(); xmlHandle = FileOpen(xmlFileName, FILE_BIN|FILE_READ); // File does not exist if FileOpen return -1 or if GetLastError = ERR_CANNOT_OPEN_FILE (4103) if (xmlHandle >= 0) { // Since file exists, close what we just opened FileClose(xmlHandle); NeedToGetFile = false; } else NeedToGetFile = true; //added by MN. Set this to false when using in another EA or Chart, so that the multiple //instances of the indicator dont fight with each other if (AllowWebUpdates) { // New method: Use global variables so that when put on multiple charts, it // will not update overly often; only first time and every 4 hours if (DebugLevel > 1) Print(GlobalVariableGet("LastUpdateTime") + " " + (TimeCurrent() - GlobalVariableGet("LastUpdateTime"))); if (NeedToGetFile || GlobalVariableCheck("LastUpdateTime") == false || (TimeCurrent() - GlobalVariableGet("LastUpdateTime")) > 14400) { if (DebugLevel > 1) Print("sUrl == ", sUrl); if (DebugLevel > 0) Print("Grabbing Web, url = ", sUrl); // THIS CALL WAS DONATED BY PAUL TO HELP FIX THE RESOURCE ERROR GrabWeb(sUrl, sData); if (DebugLevel > 0) { Print("Opening XML file...\n"); Print(sData); } // Delete existing file FileDelete(xmlFileName); // Write the contents of the ForexFactory page to an .htm file // If it is still open from the above FileOpen call, close it. xmlHandle = FileOpen(xmlFileName, FILE_BIN|FILE_WRITE); if (xmlHandle < 0) { if (DebugLevel > 0) Print("Can\'t open new xml file, the last error is ", GetLastError()); return(false); } FileWriteString(xmlHandle, sData, StringLen(sData)); FileClose(xmlHandle); if (DebugLevel > 0) Print("Wrote XML file...\n"); // THIS BLOCK OF CODE DONATED BY WALLY TO FIX THE RESOURCE ERROR //--- Look for the end XML tag to ensure that a complete page was downloaded ---// end = StringFind(sData, "", 0); if (end <= 0) { Alert("HamyarNews Error - Web page download was not complete!"); return(false); } else { // set global to time of last update GlobalVariableSet("LastUpdateTime", TimeCurrent()); } //-------------------------------------------------------------------------------// } } //end of allow web updates // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = // Perform remaining checks once per minute if (!IsEA_Call && Minute() == PrevMinute) return (true); PrevMinute = Minute(); // Print("FFCal NEW MINUTE...Refreshing News from XML file..."); // Open the log file (will not open if logging is turned off) OpenLog("FFCal"); // Init the buffer array to zero just in case ArrayInitialize(ExtMapBuffer0, 0); ArrayInitialize(ExtMapBuffer1, 0); // Open the XML file xmlHandle = FileOpen(xmlFileName, FILE_BIN|FILE_READ); if (xmlHandle < 0) { Print("Can\'t open xml file: ", xmlFileName, ". The last error is ", GetLastError()); return(false); } if (DebugLevel > 0) Print("XML file open must be okay"); // Read in the whole XML file // Ave file length == ~7K, so 65536 should always read whole file sData = FileReadString(xmlHandle, 65536); if (StringLen(sData) < FileSize(xmlHandle)) sData = sData + FileReadString(xmlHandle, FileSize(xmlHandle)); // Because MT4 build 202 complained about too many files open and MT4 hung. Added by MN if (xmlHandle > 0) FileClose(xmlHandle); // Get the currency pair, and split it into the two countries string pair = Symbol(); string cntry1 = StringSubstr(pair, 0, 3); string cntry2 = StringSubstr(pair, 3, 3); if (DebugLevel > 0) Print("cntry1 = ", cntry1, " cntry2 = ", cntry2); if (DebugLevel > 0) Log("Weekly calendar for " + pair + "\n\n"); // ------------------------------------------------- // Parse the XML file looking for an event to report // ------------------------------------------------- tmpMins = 10080; // (a week) BoEvent = 0; while (true) { BoEvent = StringFind(sData, "", BoEvent); if (BoEvent == -1) break; BoEvent += 7; next = StringFind(sData, "", BoEvent); if (next == -1) break; myEvent = StringSubstr(sData, BoEvent, next - BoEvent); BoEvent = next; begin = 0; skip = false; for (i=0; i < 7; i++) { mainData[newsIdx][i] = ""; next = StringFind(myEvent, sTags[i], begin); // Within this event, if tag not found, then it must be missing; skip it if (next == -1) continue; else { // We must have found the sTag okay... begin = next + StringLen(sTags[i]); // Advance past the start tag end = StringFind(myEvent, eTags[i], begin); // Find start of end tag if (end > begin && end != -1) { // Get data between start and end tag mainData[newsIdx][i] = StringSubstr(myEvent, begin, end - begin); } } } // for (i=6; i >= 0; i--) // Print(sTags[i], " = ", mainData[newsIdx][i]); // = - = = - = = - = = - = = - = = - = = - = = - = = - = = - = // Test against filters that define whether we want to // skip this particular annoucement if (cntry1 != mainData[newsIdx][COUNTRY] && cntry2 != mainData[newsIdx][COUNTRY] && (!ReportAllForUSD || mainData[newsIdx][COUNTRY] != "USD")) skip = true; if (!ShowHigh && mainData[newsIdx][IMPACT] == "High") skip = true; if (!ShowMedium && mainData[newsIdx][IMPACT] == "Medium") skip = true; if (!ShowLow && mainData[newsIdx][IMPACT] == "Low") skip = true; if (!ShowSpeaks && (StringFind(mainData[newsIdx][TITLE], "speaks") != -1 || StringFind(mainData[newsIdx][TITLE], "Speaks") != -1) ) skip = true; if (mainData[newsIdx][TIME] == "All Day" || mainData[newsIdx][TIME] == "Tentative" || mainData[newsIdx][TIME] == "") skip = true; // = - = = - = = - = = - = = - = = - = = - = = - = = - = = - = // If not skipping this event, then log it into the draw buffers if (!skip) { // If we got this far then we need to calc the minutes until this event // // First, convert the announcement time to seconds (in GMT) newsTime = StrToTime(MakeDateTime(mainData[newsIdx][DATE], mainData[newsIdx][TIME])); // Now calculate the minutes until this announcement (may be negative) minsTillNews = (newsTime - TimeGMT()) / 60; if (DebugLevel > 0) { Log("FOREX FACTORY\nTitle: " + mainData[newsIdx][TITLE] + "\n" + minsTillNews + "\n\n"); } // This "if" section added by MN // If minsTillNews is zero, then it's the time our news is hit if ((minsTillNews == 0) && (LastTimeAlert1 != newsTime)) { // draw the 1st news event onto the chart vertically so // we have a visual record of when it occured DisplayVerticalNews(dispTitle[0], dispCountry[0], 0); // If there is a 2nd simultaneous news event, // display the 2nd news event if (dispMinutes[0] == dispMinutes[1]) DisplayVerticalNews(dispTitle[1], dispCountry[1], 1); // only draw once per announcement LastTimeAlert1 = newsTime; } // This "if" section added by MN // Back Draw old news onto the chart. Added by MN if (ShowVertNews && !IsEA_Call) { // Back draw 1st news headline DisplayOldNews(mainData[newsIdx][TITLE], mainData[newsIdx][COUNTRY], 0, StrToTime(MakeDateTime(mainData[newsIdx][DATE], mainData[newsIdx][TIME]))); //if there is a 2nd simultaneously occuring news headline, draw that onto the chart as well if (mainData[newsIdx][TIME] == mainData[newsIdx+1][TIME]) DisplayOldNews(mainData[newsIdx+1][TITLE], mainData[newsIdx+1][COUNTRY], 1, StrToTime(MakeDateTime(mainData[newsIdx+1][DATE], mainData[newsIdx+1][TIME]))); } // Keep track of the most recent news announcement. // Do that by saving each one until we get to the // first annoucement that isn't in the past; i.e. // minsTillNews > 0. Then, keep this one instead for // display, but only once the minutes until the next // news is SMALLER than the minutes since the last. // Print("Mins till event: ", minsTillNews); if (minsTillNews < 0 || MathAbs(tmpMins) > minsTillNews) { idxOfNext = newsIdx; tmpMins = minsTillNews; } Log("Weekly calendar for " + pair + "\n\n"); if (DebugLevel > 0) { Log("FOREX FACTORY\nTitle: " + mainData[newsIdx][TITLE] + "\nCountry: " + mainData[newsIdx][COUNTRY] + "\nDate: " + mainData[newsIdx][DATE] + "\nTime: " + mainData[newsIdx][TIME] + "\nImpact: " + mainData[newsIdx][IMPACT] + "\nForecast: " + mainData[newsIdx][FORECAST] + "\nPrevious: " + mainData[newsIdx][PREVIOUS] + "\n\n"); } // Do alert if user has enabled if (Alert1MinsBefore != -1 && minsTillNews == Alert1MinsBefore) Alert(Alert1MinsBefore, " minutes until news for ", pair, ": ", mainData[newsIdx][TITLE]); if (Alert2MinsBefore != -1 && minsTillNews == Alert2MinsBefore) Alert(Alert2MinsBefore, " minutes until news for ", pair, ": ", mainData[newsIdx][TITLE]); // Buffers are set up as so: // ExtMapBuffer0 contains the time UNTIL each announcement (can be negative) // e.g. [0] = -372; [1] = 25; [2] = 450; [3] = 1768 (etc.) // ExtMapBuffer1[0] has the mintutes since the last annoucement. // ExtMapBuffer1[1] has the mintutes until the next annoucement. ExtMapBuffer0[newsIdx] = minsTillNews; newsIdx++; } } // Cycle through the events array and pick out the most recent // past and the next coming event to put into ExtMapBuffer1. // Put the corresponding impact for these two into ExtMapBuffer2. bool first = true; ExtMapBuffer1[0] = 99999; ExtMapBuffer1[1] = 99999; ExtMapBuffer2[0] = 0; ExtMapBuffer2[1] = 0; string outNews = "Minutes until news events for " + pair + " : "; for (i=0; i < newsIdx; i++) { outNews = outNews + ExtMapBuffer0[i] + ", "; if (ExtMapBuffer0[i] >= 0 && first) { first = false; // Put the relevant info into the indicator buffers... // Minutes SINCE - - - - - - - - - - - - - - - - - - - - - - - - - // (does not apply if the first event of the week has not passed) if (i > 0) { ExtMapBuffer1[0] = MathAbs(ExtMapBuffer0[i-1]); ExtMapBuffer2[0] = ImpactToNumber(mainData[i-1][IMPACT]); } // Minutes UNTIL - - - - - - - - - - - - - - - - - - - - - - - - - // Check if past the last event. if (ExtMapBuffer0[i] > 0 || (ExtMapBuffer0[i] == 0 && ExtMapBuffer0[i+1] > 0)) { ExtMapBuffer1[1] = ExtMapBuffer0[i]; } ExtMapBuffer2[1] = ImpactToNumber(mainData[i][IMPACT]); } // Also use this loop to set which information to display if (i == idxOfNext) { dispTitle[0] = mainData[i][TITLE]; dispCountry[0] = mainData[i][COUNTRY]; dispImpact[0] = mainData[i][IMPACT]; dispForecast[0] = mainData[i][FORECAST]; dispPrevious[0] = mainData[i][PREVIOUS]; dispMinutes[0] = ExtMapBuffer0[i]; } if (i == idxOfNext + 1) { dispTitle[1] = mainData[i][TITLE]; dispCountry[1] = mainData[i][COUNTRY]; dispImpact[1] = mainData[i][IMPACT]; dispForecast[1] = mainData[i][FORECAST]; dispPrevious[1] = mainData[i][PREVIOUS]; dispMinutes[1] = ExtMapBuffer0[i]; } } // If we are past all news events, then neither one will have been // set, so set the past event to the last (negative) minutes if (ExtMapBuffer1[0] == 0 && ExtMapBuffer1[1] == 0) { ExtMapBuffer1[0] = ExtMapBuffer0[i-1]; ExtMapBuffer1[1] = 999999; // Ensures that we clean up so that we get old text // left behind on old news annoumcents. Added by MN ObjectDelete("Impact"); ObjectDelete("Previous"); ObjectDelete("Forecast"); ObjectDelete("Impact2"); ObjectDelete("Previous2"); ObjectDelete("Forecast2"); } // For debugging...Print the tines until news events, as a "Comment" if (DebugLevel > 0) { Print(outNews); Print("LastMins (ExtMapBuffer1[0]) = ", ExtMapBuffer1[0]); Print("NextMins (ExtMapBuffer1[1]) = ", ExtMapBuffer1[1]); } if (!IsEA_Call) OutputToChart(); if (logHandle > 0) { FileClose(logHandle); logHandle = -1; } return (0); } void DisplayVerticalNews(string dispTitle, string dispCountry, int shift) { double Pivot, Height = 0.0; // Calculate our pivot point to determine where to place the news text Pivot = (iHigh(NULL, 1440, 1) + iLow(NULL, 1440, 1) + iClose(NULL, 1440, 1)) / 3; // If Open price is above the Pivot determine our height if (Open[0] > Pivot) Height = Low[iLowest(NULL,0,MODE_LOW,5,0)] - VertTxtShift*Point; else // Otherwise Open is below Pivot Height = High[iHighest(NULL,0,MODE_HIGH,5,0)] + VertTxtShift*Point; if (shift == 0) { // Draw a vertical line at the time of the news if it hasnt already been drawn if (ObjectFind("vLine" + Time[0]) == -1) { ObjectCreate("vLine" + Time[0], OBJ_TREND, 0, Time[0], 0, Time[0], High[0]); // experimental ObjectSet("vLine" + Time[0], OBJPROP_COLOR, VertLineColor); ObjectSet("vLine" + Time[0], OBJPROP_STYLE, STYLE_DOT); // Put object in the background behind any other object on the chart ObjectSet("vLine" + Time[0], OBJPROP_BACK, true); } // Place our news if it hasnt already been placed on our chart if (ObjectFind("Headline" + Time[0]) == -1) { // For x value use Time[0], for y value find the lowest // bar within the last 10 bars, subtract by VertTxtShift // and used that as our y coordinate ObjectCreate("Headline" + Time[0], OBJ_TEXT, 0, Time[0] - VertLeftLineShift, Height); // Rotate the text 90 degrees ObjectSet("Headline" + Time[0], OBJPROP_ANGLE, 90); ObjectSetText("Headline" + Time[0], "News: " + dispCountry + " " + dispTitle, VertTxtSize, "Arial", VertTxtColor); } } // Draw second news headline else { //place our news if it hasnt already been placed on our chart if (ObjectFind("Headline" + Time[0]+"s") == -1) { // For x value use Time[0], for y value find the lowest // bar within the last 10 bars, subtract by VertTxtShift // and used that as our y coordinate ObjectCreate("Headline" + Time[0] + "s", OBJ_TEXT, 0, Time[0] + VertRightLineShift, Height); // Rotate the text 90 degrees ObjectSet("Headline" + Time[0] + "s", OBJPROP_ANGLE, 90); ObjectSetText("Headline" + Time[0] + "s", "News: " + dispCountry + " " + dispTitle, VertTxtSize, "Arial", VertTxtColor); } } //force a redraw of our chart WindowRedraw(); return(0); } // Back Draw Old news veritically on the Chart so that we // have a visual reference of when it did occur. Added by MN void DisplayOldNews(string dispTitle, string dispCountry, int shift, datetime TheTime) { int BarShift; double Pivot; double Height = 0.0; // We have TheTime, now we need the shift so we can // access this Bar's High/Low/Close information BarShift = iBarShift(NULL, 0, TheTime); // Calculate our pivot point to determine where to place the news text Pivot = (iHigh(NULL, 1440, BarShift) + iLow(NULL, 1440, BarShift) + iClose(NULL, 1440, BarShift)) / 3; // If open price is above the Pivot, determine our height if (Open[BarShift] > Pivot) Height = Low[iLowest(NULL, 0, MODE_LOW, 5, BarShift)] - VertTxtShift*Point; // Otherwise Open is below Pivot else Height = High[iHighest(NULL, 0, MODE_HIGH, 5, BarShift)] + VertTxtShift*Point; //Print("Title recieved : " + dispTitle + " Country Recieved: " + dispCountry + " Date and time Recieved: " + TheTime); // We only want to vertically draw the news if it hasnt occured yet if (TheTime < Time[0]) { // Draw the first news headline if (shift == 0) { // Draw a vertical line at the time of the // news if it hasnt already been drawn if (ObjectFind("vLine" + TheTime) == -1) { ObjectCreate("vLine" + TheTime, OBJ_TREND, 0, TheTime, 0, TheTime, High[0]); //experimental ObjectSet("vLine" + TheTime, OBJPROP_COLOR, VertLineColor); ObjectSet("vLine" + TheTime, OBJPROP_STYLE, STYLE_DOT); // put object in the background behind any other object on the chart ObjectSet("vLine" + TheTime, OBJPROP_BACK, true); } // Place our news if it hasnt already been placed on our chart if (ObjectFind("Headline" + TheTime) == -1) { // For x value use Time[0], for y value find the lowest bar within the last 10 bars, subtract by VertTxtShift and used that as our y coordinate ObjectCreate("Headline" + TheTime, OBJ_TEXT, 0, TheTime - VertLeftLineShift, Height); // rotate the text 90 degrees ObjectSet("Headline" + TheTime, OBJPROP_ANGLE, 90); ObjectSetText("Headline" + TheTime, "News: " + dispCountry + " " + dispTitle, VertTxtSize, "Arial", VertTxtColor); } } // Draw second news headline else { //place our news if it hasnt already been placed on our chart if (ObjectFind("Headline" + TheTime + "s") == -1) { // For x value use Time[0], for y value find the lowest bar within the // last 10 bars, subtract by VertTxtShift and used that as our y coordinate ObjectCreate("Headline" + TheTime + "s", OBJ_TEXT, 0, TheTime + VertRightLineShift, Height); // Rotate the text 90 degrees ObjectSet("Headline" + TheTime + "s", OBJPROP_ANGLE, 90); ObjectSetText("Headline" + TheTime + "s", "News: " + dispCountry + " " + dispTitle, VertTxtSize, "Arial", VertTxtColor); } } // end of "if shift) } // end of (TheTime < Time[0]) // Force a redraw of our chart WindowRedraw(); return(0); } double ImpactToNumber(string impact) { if (impact == "High") return (3); if (impact == "Medium") return (2); if (impact == "Low") return (1); else return (0); } string MakeDateTime(string strDate, string strTime) { // Print("Converting Forex Factory Time into Metatrader time..."); //added by MN // Converts forexfactory time & date into yyyy.mm.dd hh:mm int n1stDash = StringFind(strDate, "-"); int n2ndDash = StringFind(strDate, "-", n1stDash+1); string strMonth = StringSubstr(strDate, 0, 2); string strDay = StringSubstr(strDate, 3, 2); string strYear = StringSubstr(strDate, 6, 4); // strYear = "20" + strYear; int nTimeColonPos = StringFind(strTime, ":"); string strHour = StringSubstr(strTime, 0, nTimeColonPos); string strMinute = StringSubstr(strTime, nTimeColonPos+1, 2); string strAM_PM = StringSubstr(strTime, StringLen(strTime)-2); int nHour24 = StrToInteger(strHour); if (strAM_PM == "pm" || strAM_PM == "PM" && nHour24 != 12) { nHour24 += 12; } if (strAM_PM == "am" || strAM_PM == "AM" && nHour24 == 12) { nHour24 = 0; } string strHourPad = ""; if (nHour24 < 10) strHourPad = "0"; return(StringConcatenate(strYear, ".", strMonth, ".", strDay, " ", strHourPad, nHour24, ":", strMinute)); } //================================================================================================= //================================================================================================= //==================================== GrabWeb Functions ====================================== //================================================================================================= //================================================================================================= // Main Webscraping function // ~~~~~~~~~~~~~~~~~~~~~~~~~ // bool GrabWeb(string strUrl, string& strWebPage) // returns the text of any webpage. Returns false on timeout or other error // // Parsing functions // ~~~~~~~~~~~~~~~~~ // string GetData(string strWebPage, int nStart, string strLeftTag, string strRightTag, int& nPos) // obtains the text between two tags found after nStart, and sets nPos to the end of the second tag // // void Goto(string strWebPage, int nStart, string strTag, int& nPos) // Sets nPos to the end of the first tag found after nStart bool bWinInetDebug = false; int hSession_IEType; int hSession_Direct; int Internet_Open_Type_Preconfig = 0; int Internet_Open_Type_Direct = 1; int Internet_Open_Type_Proxy = 3; int Buffer_LEN = 80; #import "wininet.dll" #define INTERNET_FLAG_PRAGMA_NOCACHE 0x00000100 // Forces the request to be resolved by the origin server, even if a cached copy exists on the proxy. #define INTERNET_FLAG_NO_CACHE_WRITE 0x04000000 // Does not add the returned entity to the cache. #define INTERNET_FLAG_RELOAD 0x80000000 // Forces a download of the requested file, object, or directory listing from the origin server, not from the cache. int InternetOpenA( string sAgent, int lAccessType, string sProxyName="", string sProxyBypass="", int lFlags=0 ); int InternetOpenUrlA( int hInternetSession, string sUrl, string sHeaders="", int lHeadersLength=0, int lFlags=0, int lContext=0 ); int InternetReadFile( int hFile, string sBuffer, int lNumBytesToRead, int& lNumberOfBytesRead[] ); int InternetCloseHandle( int hInet ); #import int hSession(bool Direct) { string InternetAgent; if (hSession_IEType == 0) { InternetAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Q312461)"; hSession_IEType = InternetOpenA(InternetAgent, Internet_Open_Type_Preconfig, "0", "0", 0); hSession_Direct = InternetOpenA(InternetAgent, Internet_Open_Type_Direct, "0", "0", 0); } if (Direct) { return(hSession_Direct); } else { return(hSession_IEType); } } bool GrabWeb(string strUrl, string& strWebPage) { int hInternet; int iResult; int lReturn[] = {1}; string sBuffer = " "; // 255 spaces int bytes; hInternet = InternetOpenUrlA(hSession(FALSE), strUrl, "0", 0, INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_RELOAD, 0); if (bWinInetDebug) Log("hInternet: " + hInternet); if (hInternet == 0) return(false); Print("Reading URL: " + strUrl); //added by MN iResult = InternetReadFile(hInternet, sBuffer, Buffer_LEN, lReturn); if (bWinInetDebug) Log("iResult: " + iResult); if (bWinInetDebug) Log("lReturn: " + lReturn[0]); if (bWinInetDebug) Log("iResult: " + iResult); if (bWinInetDebug) Log("sBuffer: " + sBuffer); if (iResult == 0) return(false); bytes = lReturn[0]; strWebPage = StringSubstr(sBuffer, 0, lReturn[0]); // If there's more data then keep reading it into the buffer while (lReturn[0] != 0) { iResult = InternetReadFile(hInternet, sBuffer, Buffer_LEN, lReturn); if (lReturn[0]==0) break; bytes = bytes + lReturn[0]; strWebPage = strWebPage + StringSubstr(sBuffer, 0, lReturn[0]); } Print("Closing URL web connection"); //added by MN iResult = InternetCloseHandle(hInternet); if (iResult == 0) return(false); return(true); } //================================================================================================= //================================================================================================= //=================================== LogUtils Functions ====================================== //================================================================================================= //================================================================================================= void OpenLog(string strName) { if (!EnableLogging) return; if (logHandle <= 0) { string strMonthPad = ""; string strDayPad = ""; if (Month() < 10) strMonthPad = "0"; if (Day() < 10) strDayPad = "0"; string strFilename = StringConcatenate(strName, "_", Year(), strMonthPad, Month(), strDayPad, Day(), "_log.txt"); logHandle = FileOpen(strFilename,FILE_CSV|FILE_READ|FILE_WRITE); Print("logHandle =================================== ", logHandle); } if (logHandle > 0) { FileFlush(logHandle); FileSeek(logHandle, 0, SEEK_END); } } void Log(string msg) { if (!EnableLogging) return; if (logHandle <= 0) return; msg = TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES|TIME_SECONDS) + " " + msg; FileWrite(logHandle,msg); } //================================================================================================= //================================================================================================= //=================================== Timezone Functions ====================================== //================================================================================================= //================================================================================================= #import "kernel32.dll" int GetTimeZoneInformation(int& TZInfoArray[]); #import #define TIME_ZONE_ID_UNKNOWN 0 #define TIME_ZONE_ID_STANDARD 1 #define TIME_ZONE_ID_DAYLIGHT 2 int TZInfoArray[43]; datetime TimeGMT() { int DST = GetTimeZoneInformation(TZInfoArray); if (DST == 1) DST = 3600; else DST = 0; return( TimeLocal() + DST + (OffsetHours * 3600) + (TZInfoArray[0] + TZInfoArray[42]) * 60 ); } //================================================================================================= //================================================================================================= //================================= END IMPORTED FUNCTIONS ===================================== //================================================================================================= //================================================================================================= void OutputToChart() { // Added by Robert for using TxtSize and TxtColor for easier reading int curY = 12; int Days, Hours, Mins; // to display time in days, hours, minutes string TimeStr; if (ObjectFind("Sponsor") == -1) ObjectCreate("Sponsor", OBJ_LABEL, NewsWindow, 0, 0); ObjectSetText("Sponsor", commentStr, 8, "Arial Bold", Gray); ObjectSet("Sponsor", OBJPROP_CORNER, NewsCorner); ObjectSet("Sponsor", OBJPROP_XDISTANCE, 10); ObjectSet("Sponsor", OBJPROP_YDISTANCE, 6); // If the time is 0 or negative, we want to say // "xxx mins SINCE ... news event", else say "UNTIL ... news event" string sinceUntil = "until "; int dispMins = dispMinutes[0]; if (dispMinutes[0] <= 0) { sinceUntil = "since "; dispMins *= -1; } curY = curY + TxtSize + 4; // added the following to show hours and days for longer durations // this could be enhanced to suppress 0 hours and 0 minutes if (dispMins == 999999) { TimeStr = " (No more events this week)"; } else if (dispMins < 60) { TimeStr = dispMins + " mins "; } else // time is 60 minutes or more { Hours = MathRound(dispMins / 60); Mins = dispMins % 60; if (Hours < 24) // less than a day: show hours and minutes { TimeStr = Hours + " hrs " + Mins + " mins "; } else // days, hours, and minutes { Days = MathRound(Hours / 24); Hours = Hours % 24; TimeStr = Days + " days " + Hours + " hrs " + Mins + " mins "; } } if (ObjectFind("Minutes") == -1) ObjectCreate("Minutes", OBJ_LABEL, NewsWindow, 0, 0); if (dispMins == 999999) ObjectSetText("Minutes", TimeStr, TxtSize, "Arial Bold", TxtColorNews); else ObjectSetText("Minutes", TimeStr + sinceUntil + dispCountry[0] + ": " + dispTitle[0], TxtSize, "Arial Bold", TxtColorNews); ObjectSet("Minutes", OBJPROP_CORNER, NewsCorner); ObjectSet("Minutes", OBJPROP_XDISTANCE, 10); ObjectSet("Minutes", OBJPROP_YDISTANCE, curY); curY = curY + TxtSize + 4; if (ObjectFind("Impact") == -1) ObjectCreate("Impact", OBJ_LABEL, NewsWindow, 0, 0); ObjectSetText("Impact", "Impact: " + dispImpact[0], TxtSize, "Arial Bold", TxtColorImpact); ObjectSet("Impact", OBJPROP_CORNER, NewsCorner); ObjectSet("Impact", OBJPROP_XDISTANCE, 10); ObjectSet("Impact", OBJPROP_YDISTANCE, curY); if (dispPrevious[0] != "") { curY = curY + TxtSize + 4; if (ObjectFind("Previous") == -1) ObjectCreate("Previous", OBJ_LABEL, NewsWindow, 0, 0); ObjectSetText("Previous", "Previous: " + dispPrevious[0], TxtSize, "Arial Bold", TxtColorPrevious); ObjectSet("Previous", OBJPROP_CORNER, NewsCorner); ObjectSet("Previous", OBJPROP_XDISTANCE, 10); ObjectSet("Previous", OBJPROP_YDISTANCE, curY); } if (dispForecast[0] != "") { curY = curY + TxtSize + 4; if (ObjectFind("Forecast") == -1) ObjectCreate("Forecast", OBJ_LABEL, NewsWindow, 0, 0); ObjectSetText("Forecast", "Forecast: " + dispForecast[0], TxtSize, "Arial Bold", TxtColorForecast); ObjectSet("Forecast", OBJPROP_CORNER, NewsCorner); ObjectSet("Forecast", OBJPROP_XDISTANCE, 10); ObjectSet("Forecast", OBJPROP_YDISTANCE, curY); } /////////////////////////////////////////////////////////////////////////// // Do second news event if (ShowNextTwoEvents && dispTitle[1] != "") { sinceUntil = "until "; dispMins = dispMinutes[1]; if (dispMinutes[1] <= 0) { sinceUntil = "since "; dispMins *= -1; } curY = curY + TxtSize + 20; // added the following to show hours and days for longer durations // this could be enhanced to suppress 0 hours and 0 minutes if (dispMins == 999999) { TimeStr = " (No more events this week)"; } else if (dispMins < 60) { TimeStr = dispMins + " mins "; } else // time is 60 minutes or more { Hours = MathRound(dispMins / 60); Mins = dispMins % 60; if (Hours < 24) // less than a day: show hours and minutes { TimeStr = Hours + " hrs " + Mins + " mins "; } else // days, hours, and minutes { Days = MathRound(Hours / 24); Hours = Hours % 24; TimeStr = Days + " days " + Hours + " hrs " + Mins + " mins "; } } if (ObjectFind("Minutes2") == -1) ObjectCreate("Minutes2", OBJ_LABEL, NewsWindow, 0, 0); if (dispMins == 999999) ObjectSetText("Minutes", TimeStr, TxtSize, "Arial Bold", TxtColorNews); else ObjectSetText("Minutes2", TimeStr + "until " + dispCountry[1] + ": " + dispTitle[1], TxtSize, "Arial Bold", TxtColorNews); ObjectSet("Minutes2", OBJPROP_CORNER, NewsCorner); ObjectSet("Minutes2", OBJPROP_XDISTANCE, 10); ObjectSet("Minutes2", OBJPROP_YDISTANCE, curY); curY = curY + TxtSize + 4; if (ObjectFind("Impact2") == -1) ObjectCreate("Impact2", OBJ_LABEL, NewsWindow, 0, 0); ObjectSetText("Impact2", "Impact: " + dispImpact[1], TxtSize, "Arial Bold", TxtColorImpact); ObjectSet("Impact2", OBJPROP_CORNER, NewsCorner); ObjectSet("Impact2", OBJPROP_XDISTANCE, 10); ObjectSet("Impact2", OBJPROP_YDISTANCE, curY); if (dispPrevious[1] != "") { curY = curY + TxtSize + 4; if (ObjectFind("Previous2") == -1) ObjectCreate("Previous2", OBJ_LABEL, NewsWindow, 0, 0); ObjectSetText("Previous2", "Previous: " + dispPrevious[1], TxtSize, "Arial Bold", TxtColorPrevious); ObjectSet("Previous2", OBJPROP_CORNER, NewsCorner); ObjectSet("Previous2", OBJPROP_XDISTANCE, 10); ObjectSet("Previous2", OBJPROP_YDISTANCE, curY); } if (dispForecast[1] != "") { curY = curY + TxtSize + 4; if (ObjectFind("Forecast2") == -1) ObjectCreate("Forecast2", OBJ_LABEL, NewsWindow, 0, 0); ObjectSetText("Forecast2", "Forecast: " + dispForecast[1], TxtSize, "Arial Bold", TxtColorForecast); ObjectSet("Forecast2", OBJPROP_CORNER, NewsCorner); ObjectSet("Forecast2", OBJPROP_XDISTANCE, 10); ObjectSet("Forecast2", OBJPROP_YDISTANCE, curY); } } return (0); }