Reputation: 42474
I am not able to get the idea how to provide the time correctly to draw a line. I tried like
ObjectCreate('line', OBJ_HLINE, 0, 0, 2100);
which is drawing a line at the value of 2100, but it starts from 0 and spreads to the right end unlimited. How to draw the line starting from the 50th candle from last till the second last candle?
I also tried
ObjectCreate('line', OBJ_HLINE, 0, Time[50], 2100, Time[1], 2100);
Upvotes: 0
Views: 56
Reputation: 31
This function will help you draw the Horizontal Line From the 50th candle to the 2nd last candle.
void drawTrendLine()
{
datetime time1 = Time[50];
double price1 = Close[50];
datetime time2 = Time[1];
double price2 = Close[50];
ObjectDelete(ChartID(), "CustomTrendLine"); // Delete the object if already exist
ObjectCreate(ChartID(),"CustomTrendLine",OBJ_TREND,0,time1,price1,time2,price2);
ObjectSetInteger(ChartID(),"CustomTrendLine",OBJPROP_RAY_RIGHT,false);
}
Upvotes: 0
Reputation: 119
You'll need a trend line and switch off the ray.
//assign parameters (2 moments in time, 2 prices (equal for Horizontal), **unique** name)
double price1 = 2100;
double price2 = price1;
datetime time1 = iTime(0,0,50);
datetime time2 = iTime(0,0,1);
string name = "nameOnceUsedIsInvaladidForNextLinesToBeNamed";
//create the line
ObjectCreate(ChartID(),name,OBJ_TREND,0,time1,price1,time2,price2);
//switch off the ray
ObjectSetInteger(ChartID(),name,OBJPROP_RAY,false);
Upvotes: 0