Do I need to check IsTradeAllowed() in my Expert Advisor?

 

Hi,

So far yes, my code is full of options where I check if the trading is allowed, then do something, else do otherwise, but I was just wondering... do I really need it? I mean, isn't Metatrader "smart enough" to not allow the EA to trade if AutoTrading is not checked? In other words, what I'm asking is, say I have an EA that doesn't do any checks, it just tries to execute an OrderSend at the very beginning of OnTick()... so if my AutoTrading buttond isn't checked, will the EA really open a position, or will I received an error? I believe it should be the latter, and in that case I don't really see the use case of IsTradeAllowed... unless I'm wrong and it's not the latter but the former, that is there's no internal check on whether AutoTrading button is on or off.

Am I missing something? Thanks in advance.

 
Carlos Moreno Gonzalez: So far yes, my code is full of options where I check if the trading is allowed, then do something, else do otherwise, but I was just wondering... do I really need it? I mean, isn't Metatrader "smart enough" to not allow the EA to trade if AutoTrading is not checked? In other words, what I'm asking is, say I have an EA that doesn't do any checks, it just tries to execute an OrderSend at the very beginning of OnTick()... so if my AutoTrading buttond isn't checked, will the EA really open a position, or will I received an error? I believe it should be the latter, and in that case I don't really see the use case of IsTradeAllowed... unless I'm wrong and it's not the latter but the former, that is there's no internal check on whether AutoTrading button is on or off. Am I missing something?

You will receive an error and the event will be logged in the journal.

Doing the checks is a question of proper design logic of your code and should be considered a good coding practice.

You shouldn't have any unnecessary code running, consuming extra CPU or RAM, when it can be avoided.

It also reduces message clutter in your logs that might lead you to overlook other more important log entries.

 
Fernando Carreiro #:

You will receive an error and the event will be logged in the journal.

Doing the checks is a question of proper design logic of your code and should be considered a good coding practice.

You shouldn't have any unnecessary code running, consuming extra CPU or RAM, when it can be avoided.

It also reduces message clutter in your logs that might lead you to overlook other more important log entries.

Makes a lot of sense. Thanks for the clarification!

Reason: