EA behave differently based on MqlTick()

 

Hi,

Does anyone know why an EA behave differently based on MqlTick() position.

Is it mandatory to have MqlTick() declaration inside OnTick() ? 

#include <Trade\Trade.mqh>
#include <Trade\PositionInfo.mqh>

   MqlTick price_info; 1st situation: Declared HERE (Global) and used in OnTick()
   
//+------------------------------------------------------------------+

void OnTick()
  {
   MqlTick price_info; 2nd situation: Declared in OnTick() and used in OnTick()
  }
//+------------------------------------------------------------------+
 
YouTrade:

Hi,

Does anyone know why an EA behave differently based on MqlTick() position.

Is it mandatory to have MqlTick() declaration inside OnTick() ? 

You have to declare the price_info variable as global.

Inside OnTick( ) you have to use:

SymbolInfoTick(_Symbol,price_info);

 That's it.

 
Malacarne:

You have to declare the price_info variable as global.

Inside OnTick( ) you have to use:

 That's it.

Thank you ... I will check that !
 
YouTrade:

Hi,

Does anyone know why an EA behave differently based on MqlTick() position.

Is it mandatory to have MqlTick() declaration inside OnTick() ? 

It's not mandatory, both cases are correct, i.e., you can declare price_info inside OnTick(), as you did at 2nd situation.

Can you share with us what is different in your case?

 
figurelli:

It's not mandatory, both cases are correct, i.e., you can declare price_info inside OnTick(), as you did at 2nd situation.

Can you share with us what is different in your case?

price_info value. Still trying to understand what is happening. I will let y know. Thank you
 
YouTrade:
price_info value. Still trying to understand what is happening. I will let y know. Thank you

Once you declare the price_info function, values are not automatically assigned to it. You have to "copy" your data into your variable. You do this using another function: SymbolInfoTick( ).

If you declare your variable without copying values into it, so you will get no values (I didn't test it yet, but maybe you can also get incorrect values).

Are you still getting these "different" values even after using the SymbolInfoTick function? It would be interesting to know that, so we could help you ...

 
Malacarne:

Once you declare the price_info function, values are not automatically assigned to it. You have to "copy" your data into your variable. You do this using another function: SymbolInfoTick( ).

If you declare your variable without copying values into it, so you will get no values (I didn't test it yet, but maybe you can also get incorrect values).

Are you still getting these "different" values even after using the SymbolInfoTick function? It would be interesting to know that, so we could help you ...

That is it ! I hate being Newbie !
Reason: