Questions how to ensure EA is constantly checking current price

 
hi

i am trying to get the EA to check if the current ask/bid is above/below my target price, execute a function. So the script needs to constantly check the current bid/ask price

My question is, do i need to add any special command or routine so that it will be constantly checking for the current ask/bid price?

if yes, what is it?

thanks in advance

 
tanwt:
hi

i am trying to get the EA to check if the current ask/bid is above/below my target price, execution a function, so the script needs to constantly check the current/bid price

My question is, do i need to add any special command or routine so that it will be constantly checking for the current ask/bid price?

if yes, what is it?

thanks in advance

Bid for current bid and Ask for current ask price 

 

If there is no tick there is no change of the price. Use OnTick() and if you want to be sure, use the CSymbolInfo class and

CSymbolInfo::RefreshRates() followed by .Ask() and .Bid().  

 

thanks all

i will try

 

what about MarketInfo(Symbol(),MODE_BID) and MarketInfo(Symbol(),MODE_ASK) ?

 can it do the job? 

 
tanwt:

thanks all

i will try

 

what about MarketInfo(Symbol(),MODE_BID) and MarketInfo(Symbol(),MODE_ASK) ?

 can it do the job? 

Mode Bid for  for sell

Mode ask for buy 

 
Use the class as mentioned. It uses exactly this in the end. 
 
Doerk Hilger:
Use the class as mentioned. It uses exactly this in the end. 

thanks

 will try it 

 
Doerk Hilger:
Use the class as mentioned. It uses exactly this in the end. 

Hi Doerk,

To clarify

is it every single code inside the OnTick() will be executed once there's a tick change?

also another seprate question. For calling the MA function like this iMA(Symbol(), 0, MA_Period2, MA_Shift2, MA_Method2, Applied_Price2, 1), if we use "PRICE_CLOSE"  and the bar hasn't close yet, will it use the tick price as "PRICE_CLOSE" ?

Thanks 

 
tanwt:

Hi Doerk,

To clarify

is it every single code inside the OnTick() will be executed once there's a tick change?

also another seprate question. For calling the MA function like this iMA(Symbol(), 0, MA_Period2, MA_Shift2, MA_Method2, Applied_Price2, 1), if we use "PRICE_CLOSE"  and the bar hasn't close yet, will it use the tick price as "PRICE_CLOSE" ?

Thanks 

Yes, OnTick() will execute on every tick. But if OnTick() is still processing when a new tick arrives it won't process the new tick

And yes, using PRICE_CLOSE of the current bar [0] will get the current price. Works fine live though it can have unexpected results when using backtester (to prevent looking into the future).
 
Stuart Browne:
Yes, OnTick() will execute on every tick. But if OnTick() is still processing when a new tick arrives it won't process the new tick

And yes, using PRICE_CLOSE of the current bar [0] will get the current price. Works fine live though it can have unexpected results when using backtester (to prevent looking into the future).

Thanks Stuart. I understand now

 Do you have any idea how fast it can complete execution before the next tick arrives? i understand it depends a lot on how many codes you put in but would appreciate some feedback based on your experience. As long as it can complete before next tick comes, should be good enough

Regarding the MA, that means the MA value will keep fluctuating before the bar closes? 

 btw, the original code which i am editing is using int Start(). Can i know under what condition the codes inside Start() will be executed? 

 
tanwt:

Thanks Stuart. I understand now

 Do you have any idea how fast it can complete execution before the next tick arrives? i understand it depends a lot on how many codes you put in but would appreciate some feedback based on your experience. As long as it can complete before next tick comes, should be good enough

Regarding the MA, that means the MA value will keep fluctuating before the bar closes? 

 btw, the original code which i am editing is using int Start(). Can i know under what condition the codes inside Start() will be executed? 

Welcome mate :)

How fast the program completes is totally dependent on what logic needs to be executed in each tick event, along with any other events that are firing (eg Timer events, chart events, web requests, file operations etc etc). And how quickly every tick arrives is totally dependant on the pair. Some volatile pairs could have multiple ticks per second, some might only have a few a minute. 

But in general, MQ code is pretty efficient as a language (as long as it's programmed well!) so can handle most situations you would want to program without many problems. Though I personally wouldn't use it for high frequency micro pip scalping!

Re the MA, yes, if you use the current close value (ie the current bid), the MA value of the current candle will keep fluctuating. That's why most MA strategies use the close value of the previous bar (Close[1])

Start() is pretty much a deprecated function with the latest builds and differs depending on the type of program using it. but is basically equivalent to OnTick and OnCalculate. Probably best if you read up the docs here and here

Finally, if you're worried about execution speed, you need to keep in mind that indicators all run in the same thread whereas EAs run in their own threads. But as I said, for 99% of what you want to get out of MT, it shouldn't be a problem.

Special Functions - Program in MQL4 - MQL4 Tutorial
Special Functions - Program in MQL4 - MQL4 Tutorial
  • book.mql4.com
Special Functions - Program in MQL4 - MQL4 Tutorial
Reason: