//+------------------------------------------------------------------+ //| TurningPoints.mq4 | //| Abhay | //| itisabhay@hotmail.com | //+------------------------------------------------------------------+ #property copyright "Abhay" #property link "itisabhay@hotmail.com" #property indicator_chart_window #property indicator_buffers 4 #property indicator_color1 DarkSlateGray #property indicator_color2 Yellow #property indicator_color3 DarkOrange #property indicator_color4 DarkOrange double UpBuffer[]; double DnBuffer[]; double BorderTop[]; double BorderBottom[]; string TP_From[], TP_To[]; string shortName = "TurningPoint"; bool look.next.turningpoint=true,look.next.trendchange=true,tp_drawn=true; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- additional buffers are used for counting IndicatorBuffers(4); SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_DOT,1); SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_DOT,1); // SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,2); // SetIndexStyle(3,DRAW_LINE,STYLE_SOLID,2); SetIndexBuffer(0,UpBuffer); SetIndexBuffer(1,DnBuffer); SetIndexBuffer(2,TP_From); SetIndexBuffer(3,TP_To); IndicatorShortName(shortName); return(0); } //+------------------------------------------------------------------+ //| SignalIndicator | //+------------------------------------------------------------------+ int start() { int limit,bar; int counted_bars=IndicatorCounted(); if(counted_bars<0) counted_bars=0; if(counted_bars>0) counted_bars--; limit=Bars-counted_bars; int eCount=0,eCount1=0; string tp1[],tp2[]; int handle=0,handle1=0; string str[],str1[],FileName="TurningPoints.csv",TrendFile="TrendChange.csv"; string trdchg[],trdchg1[],trdchg2[]; if (handle1==0) handle1 = FileOpen(TrendFile, FILE_CSV|FILE_READ,','); // Open TrendChange.CSV if(handle1==0) Comment("File "+TrendFile+" not found."); for(bar = 0 ;bar <= limit ;bar++) { // Print("^^ Time[limit-bar]: ",TimeToStr(Time[limit-bar])," ","TP2: ",StrToTime(trdchg1[eCount1])); if ( StrToTime(TimeToStr(Time[limit-bar],TIME_DATE)) > StrToTime(trdchg1[eCount1]) || StrToTime(trdchg1[eCount1])==0 ) look.next.trendchange=true; else look.next.trendchange=false; Print("!!** limit: ",limit," ","bar: ",bar," ","Time[limit-bar]: ",TimeToStr(Time[limit-bar],TIME_DATE)," ","TP2: ",TimeToStr(StrToTime(trdchg1[eCount1]),TIME_DATE)); /* for(eCount1 = 0; look.next.trendchange==true && !FileIsEnding(handle1); eCount1++) // Read from NEWS.CSV; one line per event { Print("&& limit: ",limit," ","bar: ",bar," ","Time[limit-bar]: ",TimeToStr(Time[limit-bar],TIME_DATE)," ","TP2: ",TimeToStr(StrToTime(trdchg1[eCount1]),TIME_DATE)); if(handle1>0) { trdchg[eCount1]=FileReadString(handle1); trdchg1[eCount1]=FileReadString(handle1); trdchg2[eCount1]=FileReadString(handle1); Print("Turning point string(",eCount1,"): ",(trdchg[eCount1])," ","TP2: ",(trdchg1[eCount1])," ","Bar: ",limit-bar," ","BarTime: ",TimeToStr(Time[limit-bar],TIME_DATE)); if (StrToTime(TimeToStr(Time[limit-bar],TIME_DATE)) >= StrToTime(trdchg[eCount1]) && StrToTime(TimeToStr(Time[limit-bar],TIME_DATE)) <= StrToTime(trdchg1[eCount1]) ) { Print("** Time[bar]: ",TimeToStr(Time[limit-bar])," ","Tp1: ",trdchg[eCount1]," ","Tp2: ",trdchg1[eCount1]); break; } } } */ // Print("Time[limit-bar]: ",TimeToStr(Time[limit-bar],TIME_DATE)," ","TP2: ",TimeToStr(StrToTime(str1[eCount]),TIME_DATE)," ","TP_Drawn: ",tp_drawn); if (StrToTime(TimeToStr(Time[limit-bar],TIME_DATE)) >= StrToTime(trdchg[eCount1]) && StrToTime(TimeToStr(Time[limit-bar],TIME_DATE)) <= StrToTime(trdchg1[eCount1]) ) { if(!ObjectCreate("TC"+(limit-bar),OBJ_VLINE,0,Time[limit-bar],0,0,0)) { ObjectDelete("TC"+(limit-bar)); ObjectCreate("TC"+(limit-bar),OBJ_VLINE,0,Time[limit-bar],0,0,0); // Print("Problem creating "+"TP"+(limit-bar)+" "+TimeToStr(Time[limit-bar]),":",GetLastError()); } else { if (trdchg2[eCount1] == "L" || trdchg2[eCount1] == "ML") { ObjectSet("TC"+(limit-bar),OBJPROP_COLOR,Blue); ObjectSet("TC"+(limit-bar),OBJPROP_STYLE,STYLE_DASH); ObjectSet("TC"+(limit-bar),OBJPROP_WIDTH,2); } else if (trdchg2[eCount1] == "H" || trdchg2[eCount1] == "MH") { ObjectSet("TC"+(limit-bar),OBJPROP_COLOR,Red); ObjectSet("TC"+(limit-bar),OBJPROP_STYLE,STYLE_DASH); ObjectSet("TC"+(limit-bar),OBJPROP_WIDTH,2); } } } } FileClose(handle); FileClose(handle1); Comment("\nNext Turning From: ",str[eCount]," ","To: ",str1[eCount]," ","Current Dt: ",TimeToStr(Time[0])); //---- return(0); } //+------------------------------------------------------------------+