Hello everyone, I have a problem. in my for loop, the bot draws lines at the top and bottom anchor points of the red rectangles that are on the chart. unfortunately lines are set uninterrupted and i only need one above and one below per rectangle. unfortunately I don't know how to end the loop, so that logically only one line is set at the top and one at the bottom per rectangle.
Hello everyone, I have a problem. in my for loop, the bot draws lines at the top and bottom anchor points of the red rectangles that are on the chart. unfortunately lines are set uninterrupted and i only need one above and one below per rectangle. unfortunately I don't know how to end the loop, so that logically only one line is set at the top and one at the bottom per rectangle.
Try this, only checking the objects once. This will probably have issues if objects are deleted from the chart, to resolve that you would need to store the rectangle names in an array and do a full loop through the objects checking against the array by name before drawing the lines.
// Public var out of function int checkedObjects = 0; // Loop within function void DrawLines() { for (int i = checkedObjects; i<ObjectsTotal(); i++) { string object_name = ObjectName(ChartID(), i); if (ObjectGetInteger(ChartID(), object_name, OBJPROP_TYPE) != OBJ_RECTANGLE) continue; string high_name = "Line-High"+string(i); string low_name = "Line-Low"+string(i); if(ObjectGetInteger(ChartID(), object_name,OBJPROP_COLOR)==clrRed){ if(!ObjectCreate(_Symbol,high_name,OBJ_HLINE,0,0,ObjectGetDouble(ChartID(), object_name,OBJPROP_PRICE,1)))PrintFormat("Error object %s not created!",high_name); else PrintFormat("object %s created successfully", high_name); if(!ObjectCreate(_Symbol,low_name ,OBJ_HLINE,0,0,ObjectGetDouble(ChartID(), object_name,OBJPROP_PRICE,0)))PrintFormat("Error object %s not created!",low_name); else PrintFormat("object %s created successfully", low_name); } checkedObjects = i+1; } }
Try this, only checking the objects once. This will probably have issues if objects are deleted from the chart, to resolve that you would need to store the rectangle names in an array and do a full loop through the objects checking against the array by name before drawing the lines.
Thanks for your answer, Mark!
when the rectangle disappears, the lines should also disappear. but I can't do that until I've ticked off the lines
with your code it only checks a rectangle and then doesn't continue. I'm trying to optimize it, that helped me
Hello everyone, I have a problem. in my for loop, the bot draws lines at the top and bottom anchor points of the red rectangles that are on the chart. unfortunately lines are set uninterrupted and i only need one above and one below per rectangle. unfortunately I don't know how to end the loop, so that logically only one line is set at the top and one at the bottom per rectangle.
Tell me, who initially draws these rectangles? Does the user draw them by hand?
Tell me, who initially draws these rectangles? Does the user draw them by hand?
an indicator plots those on the chart. I've also thought about doing this using the indicator, but that's too complicated because it numbers the rectangles consecutively and always names them differently (because of different colors) and it's therefore difficult to come up with a name.
an indicator plots those on the chart. I've also thought about doing this using the indicator, but that's too complicated because it numbers the rectangles consecutively and always names them differently (because of different colors) and it's therefore difficult to come up with a name.
Good. So as soon as a new rectangle appears, it is necessary to draw two lines: along the upper border and along the lower border of the rectangle?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello everyone, I have a problem. in my for loop, the bot draws lines at the top and bottom anchor points of the red rectangles that are on the chart. unfortunately lines are set uninterrupted and i only need one above and one below per rectangle. unfortunately I don't know how to end the loop, so that logically only one line is set at the top and one at the bottom per rectangle.