//+------------------------------------------------------------------+ //|Auto TL 04.mq4 //|Copyright © 2008, Todd Geiger aka fxid10t@yahoo.com (tageiger@comcast.net) //|http://www.metaquotes.net //+------------------------------------------------------------------+ #property copyright "Copyright © 2008, Todd Geiger aka fxid10t@yahoo.com (tageiger@comcast.net)" #property link "http://www.metaquotes.net" #property indicator_chart_window extern int Sensitivity=13;//see note below * extern color Color=Magenta; /*Sensitivity is the number of bars from the current bar to the 2nd point of the last trendline that triggers a new trendline creation. If the trendlines are too close, increase the value. Too far, then decrease the value.*/ int s; double L1,L2,H1,H2; datetime LT1,LT2,HT1,HT2; string hn,ln; int init() { //delete all indicator created TL's for(int i=ObjectsTotal();i>=0;i--) { if(StringSubstr(ObjectName(i),0,5)=="Lo TL" || StringSubstr(ObjectName(i),0,5)=="Hi TL") { ObjectDelete(ObjectName(i)); LT1=0; HT1=0; } } s=Sensitivity; return(0);} int deinit(){ //delete all indicator created TL's for(int i=ObjectsTotal();i>=0;i--) { if(StringSubstr(ObjectName(i),0,5)=="Lo TL" || StringSubstr(ObjectName(i),0,5)=="Hi TL") { ObjectDelete(ObjectName(i)); } } return(0); } int start() { //if no TL's, make some... while(ObjectFind(hn)<0 || iBarShift(Symbol(),Period(),HT2)>s) { HTL(); } while(ObjectFind(ln)<0 || iBarShift(Symbol(),Period(),LT2)>s) { LTL(); } //trendline breach handling for(int i=1; i<iBarShift(Symbol(),Period(),HT2); i++) { if(High[i]>ObjectGetValueByShift(hn,i)) { init(); } } for(int ii=1; ii<iBarShift(Symbol(),Period(),LT2); ii++) { if(Low[ii]<ObjectGetValueByShift(ln,ii)) { init(); } } return(0);} //+------------------------------------------------------------------+ void HTL() { if(HT1==0) { HT1=Time[iHighest(Symbol(),Period(),MODE_HIGH,Bars,0)]; H1=High[iHighest(Symbol(),Period(),MODE_HIGH,Bars,0)]; HT2=Time[iHighest(Symbol(),Period(),MODE_HIGH,Bars,0)-1]; H2=High[iHighest(Symbol(),Period(),MODE_HIGH,Bars,0)-1]; hn="Hi TL "+TimeToStr(HT1,TIME_DATE|TIME_MINUTES); create.hi(); } if(HT1>0) { HT1=HT2; H1=H2; HT2=Time[iBarShift(Symbol(),Period(),HT1)-1]; H2=High[iBarShift(Symbol(),Period(),HT1)-1]; hn="Hi TL "+TimeToStr(HT1,TIME_DATE|TIME_MINUTES); create.hi();} }//end HTL(); void create.hi() { ObjectCreate(hn,2,0,HT1,H1,HT2,H2); ObjectSet(hn,6,Color);//color ObjectSet(hn,7,0);//STYLE_DASH ObjectSet(hn,8,0);//width ObjectSet(hn,9,1);//set as background drawing ObjectSet(hn,10,1);//set as ray for(int ii=iBarShift(Symbol(),Period(),HT1); ii>0; ii--) { if(High[ii]>ObjectGetValueByShift(hn,ii)) { HT2=Time[ii]; H2=High[ii]; ObjectMove(hn,1,HT2,H2); } } }//end create.hi(); void LTL() { if(LT1==0) { LT1=Time[iLowest(Symbol(),Period(),MODE_LOW,Bars,0)]; L1=Low[iLowest(Symbol(),Period(),MODE_LOW,Bars,0)]; LT2=Time[iLowest(Symbol(),Period(),MODE_LOW,Bars,0)-1]; L2=Low[iLowest(Symbol(),Period(),MODE_LOW,Bars,0)-1]; ln="Lo TL "+TimeToStr(LT1,TIME_DATE|TIME_MINUTES); create.low(); } if(LT1>0) { LT1=LT2; L1=L2; LT2=Time[iBarShift(Symbol(),Period(),LT1)-1]; L2=Low[iBarShift(Symbol(),Period(),LT1)-1]; ln="Lo TL "+TimeToStr(LT1,TIME_DATE|TIME_MINUTES); create.low();} }//end LTL(); void create.low() { ObjectCreate(ln,2,0,LT1,L1,LT2,L2); ObjectSet(ln,6,Color);//color ObjectSet(ln,7,0);//STYLE_DASH ObjectSet(ln,8,0);//width ObjectSet(ln,9,1);//set as background drawing ObjectSet(ln,10,1);//set as ray for(int ii=iBarShift(Symbol(),Period(),LT1); ii>0; ii--) { if(Low[ii]<ObjectGetValueByShift(ln,ii)) { LT2=Time[ii]; L2=Low[ii]; ObjectMove(ln,1,LT2,L2); } } }//create.low();
Sample
Analysis
Market Information Used:
Series array that contains the highest prices of each bar
Series array that contains the lowest prices of each bar
Series array that contains open time of each bar
Indicator Curves created:
Indicators Used:
Custom Indicators Used:
Order Management characteristics:
Other Features: