Extending trandlines to right or left

 


OBJ_TREND draws a line between two points. Is there a way to extend it beyond its left and right points that define the trendline?
Please reply if you know how to do this.

Thanks
ForexWatchman

 

Yes, it's possible. Pay attention to object property OBJPROP_RAY for OBJ_TREND.

 
Roger wrote >>

Yes, it's possible. Pay attention to object property OBJPROP_RAY for OBJ_TREND.


Thanks Roger. I tried that and it worked for extending the line to the right but NOT to the left.
Thanks for your reply.

ForexWatchman
 

Hi, ForexWatchman,

this shouldn't be too hard. I actually wrote down this idea, assuming that value and time 1 are on the left and value and time 2 are the right coordinates of the trendline...

extern int ExtensionLeft;
extern int ExtensionRight;

int TrendlineModify(string Name)
   {
   int      BarPeriod=Period
   double   Value1=ObjectGet(Name, OBJPROP_PRICE1);
   double   Value2=ObjectGet(Name, OBJPROP_PRICE2);
   datetime Time1=ObjectGet(Name, OBJPROP_TIME1);
   datetime Time2=ObjectGet(Name, OBJPROP_TIME2);
   
   double Delta=(Value2-Value1)/(((Time2-Time1)/60)/Barperiod);
   
   double   NewValue1=Value1-Delta*ExtensionLeft;
   double   NewValue2=Value2+Delta*ExtensionRight;
   
   datetime TimeNew1=Time1-(BarPeriod*60)*ExtensionLeft;
   datetime TimeNew2=Time2+(BarPeriod*60)*ExtensionRight;
   
   ObjectDelete(Name);
   ObjectCreate(Name,OBJ_TREND,0,TimeNew1,NewValue1,TimeNew2,NewValue2);
   }
I do not guarantee that this works, but this might be an idea to build further ones on. Anyway I am not shure if the datetime values are really expressed in seconds from 1970...which in case I am wrong make calculations more complex...
Reason: