Tracking the Painted Bar

 

Ive written an EA that paints a Bar Red directly on the chart, then uses that bar to make comparisons and calculations.

Im having trouble keeping track of the bar. Seems bars are NOT objects that i can search for by color, therefore I must track the Bar by Number.

Which number should I use???

The predefined variable Bars changes on every new bar, and so does the offset of the Red Bar. How can i keep track of its current ordinal location?

Im thinking of storing the value of (Bars - offset) of the Red Bar at the time it was painted. Then on every new bar, I can subtract that stored number

from Bars and get the current offset. Is this a reliable way to handle this? Im worried that the predefined Bars variable could change in unexpected

ways and cause errors.


The other options is to create an arrow at the Red Bar. How would I then get the location of the arrow? I dont see that as an attrubute of Objects List.

 
hkjonus:

Ive written an EA that paints a Bar Red directly on the chart, then uses that bar to make comparisons and calculations.

Im having trouble keeping track of the bar. Seems bars are NOT objects that i can search for by color, therefore I must track the Bar by Number.

Which number should I use???

The predefined variable Bars changes on every new bar, and so does the offset of the Red Bar. How can i keep track of its current ordinal location?

Im thinking of storing the value of (Bars - offset) of the Red Bar at the time it was painted. Then on every new bar, I can subtract that stored number

from Bars and get the current offset. Is this a reliable way to handle this? Im worried that the predefined Bars variable could change in unexpected

ways and cause errors.


The other options is to create an arrow at the Red Bar. How would I then get the location of the arrow? I dont see that as an attrubute of Objects List.


Hi, Can you please share the code you used to paint the bar directly on the chart ?


regards

Sat

 
hkjonus:

Ive written an EA that paints a Bar Red directly on the chart, then uses that bar to make comparisons and calculations.

Im having trouble keeping track of the bar. Seems bars are NOT objects that i can search for by color, therefore I must track the Bar by Number.

Which number should I use???

The predefined variable Bars changes on every new bar, and so does the offset of the Red Bar. How can i keep track of its current ordinal location?

Im thinking of storing the value of (Bars - offset) of the Red Bar at the time it was painted. Then on every new bar, I can subtract that stored number

from Bars and get the current offset. Is this a reliable way to handle this? Im worried that the predefined Bars variable could change in unexpected

ways and cause errors.


The other options is to create an arrow at the Red Bar. How would I then get the location of the arrow? I dont see that as an attrubute of Objects List.


You can save the bar's time and later use iBarShift()
 
skt1977:

Hi, Can you please share the code you used to paint the bar directly on the chart ?


regards

Sat

I didnt log on for quite some time. Did you figure this out? Let me know and I will look into some code for you.
Reason: