Here compile as Script. It's an old function of mine.
void start(){ Trend_Line(Time[10],Time[0],Open[10],Open[0],Gold,STYLE_SOLID); } void Trend_Line( datetime x1, datetime x2, double y1, double y2, color lineColor, double style){ //~~~~~~~~~~ string label = "_Trend_Line_"; ObjectDelete(label); ObjectCreate(label, OBJ_TREND, 0, x1, y1, x2, y2, 0, 0); ObjectSet(label, OBJPROP_RAY, 0); ObjectSet(label, OBJPROP_COLOR, lineColor); ObjectSet(label, OBJPROP_STYLE, style); //~~~~~~~~~~ }
Hi ubzen, Hi WHRoeder,
thank you for youre answers. I checked https://www.mql5.com/en/forum/134129 already, but I was not able to make it with it, thank you anyway!
Here is the code (part of an EA) that shall draw a trendline:
datetime T1, T2; double P1, P2; int start() { P1 = Open[1]; T1 = Time[1]; P2 = Open[10]; T2 = Time[10]; ObjectCreate("label", OBJ_TREND, 0, T1, P1, T2, P2); ObjectSet("label", OBJPROP_RAY, 0); ObjectSet("label", OBJPROP_COLOR, Gold); ObjectSet("label", OBJPROP_STYLE, STYLE_SOLID); return(0); }
T1,T2,P1,P2 have values, but the EA does not draw anything. Something must be wrong.
In my example T1 is bar 10. Try switching them around.
Yeah! Now its working! Thank you :-)
void start(){ Trend_Line(Time[10],Time[0],Open[10],Open[0],Gold,STYLE_SOLID); } void Trend_Line( datetime x1, datetime x2, double y1, double y2, color lineColor, double style){ //~~~~~~~~~~ string label = "_Trend_Line_"; ObjectDelete(label); ObjectCreate(label, OBJ_TREND, 0, x1, y1, x2, y2, 0, 0); ObjectSet(label, OBJPROP_RAY, 0); ObjectSet(label, OBJPROP_COLOR, lineColor); ObjectSet(label, OBJPROP_STYLE, style); //~~~~~~~~~~ }
Following Steps are part of custom indicator and not expert advisers and i have started to make use of it and thank you as soon as i saw the steps
There is not a lot of information on this, I am trying to learn the basics of drawing a trendline.
Each I run this code I get a horizontal green line. Any ideas what is wrong with the code.
Thank you
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
datetime point1 = D'2018.11.30.20:30';
datetime point2 = D'2018.12.30.20:30';
datetime point3 = D'2019.01.30.20:30';
ObjectCreate("getTrend",OBJ_TREND,0,point1,High[1],point2,High[1],point3,High[1]);
ObjectSet("getTrend", OBJPROP_TIME1, point1);
ObjectSet("getTrend", OBJPROP_TIME2, point2);
ObjectSet("getTrend", OBJPROP_TIME2, point3);
ObjectSetInteger(0,"getTrend",OBJPROP_WIDTH,3);
ObjectSetInteger(0,"getTrend",OBJPROP_COLOR,clrGreen);
ObjectSetInteger(0,"getTrend",OBJPROP_STYLE,STYLE_SOLID);
return(rates_total);
}
There is not a lot of information on this, I am trying to learn the basics of drawing a trendline.
Each I run this code I get a horizontal green line. Any ideas what is wrong with the code.
Thank you
You are using the same price 3 times .
Additionally (beyond the horizontal line) how are you certain the dates correspond to these prices

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Questions about that were asked quiet oftenly and I read all answers and some article fitting to that topic - and I still cannot solve that simple problem :/
PLEASE HELP ME!
I want to draw a trendline using
ObjectCreate("Trendline",OBJ_TREND,0,Price1,Time1,Price2,Time2);
I want Price1, Time1 to take the values of bar 10 and Time2,Price2 to take the values of bar 0. I tried so many different ways and none did work, I must ask for help and I hope there is someone who nows how that can work.
Thank you very much in advance!