Hello guys,
I'm new in ForexTester programming.
I created lots of expert advisors in mql4, but now i must to translate one to ForexTester.
Can somebody help me, how can i get the value of a trend line at the current bar?
I can get the trendline properties(name, price1, etc.), but i can't find any function like getValueByShift in mql4.
I tried to shift the trend line times to the past and ask it length with the iBarShift function, but sometimes, it returns -1 (first i get the correct value, then during the next bar -1, then the correct value again. It is randomly).
Could somebody help me?
Thank you
TrendLine question
-
- Posts: 1479
- Joined: Mon Apr 01, 2013 3:55 am
Please try this function. It should do what you need.
Code: Select all
function GetTrendLineValue (TrendLineName: string) : double;
var y, x1,x2,x, y1, y2: double;
begin
if ObjectExists(TrendLineName) then begin y1 := ObjectGet(TrendLineName, OBJPROP_PRICE1);
y2 := ObjectGet(TrendLineName, OBJPROP_PRICE2);
x1 := ObjectGet(TrendLineName, OBJPROP_TIME1);
x2 := ObjectGet(TrendLineName, OBJPROP_TIME2);
x:=iTime('GBPCHF', 1, 0);
y:=(x-x1)*(y2-y1)/(x2-x1)+y1;
result:=y;
end
else result:=-1;
end;
-
- Posts: 905
- Joined: Sat Jul 11, 2009 10:54 am
Return to “Programming lessons”
Who is online
Users browsing this forum: No registered users and 18 guests