Price of trend line in Time[0] - page 2

 
franky:

Hello

For exemple I have a trend line and 2 point A and B

A : x=Time[i] -------- y=Low[i] (Or High)

B: x=Time[j] --------- y=Low[j] (Or High)

How can i identify the price of the trend line in Time[0]

C: x=Time[0] ---------- y = ?

Thank you


Not knowing what values are assigned to i and j, I don't know which time is earliest on your chart.

Please try this, time1 is the earliest of Time[i] and Time[j], price 1 is the corresponding price. Obviously, time2 and price 2 are the remainder.

I've not tested it fully.

 int shifttime1 = iBarShift(NULL,0,time1,false);
 int shifttime2 = iBarShift(NULL,0,time2,false);
 double currenttrendvalue = price1 + ( (price2 - price1)/(shifttime1 - shifttime2) * shifttime1 );
 Alert("Trendline current bar = ", DoubleToStr(currenttrendvalue,Digits) );
 

It`s not simple, but very symple:)

You define trendline by price and time, but draw it by price and bar.

What about Sunday?

 
franky: this is not the problem
  1. IF you calculated c2 as 2 and that is 2 bars from the current chart, then that is your problem, as you use it in iTime(null,t,c2). two bars on the M1 is two minutes ago. two bars when t=D1 is two days ago.
  2. If you don't want to answer questions asked, and argue then I can't help you and you apparently know what the problem is because you already know what it isn't.
 
GumRai:


Not knowing what values are assigned to i and j, I don't know which time is earliest on your chart.

Please try this, time1 is the earliest of Time[i] and Time[j], price 1 is the corresponding price. Obviously, time2 and price 2 are the remainder.

I've not tested it fully.


Perfect, thank you GumRai

Now it work

I think that the lack of precision with the first method was because of the difference between iTime (very large number) compared to price, Now it work perfectly with the same formula (just replace Time by shift)

it's easier to use the shift of bar as abscissa instead of time :-)

thank you everyone for your help

double price_trend(int c1, int c2, string sr, int t){

double y1,y2,y4; int x1,x2,x4;

x1 = MathMax(c1,c2);

x2 = MathMin(c1,c2);

x4 = 0;

if (sr=="down") y1 = iLow(Symbol(),t,MathMax(c1,c2));else y1 = iHigh(Symbol(),t,MathMax(c1,c2));

if (sr=="down") y2 = iLow(Symbol(),t,MathMin(c1,c2));else y2 = iHigh(Symbol(),t,MathMin(c1,c2));

ObjectDelete("ligne1");ObjectCreate("ligne1", OBJ_TREND, 0, iTime(Symbol(),t,x1), y1, iTime(Symbol(),t,x2), y2, 0, 0);

y4 = (x4-x1)*(y2-y1)/(x2-x1)+y1;

Comment(y4+"\n"+ObjectGetValueByShift("ligne1",0)); // Now i have always the same value

return(y4);}
Reason: