Download MetaTrader 5

Help Wanted ! Declaring anchor points in ObjectCreate

To add comments, please log in or register
Ask your broker to open the official channel. Thousands of traders will read the news!
mikegreen
276
mikegreen 2015.12.01 16:37 

Hi,

I hope you can help, I have an indicator that I am working on and want to draw a trendline however I am having trouble in where I should declare the anchor points.

Any suggestions would be appreciated..... 

Files:
whroeder1
14480
whroeder1 2015.12.01 17:34  
mickeyferrari: I am having trouble
      double Line=ObjectCreate("current_chart_id",OBJ_TREND,0,time1,Price1,time2,price2,0,0);
      :
         TrendLine[i]=Line;
  1. "having trouble " is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless. There are no mind readers here.
  2. What does ObjectCreate() return?
  3. Why are you trying to create a trendline and have a line buffer?
  4. Once you create an object, you can't create it again; it's not going to move.
mikegreen
276
mikegreen 2015.12.01 18:06  
Great thanks but where would I declare the anchor points?
mikegreen
276
mikegreen 2015.12.01 18:11  
OK I remove the buffer but how would I code it to draw a line from the top of the price bars that close outside the bollinger when i+1 is higher than i
mikegreen
276
mikegreen 2015.12.01 18:13  

I do want the line to be static though is there a way of coding a trend line using the buffer method I use in the program allready?

Carl Schreiber
6588
Carl Schreiber 2015.12.01 18:44  

A line - with one and (ray) or with two ends - has to have two points - neither only one point nor a buffer with thousands of points!

A point here is defined by a time and a price look at this example:

bool drawLine(string n, datetime t1, double p1, datetime t2, double p2, color clr=clrDimGray, string dscr="", bool ray=false, double stl=STYLE_SOLID, double wdt=1) {
    if(ObjectFind(n) >= 0) ObjectDelete(n);
    if (!ObjectCreate(n,OBJ_TREND,0,t1,p1, t2, p2) )  return(false);
    bool ok =  ObjectSet(n,OBJPROP_COLOR,clr);
    ok = ok && ObjectSet(n,OBJPROP_STYLE,stl);
    ok = ok && ObjectSet(n, OBJPROP_RAY, ray);
    ok = ok && ObjectSet(n,OBJPROP_WIDTH,wdt);
    ok = ok && ObjectSetText(n,dscr,10);
    return(ok);
}
mikegreen
276
mikegreen 2015.12.02 09:29  
gooly:

A line - with one and (ray) or with two ends - has to have two points - neither only one point nor a buffer with thousands of points!

A point here is defined by a time and a price look at this example:

thanks gooly. May I ask you to clarify where I would place this in the code body (see attached top) and where would I declare the t2 and p2 inputs for these functions?

regards........... 

Carl Schreiber
6588
Carl Schreiber 2015.12.02 09:52  

??

It is a function. Place it where ever you want but NOT within another function.

Then in e.g. in OnCalculate() you call this function.

mikegreen
276
mikegreen 2015.12.02 13:13  
Before or after the for loop?
Carl Schreiber
6588
Carl Schreiber 2015.12.02 13:41  
Well it depends on your strategy - start experimenting to find out what you want and what you need!
mikegreen
276
mikegreen 2015.12.02 13:55  
thanks gooly will give it a go.............
12
To add comments, please log in or register