Download MetaTrader 5

EA behave differently based on MqlTick()

To add comments, please log in or register
Marcelo Coutinho
1205
Marcelo Coutinho  

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()
  }
//+------------------------------------------------------------------+
Rodrigo Malacarne
Moderator
10647
Rodrigo Malacarne  
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.

Marcelo Coutinho
1205
Marcelo Coutinho  
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 !
Rogerio Figurelli
Moderator
45120
Rogerio Figurelli  
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?

Marcelo Coutinho
1205
Marcelo Coutinho  
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
Rodrigo Malacarne
Moderator
10647
Rodrigo Malacarne  
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 ...

Marcelo Coutinho
1205
Marcelo Coutinho  
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 !
To add comments, please log in or register