Objectget and objectgetvaluebyshift question

 

HI can anyone help with this. I have an ea that gets a price value from a horizontal line or trendline. However i have the code as follows but it will not pick up either value. If i remove the Objectgetvaluebyshift it will pick up the Horizontal line price and vice versa. But i need it to recognise both and get the value from which ever line i have on my chart(either a trand or h_line). Maybe someone will post a bit of code so i can understand what to do.

thanks.

tp =(ObjectGetValueByShift( TP_P, OBJPROP_PRICE1)) || (ObjectGet( TP_P, OBJPROP_PRICE1));

 

ObjectGetValueByShift( string name, int shift)

OBJPROP_PRICE1 is not the "shift"... Shift is the bar number at which you want to take the value -- applicable to trendline and similar objects

double tp = ObjectGetValueByShift( TP_P, 0); // assuming TP_P is a string variable containing the name of the object, and you want the value of the line at the current bar

 
phy:

ObjectGetValueByShift( string name, int shift)

OBJPROP_PRICE1 is not the "shift"... Shift is the bar number at which you want to take the value -- applicable to trendline and similar objects

double tp = ObjectGetValueByShift( TP_P, 0); // assuming TP_P is a string variable containing the name of the object, and you want the value of the line at the current bar


I have tried what you have explianed. It doesnt seen to work. Any other info would be great.
 

gavin:

I have tried what you have explianed. It doesnt seen to work. Any other info would be great.

Does what uyou explained obtain the vaule from both a trendline or a h_line, which ever i have loaded on the chart at the time?

 

Post your code, we have no idea what you have done.

 

This is what i had.

--------------------------------------------------------

string TP_P;
if (OrderType()==OP_BUY) TP_P = BTP;
if (OrderType()==OP_SELL) TP_P = STP;

double tp;

tp =(ObjectGetValueByShift( TP_P, OBJPROP_PRICE1)) || (ObjectGet( TP_P, OBJPROP_PRICE1));

-----------------------------------------------------------------------------------------------------------------

I then put this in instead, what you said yea?.

----------------------------------------------------------

tp = ObjectGetValueByShift( TP_P,0);

 

any helpers??

 
if (ObjectType(TP_P) == OBJ_TREND) tp = ObjectGetValueByShift(TP_P, shift);
else                               tp = ObjectGEt(TP_P, OBJPROP_PRICE1)
 
WHRoeder:


So simple now i have seen it. Thanks alot mate for the help. That has worked out just how i wanted. Cheers....
 

Hi,

I have the following code for getting the price from trendline. It is not working. Any help please.

int obj_total = ObjectsTotal();
   string name;
   for(int j = 0; j<obj_total; j++)
   {
   name = ObjectName(j);
   Print(j, "Object - ", name);
   }
      if(ObjectType(name) == OBJ_TREND && name == "Trendline1-m30")
      {
       price1 = ObjectGetValueByShift(name, 0);
      }

      if(ObjectType(name) == OBJ_TREND && name == "Trendline2-m30")
      {
       price2 = ObjectGetValueByShift(name, 0);
      }

 

Hello, please use the SRC button when posting code.

All of the code in yellow is OUTSIDE the 'for' loop.

So the value of 'name' is always the name of the final object.

int obj_total = ObjectsTotal();
   string name;
   for(int j = 0; j<obj_total; j++)
   {
   name = ObjectName(j);
   Print(j, "Object - ", name);
   }
      if(ObjectType(name) == OBJ_TREND && name == "Trendline1-m30")
      {
       price1 = ObjectGetValueByShift(name, 0);
      }

      if(ObjectType(name) == OBJ_TREND && name == "Trendline2-m30")
      {
       price2 = ObjectGetValueByShift(name, 0);
      }


Perhaps try this (presuming price1 and price2 are already declared somewhere else):

   int obj_total = ObjectsTotal();
   string name;
   for(int j = 0; j<obj_total; j++)
     {
      name = ObjectName(j);
      Print(j, "Object - ", name);
      if(ObjectType(name) == OBJ_TREND && name == "Trendline1-m30")
        {
         price1 = ObjectGetValueByShift(name, 0);
        }

      if(ObjectType(name) == OBJ_TREND && name == "Trendline2-m30")
        {
         price2 = ObjectGetValueByShift(name, 0);
        }
     }
Reason: