Need help with array problem and determining current bar.Back to topics list |
|
Keris2112
2005.08.31 02:42
HELP!!!
Hi all, I hope somebody can help with the indicator that I'm working on. I'm using the ObjectCreate fuction to create a vertical line when certain parameters are met. I want to take it one step futher than I have it, but I don't know how. What I want to do isn't really about ObjectCreate. It's more about arrays, as you'll see... First I'll give the logic code, then I'll explain what I want to happen. Also, I know all those iCustoms can be thinned down by putting them in variables. I will do that on the final draft.... // *** If the Slope is UP, Juice is Green, and we get Green crossing up on iTrend
if((iCustom(NULL,0,"Shi_Channel",2,0) > 0 && iCustom(NULL,0,"Juice",2,0) >= 0 &&
( // iTrend Green crossing on current bar or previous bar
(iCustom(NULL,0,"i_Trend",0,2) < iCustom(NULL,0,"i_Trend",1,2) && iCustom(NULL,0,"i_Trend",0,1) > iCustom(NULL,0,"i_Trend",1,1) && iCustom(NULL,0,"Juice",2,1) <= 0) ||
(iCustom(NULL,0,"i_Trend",0,1) < iCustom(NULL,0,"i_Trend",1,1) && iCustom(NULL,0,"i_Trend",0,0) > iCustom(NULL,0,"i_Trend",1,0))
)
)
||
// *** If the Slope is DOWN, Juice is Green, and we get Red crossing down on iTrend
(iCustom(NULL,0,"Shi_Channel",2,0) < 0 && iCustom(NULL,0,"Juice",2,0) >= 0 &&
( // iTrend Red crossing on current bar or previous bar
(iCustom(NULL,0,"i_Trend",1,2) < iCustom(NULL,0,"i_Trend",0,2) && iCustom(NULL,0,"i_Trend",1,1) > iCustom(NULL,0,"i_Trend",0,1) && iCustom(NULL,0,"Juice",2,1) <= 0) ||
(iCustom(NULL,0,"i_Trend",1,1) < iCustom(NULL,0,"i_Trend",0,1) && iCustom(NULL,0,"i_Trend",1,0) > iCustom(NULL,0,"i_Trend",0,0))
)
)
)
{
ObjectDelete("VL0");
ObjectCreate("VL0",OBJ_VLINE,0,CurTime(),0); //(CurTime()-(Period()*60*2))
ObjectSet("VL0",OBJPROP_COLOR,Yellow);
ObjectSet("VL0",OBJPROP_WIDTH,1);
ObjectSet("VL0",OBJPROP_STYLE,STYLE_SOLID);
// ObjectCreate(TimeToStr(CurTime()),OBJ_VLINE,0,CurTime(),0); //(CurTime()-(Period()*60*2))
// ObjectSet(TimeToStr(CurTime()),OBJPROP_COLOR,Yellow);
// ObjectSet(TimeToStr(CurTime()),OBJPROP_WIDTH,1);
// ObjectSet(TimeToStr(CurTime()),OBJPROP_STYLE,STYLE_SOLID);
}
|
|
Shimodax
2005.08.31 05:52
Hi! I'm not sure if I understand the problem correctly, but here are some ideas anyway. Re your last paragraph. Use TimeToStr(Time[x]) as the name for the object as that doesn't change. That way you will elegantly be able to always access the object that belongs to a bar. Even if the bar moved back into the past, it's Time[x] will be constant. Another way could be to do vertical bars by using a histogram indicator. I'm not sure how histograms work in chart_window indicators but there must be a way. The ichimoku charts sample has a histogram to paint one of the channels. From checking the source I had the impression that it's start point is in the DRAW_HISTOGRAM type buffer and reaches up to the next chart buffer (but as said, I've never done that so far). That way you could avoid objects alltogether, just let the histogram reach from zero to 100 for the bars where you need it and from 0 to 0 where you don't need them. MT would scroll them with the chart and the user would not see tons of objects. Hope that helps. Markus |
|
Shimodax
2005.08.31 06:31
Or, on second thought, you may want to consider a different alternative. Instead of vertical bars, mark the points where your condition is met with symbols SetIndexStyle(0,DRAW_ARROW); SetIndexBuffer(0,Buffer1); SetIndexArrow(0,159); SetIndexEmptyValue(0, 0.0);
|
|
Keris2112
2005.08.31 11:33
Re your last paragraph. Use TimeToStr(Time[x]) as the name for the object as that doesn't change. That way you will elegantly be able to always access the object that belongs to a bar. Even if the bar moved back into the past, it's Time[x] will be constant. Markus, Thanks for the input. I want to use the time as the unique name similar to the way you described above and I know how to delete an object calling that name, but what I don't know exactly how to do is to place that name into an array/variable to be called later or how to determine if that object is on the current bar or previous bar. I want to use Object - Vertical Line, because I like the way it draws the line through everything on the window, i.e. price chart and all indicators. This is what I'm trying to do... If (all my parameters are met) {
Create a unique name based on current time and store it in a variable or array
Delete previous line using ObjectDelete("UniqueName") [b]only if the previous line is on the current bar.[/b]
Create a new line using CreateObject("UniqueName",OBJ_VLINE,...)
}
|
|
Shimodax
2005.08.31 13:04
Keris, I think you don't need an array. You can just go through all bars, do a ObjectFind(TimeToString(Time[barcount])). Essentially this says: Find the object that has a name matching this bar number (barcount). If an object under that name exists, the bar has a line, if there's no such object there's no bar. And if barcount is greater than 0 it's a past bar. Hope this helps Markus |
|
Keris2112
2005.09.01 04:36
I think you don't need an array. You can just go through all bars, do a ObjectFind(TimeToString(Time[barcount])). Essentially this says: Find the object that has a name matching this bar number (barcount). If an object under that name exists, the bar has a line, if there's no such object there's no bar. And if barcount is greater than 0 it's a past bar. Markus, Thank you for all of your help. It really got me thinking in the right direction. This is what I finally ended up with and it seems to work perfectly. for(int i=1; i<Bars; i++)
{
ObjectDelete(TimeToStr(Time[0]));
ObjectCreate(TimeToStr(Time[0]),OBJ_VLINE,0,CurTime()-(Period()*60*0),0); //(CurTime()-(Period()*60*2))
ObjectSet(TimeToStr(Time[0]),OBJPROP_COLOR,Yellow);
ObjectSet(TimeToStr(Time[0]),OBJPROP_WIDTH,1);
ObjectSet(TimeToStr(Time[0]),OBJPROP_STYLE,STYLE_SOLID);
ObjectSet(TimeToStr(Time[i]),OBJPROP_COLOR,Red);
}
|
|
Shimodax
2005.09.01 12:11
Glad to have been of help. Good luck with the Shi-Channels. Markus |
