Objectget and objectgetvaluebyshift question - page 2

 
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.


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

Many thanks for your help. How to print to see the price1... in the journal to make sure it works.
 
Rajakumar1:
Many thanks for your help. How to print to see the price1... in the journal to make sure it works.
The same way you print the name... 
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);
         Print("price1: ", price1);
        }

      if(ObjectType(name) == OBJ_TREND && name == "Trendline2-m30")
        {
         price2 = ObjectGetValueByShift(name, 0);
         Print("price2: ", price2);
        }
     }
 
honest_knave:
The same way you print the name... 
Thanks. I have the print command in the EA. It is not getting printed in the journal. Where does it print the output?.
 
Rajakumar1:
Thanks. I have the print command in the EA. It is not getting printed in the journal. Where does it print the output?.

Experts (tab to the left of Journal)
 
honest_knave:

Experts (tab to the left of Journal)
I have an indicator drawing trend line. The EA is based on the trend lines drawn by the indicator. Is there any way to check why it not printing the values.  I am attaching the files. Sorry to bother you. Thanks for your help.
 
Rajakumar1:
I have an indicator drawing trend line. The EA is based on the trend lines drawn by the indicator. Is there any way to check why it not printing the values.  I am attaching the files. Sorry to bother you. Thanks for your help.


You will need to go through your code adding Print statements at various points.

That way you can track down your problem.

You need to look for functions not getting called, or unexpected values of variables.

It will take some time, but it is something you can do yourself.

For example, I have an EA with a variable that increases by 1 every tick.

I don't know why sometimes the variable gets reset back to 0  


#property strict

int myVariable;

int OnInit()
  {
   myVariable = 0;
   Print(__FUNCTION__, " // myVariable = ", myVariable);
   EventSetTimer(5);
   return(INIT_SUCCEEDED);
  }

void OnTimer()
  {
   myVariable = 0;
   Print(__FUNCTION__, " // myVariable = ", myVariable);
  }

void OnTick()
  {
   myVariable++;
   Print(__FUNCTION__, " // myVariable = ", myVariable);
  }


And the output:




I can see that the myVariable is increasing by 1 every tick, but OnTimer() is resetting it back to zero.

I now know where the problem is.

----

Or you can try to use the debug function built into MetaEditor, although some users have been reporting issues with that... YMMV

 
honest_knave:


You will need to go through your code adding Print statements at various points.

That way you can track down your problem.

You need to look for functions not getting called, or unexpected values of variables.

It will take some time, but it is something you can do yourself.

For example, I have an EA with a variable that increases by 1 every tick.

I don't know why sometimes the variable gets reset back to 0  



And the output:

Thanks. Shall I delete the files ?.



I can see that the myVariable is increasing by 1 every tick, but OnTimer() is resetting it back to zero.

I now know where the problem is.

----

Or you can try to use the debug function built into MetaEditor, although some users have been reporting issues with that... YMMV

 
Rajakumar1:
Thanks. Shall I delete the files.
 
Rajakumar1:
Thanks. Shall I delete the files.


That is your decision - there are nearly 800 lines of code between those 2 indicators... somebody may have the time to go through it for you.

But you may get a quicker solution by narrowing down the problem yourself first. 

Good luck 


 
honest_knave:


That is your decision - there are nearly 800 lines of code between those 2 indicators... somebody may have the time to go through it for you.

But you may get a quicker solution by narrowing down the problem yourself first. 

Good luck 


Many thanks for your help. Any area where to look first?. The Meta editor shows only warnings. No errors.

Reason: