Download MetaTrader 5

Objectget and objectgetvaluebyshift question

To add comments, please log in or register
gavin
390
gavin  

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));

Ray
2649
Ray  

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

gavin
390
gavin  
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
390
gavin  

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?

Ray
2649
Ray  

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

gavin
390
gavin  

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);

gavin
390
gavin  

any helpers??

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


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

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);
      }

honest_knave
Moderator
2326
honest_knave  

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);
        }
     }
123
To add comments, please log in or register