Automated Trend Lines indicator

If you need an Indicator or Signal developed or translated from other language, please post all Indicator development REQUESTS to this section here.

Moderator: admin

Automated Trend Lines indicator

Postby Apprentice » Tue Feb 09, 2010 4:42 am

I have one difficult task for you.
Automated Trend Lines indicator.
Implementation of this indicator would be a good start for the development of indicators with the possibility of pattern recognition.

Code: Select all
//+------------------------------------------------------------------+
//|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)); }  }
   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))   {
         HT2=HT1;
         H2=H1;
         ObjectDelete(hn);
         HTL();   }  }
   for(int ii=1; ii<iBarShift(Symbol(),Period(),LT2); ii++) {
      if(Low[ii]<ObjectGetValueByShift(ln,ii))  {
         LT2=LT1;
         L2=L1;
         ObjectDelete(ln);
         LTL();   }  }

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();
Attachments
Auto Trend Lines.PNG
Auto Trend Line
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36341
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Automated Trend Lines indicator

Postby Nikolay.Gekht » Tue Feb 09, 2010 3:36 pm

It's interesting task. I have to think first how to do it in the best way.
Nikolay.Gekht
FXCodeBase: Site Admin
 
Posts: 1235
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC

Re: Automated Trend Lines indicator

Postby Nikolay.Gekht » Fri Feb 12, 2010 9:23 pm

I bargained with Marketscope developers to have line drawing feature in the next release. The indicore part is ready. I'll start work on this task as soon as I get the beta version of the Marketscope. I hope it will happen in a couple of weeks.
Nikolay.Gekht
FXCodeBase: Site Admin
 
Posts: 1235
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC


Return to Indicator and Signal Requests

Who is online

Users browsing this forum: Bing [Bot] and 11 guests