Problem Drawing Vertical Lines

 
Hello,

I'm writing an indicator to draw vertical lines when condition one of the conditions are true. It's working ok on forward test, it will draw them when A and B is true, but as an indicator and since it has the routine to go back to previous bars it should also draw them but it doesn't, it creates just one vertical line in the last true condition (counting from bar zero). I want to see all vertical bars draw on previous data in the chart. I'm counting the bars on the chart from the end to 0 (instead using the reverse), but if I do the opposite the same happens. Any help? I use this in my start() routine:

Limit = Bars - IndicatorCounted(); while (Limit >= 0) { RSI[Limit] = iRSI(NULL, 0, 14, PRICE_CLOSE, Limit); Low_RSI = RSI[ArrayMinimum(RSI, Limit + 14, Limit + 1)]; High_RSI = RSI[ArrayMaximum(RSI, Limit + 14, Limit + 1)]; if (Low_RSI > 40 && RSI[Limit] < 40) { ObjectCreate("Changed to DownTrend", OBJ_VLINE, 0, iTime(NULL, 0, Limit), Close[Limit]); } if (High_RSI < 60 && RSI[Limit] > 60) { ObjectCreate("Changed to UpTrend", OBJ_VLINE, 0, iTime(NULL, 0, Limit), Close[Limit]); } Limit--; }


Thank you.
Cleon
 
Mabye U should use buffers, and color bars like histogram, or create arrows.
 
Cleon

Each of the two calls use the same object name. In help, you will see that objectName string must be "unique".
In other words, every call you make to create object has same name, so you only ever create one object (the object created with the "last" call with the "last" set of input parameters) - regardless of number of times objectcreate called... because name is not unique for each call.

Suggestion...
Use Limit to uniquely qualify the object names by concatenating fixed string with dynamic/unique string part (ie, Limit, which changes on each while() iteration):
ObjectCreate("Changed to UpTrend"+Limit,...)
ObjectCreate("Changed to DownTrend"+Limit,...)

So,
if Limit has value of 5
then (using your code loop)
6 "unique" objects with names "Changed to UpTrend5",...,"Changed to UpTrend0" MAY be created if the IF(condition)'s satisfied during each iteration. ..

BTW, for your purposes Time[Limit] is same as iTime(NULL, 0, Limit)
Is execution speed consideration to be aware of...

Let us know how you get on, OK?

Regards
Tim

PS.
I ran modified code on 34000 bars of M15,GBPUSD and only came up with 2 created vertical lines.
I inserted following two lines to catch object creation strings and then used Comment(s); outside of while();

s=StringConcatenate(s,"\n\"Changed to UpTrend"+Limit,"\" @",TimeToStr(Time[Limit]));
s=StringConcatenate(s,"\n\"Changed to DownTrend"+Limit,"\" @",TimeToStr(Time[Limit]));

PPS.
Here, I am going into unknown territory but if same names used each time start() called then will not previously created names/objects be redefined/created and therefore moved...?

IE, let Limit have value of 3 'each time' start() re-called:
This implies that "Changed...3|2|1|0" will be continuously recreated - which will remove the previously created objects "Changed...3|2|1|0"

As said - not done this, I became interested in your post because I must start learning more myself ;)
Files:
aaa.jpg  6 kb
 
Hi ukt,

It' makes sense, let me do some testing. Thank you for the help.
 
cleon:
Hi ukt,

It' makes sense, let me do some testing. Thank you for the help.
Ya, good. I look forwards to hearing what you learn/discover.

Is good to share and both can profit from this!
 
Cleon, look forwards to hearing what you find.
Is good to share... all can profit!
 
ukt,

Just this week I resumed my work on this problem. Until know I'm not able to draw correctly the lines although I named each line with a different name using Time function. I will update the post as soon as possible. Thank you.

Cleon
 
cleon:
ukt,

Just this week I resumed my work on this problem. Until know I'm not able to draw correctly the lines although I named each line with a different name using Time function. I will update the post as soon as possible. Thank you.

Cleon
Greetings Cleon

Ages ago, I should have included my test code done to get vertical lines plotted.
Is really all your code - I just added in naming ideas and comment()...

HTH

Tim


#property indicator_chart_window int init() { //---- start with blank chart comment area Comment(""); return(0); } int deinit() { //---- comment out this line if want to leave any indicator generated text showing after indicator removed. //Comment(""); //be sure we leave the chart's comment area blank return(0); } //-------------------------------------------------------------------- int start() { int Limit = Bars; // - IndicatorCounted(); string s=""; double RSI[]; int imax=20; ArrayResize(RSI,Bars); while (Limit >= 0 && imax > 0) { RSI[Limit] = iRSI(NULL, 0, 14, PRICE_CLOSE, Limit); double Low_RSI = RSI[ArrayMinimum(RSI, Limit + 14, Limit + 1)]; double High_RSI = RSI[ArrayMaximum(RSI, Limit + 14, Limit + 1)]; if (Low_RSI > 40 && RSI[Limit] < 40) { ObjectCreate("Changed to DownTrend"+Limit, OBJ_VLINE, 0, iTime(NULL, 0, Limit), Close[Limit]); s=StringConcatenate(s,"n"Changed to DownTrend"+Limit,"" @",TimeToStr(Time[Limit])); imax--; } if (High_RSI < 60 && RSI[Limit] > 60) { ObjectCreate("Changed to UpTrend"+Limit, OBJ_VLINE, 0, iTime(NULL, 0, Limit), Close[Limit]); s=StringConcatenate(s,"n"Changed to UpTrend"+Limit,"" @",TimeToStr(Time[Limit])); imax--; } Limit--; } Comment(s+"nimax="+imax); return(0); }
 
ukt,

Thank you for your help, I have copy past your code to an indicator to test it and it also draws two lines, I will let it run for a while to see if draws the next lines. I was trying to put lines in the visible bars also. Maybe it's easy to use another method instead using lines, like arrows or something like that.

Thank you for your help.
Cleon
Reason: