Asking for help determining object lines

 

I like the below indicator and want to use it with an EA I am writing. However I'm having a lot of trouble figuring out how to get the price values of the last or current set of lines the indicator draws. Everytime I add the indicator the last set of line names changes because of the amount of bars it uses is apart of the line name. My lack of experience is hindering me in figuring it out. Basically I want to check to see if price is above or below the lines. If anyone could help me with this I would greatly appreciate it.

I'm trying to use:

ObjectGet("<linenamehere>", OBJPROP_PRICE1);

but I can't figure out the names of the lines because they change each time the indicator is added. As best I can figure the line names start with "_lev" then + the bar number it is on +, "_0_", then + the line number 0-8. Since the bar count changes all the time how can I call the price used to create the line?

Thanks

 
Files:
gann_s9.mq4  11 kb
 

  1. For large postings like yours - ATTACH a file
  2. All the object start with _lev so find them in reverse order
    #define PREFIX "_lev"
    for(int iObj=ObjectsTotal()-1; iObj >= 0; iObj--){
        string on = ObjectName(iObj);
        if (StringFind(on, name) == 0){
            // found one
        }
    }
    
    Or look for a specific one _lev0 _lev1 _levV ...
 

Please use this to post code . . . it makes it easier to read.


All the line names start with _lev, cycle through the ones that match and find the most recent one by datetime ( OBJPROP_TIME1 & 2 )

 
Beat me to it . . . ;-)
 
WHRoeder:

  1. For large postings like yours - ATTACH a file
  2. All the object start with _lev so find them in reverse order Or look for a specific one _lev0 _lev1 _levV ...


_lev 20_0_ 0 txt
_lev 20_0_ V
_lev 20_0_1
_lev 20_0_1 txt
_lev 20_0_2
_lev 20_0_2 txt
_lev 20_0_3

I will use the SRC in the future. Thank you for the help, I am finally able to get these object names (example above). Now I only want the ones with the ending of "_2". It doesn't matter what is in front of it but not the ones that end in "txt". There should be 4 figures that end up with "_2" in the journal.

After I identify the four "_lev XX_0_2" or "_lev X_0_2" (X or XX is a number) named objects I only want to look at the one where XX or X is the smallest of the four found.

Would anyone be so kind to help me with that part of the code? I'm struggling with comparing things in the middle of the string when I don't know if it is a single digit number (X) or double digit number (XX).

 

You don't need to worry about messing with strings . . .

"However I'm having a lot of trouble figuring out how to get the price values of the last or current set of lines the indicator draws"

Find the ones that are lines, if(ObjectType("name") == OBJ_TREND; . . . then look at their datetime values, ObjectGet("hline12", OBJPROP_TIME1); and OBJPROP_TIME2, find the newest one.

 

First I can't thank you enough for the help -- invaluable! Sorry for keep asking for bits and pieces but I’m doing my best to try and develop the code on my own instead of someone just giving it to me but I'll take some give me's at this point. :-)

Below is what I’ve come up with so far that identifies all the proper lines and their time. I want next to only use the most recent 0-8 lines so I can compare their value to price. I need to identify each line by their 0-8 designation because when prices crosses a particular line that is important to me.

I figure I should use an array to store the recent 0-8 line names then I can just call array[0-8] and ObjectGet(array[1], OBJPROP_PRICE2) when needed. But I’m struggling on how to get the recent lines into array as a group...

#define PREFIX "_lev"
   for(int iObj=ObjectsTotal()-1; iObj >= 0; iObj--)
   {
       hline = ObjectName(iObj);
       if(ObjectType(hline) == OBJ_TREND && ObjectGet(hline, OBJPROP_PRICE1) == ObjectGet(hline, OBJPROP_PRICE2))
       {
            Print("*********Name: ",hline,"   Time: ",ObjectGet(hline,OBJPROP_TIME2));
       }
   }

These sets continue on and on -- when a new bar is formed another set is made (_lev XX_0_0-8).

09:30:53 2010.06.02 22:00    EURUSDm,M30: *********Name: _lev 19_0_8   Time: 1275498000
09:30:53 2010.06.02 22:00    EURUSDm,M30: *********Name: _lev 19_0_7   Time: 1275498000
09:30:53 2010.06.02 22:00    EURUSDm,M30: *********Name: _lev 19_0_6   Time: 1275498000
09:30:53 2010.06.02 22:00    EURUSDm,M30: *********Name: _lev 19_0_5   Time: 1275498000
09:30:53 2010.06.02 22:00    EURUSDm,M30: *********Name: _lev 19_0_4   Time: 1275498000
09:30:53 2010.06.02 22:00    EURUSDm,M30: *********Name: _lev 19_0_3   Time: 1275498000
09:30:53 2010.06.02 22:00    EURUSDm,M30: *********Name: _lev 19_0_2   Time: 1275498000
09:30:53 2010.06.02 22:00    EURUSDm,M30: *********Name: _lev 19_0_1   Time: 1275498000
09:30:53 2010.06.02 22:00    EURUSDm,M30: *********Name: _lev 19_0_ 0   Time: 1275498000
09:30:53 2010.06.02 22:00    EURUSDm,M30: *********Name: _lev 10_0_8   Time: 1275606000
09:30:53 2010.06.02 22:00    EURUSDm,M30: *********Name: _lev 10_0_7   Time: 1275606000
09:30:53 2010.06.02 22:00    EURUSDm,M30: *********Name: _lev 10_0_6   Time: 1275606000
09:30:53 2010.06.02 22:00    EURUSDm,M30: *********Name: _lev 10_0_5   Time: 1275606000
09:30:53 2010.06.02 22:00    EURUSDm,M30: *********Name: _lev 10_0_4   Time: 1275606000
09:30:53 2010.06.02 22:00    EURUSDm,M30: *********Name: _lev 10_0_3   Time: 1275606000
09:30:53 2010.06.02 22:00    EURUSDm,M30: *********Name: _lev 10_0_2   Time: 1275606000
09:30:53 2010.06.02 22:00    EURUSDm,M30: *********Name: _lev 10_0_1   Time: 1275606000
09:30:53 2010.06.02 22:00    EURUSDm,M30: *********Name: _lev 10_0_ 0   Time: 1275606000
 
stryker251:
I am finally able to get these object names (example above). Now I only want the ones with the ending of "_2".
#define PREFIX "_lev"
#define POSTFIX "_2"
#define POSTFIX_OFFSET 1 // Length of POSTFIX - 1
for(int iObj=ObjectsTotal()-1; iObj >= 0; iObj--){
    string on = ObjectName(iObj);
    if (StringFind(on, name) == 0                                // Starts with _lev
    &&  StringSubstr(on, StringLen(on) - POSTFIX_OFFSET) == "_0" // Ends with _0
    ){
        // found one
    }
}
 

Many thanks WHRoeder and RaptorUK!!

Reason: