OrderCalcProfit() problem - page 2

 
Fernando Carreiro #:
Just as a test—do you have the AUDUSD symbol active on your Market Watch, and if not, can you please enable it, and try again?

I did not. I've added this symbol (both live and demo variants for my broker, AUDUSD and AUDUSD.a) to my Market Watch.

I will report back tomorrow as my EA only places orders once per day. I have only encountered this issue in live conditions and cannot replicate it in the tester.

 
Fernando Carreiro #:
Just as a test—do you have the AUDUSD symbol active on your Market Watch, and if not, can you please enable it, and try again?

@Fernando Carreiro, what are you thinking? Looks like this had an effect.

I have the EA running in two terminals, trading the same symbols (DE40, GBPJPY, GBPUSD, USDJPY).

  1. First terminal, now with AUDUSD added to the Market Watch: 8/8 trades had their lot sizes calculated correctly (via OrderCalcProfit())
  2. Second terminal, AUDUSD not in the Market Watch: 8/8 trades had their lot sizes calculated incorrectly (i.e. set to SYMBOL_VOLUME_MAX)

I was reading through this material: https://www.mql5.com/en/book/automation/experts/experts_ordercalcprofit

Which made me realise the terminal needs to exchange the order profit currency to my account currency to calculate the theoretical profit value. So I added EURAUD and AUDJPY to the Market Watch for the second terminal. This didn't help and all calculations failed.

It was only once AUDUSD was added (to the first terminal) that OrderCalcProfit() seems well-behaved.

MQL5 Book: Trading automation / Creating Expert Advisors / Estimating the profit of a trading operation: OrderCalcProfit
MQL5 Book: Trading automation / Creating Expert Advisors / Estimating the profit of a trading operation: OrderCalcProfit
  • www.mql5.com
One of the MQL5 API functions, OrderCalcProfit , allows you to pre-evaluate the financial result of a trading operation if the expected conditions...
 
Bill M #:

@Fernando Carreiro, what are you thinking? Looks like this had an effect.

I have the EA running in two terminals, trading the same symbols (DE40, GBPJPY, GBPUSD, USDJPY).

  1. First terminal, now with AUDUSD added to the Market Watch: 8/8 trades had their lot sizes calculated correctly (via OrderCalcProfit())
  2. Second terminal, AUDUSD not in the Market Watch: 8/8 trades had their lot sizes calculated incorrectly (i.e. set to SYMBOL_VOLUME_MAX)

I was reading through this material: https://www.mql5.com/en/book/automation/experts/experts_ordercalcprofit

Which made me realise the terminal needs to exchange the order profit currency to my account currency to calculate the theoretical profit value. So I added EURAUD and AUDJPY to the Market Watch for the second terminal. This didn't help and all calculations failed.

It was only once AUDUSD was added (to the first terminal) that OrderCalcProfit() seems well-behaved.

It's probably an issue due to the suffix as the needed symbols (like AUDUSD) are supposed to be added (but hidden) automatically.

Could you send me a private message with the broker you are using ? I would check it.

 

So I run a small test, on your broker, live account in AUD. I tried with several symbols (GBPJPY.a,...) and got each time the same behaviour.

1. I closed all charts. I "Hide all" in Market Watch.

2. I add one symbol. Then open a chart on this symbol.

3. I ran my script.

(DE40.a,H1)    account currency is AUD
(DE40.a,H1)    DE40.a: BUY PROFIT: via OrderCalcProfit = 0.00 AUD (1000 ticks) with 0.10 lot.
(DE40.a,H1)    Symbol "DE40.a" selected in Market Watch and Visible .
(DE40.a,H1)    Symbol "EURAUD" selected in Market Watch and NOT Visible.
(DE40.a,H1)    Symbol "EURUSD" selected in Market Watch and NOT Visible.

(DE40.a,H1)    account currency is AUD
(DE40.a,H1)    DE40.a: BUY PROFIT: via OrderCalcProfit = 1.63 AUD (1000 ticks) with 0.10 lot.
(DE40.a,H1)    Symbol "DE40.a" selected in Market Watch and Visible .
(DE40.a,H1)    Symbol "EURAUD" selected in Market Watch and NOT Visible.
(DE40.a,H1)    Symbol "EURUSD" selected in Market Watch and NOT Visible.

The first time I got 0, which is 'normal' and can always happen if the underlying data feed are not ready. Then I got correct values each time. I didn't add any additional symbol myself, only the tested symbol.

So I can't reproduce your issue, as you said you always got 0.0 returned by OrderCalcProfit() (except adding some symbol manually).

 
Alain Verleyen #:

So I run a small test, on your broker, live account in AUD. I tried with several symbols (GBPJPY.a,...) and got each time the same behaviour.

1. I closed all charts. I "Hide all" in Market Watch.

2. I add one symbol. Then open a chart on this symbol.

3. I ran my script.

(DE40.a,H1)    account currency is AUD
(DE40.a,H1)    DE40.a: BUY PROFIT: via OrderCalcProfit = 0.00 AUD (1000 ticks) with 0.10 lot.
(DE40.a,H1)    Symbol "DE40.a" selected in Market Watch and Visible .
(DE40.a,H1)    Symbol "EURAUD" selected in Market Watch and NOT Visible.
(DE40.a,H1)    Symbol "EURUSD" selected in Market Watch and NOT Visible.

(DE40.a,H1)    account currency is AUD
(DE40.a,H1)    DE40.a: BUY PROFIT: via OrderCalcProfit = 1.63 AUD (1000 ticks) with 0.10 lot.
(DE40.a,H1)    Symbol "DE40.a" selected in Market Watch and Visible .
(DE40.a,H1)    Symbol "EURAUD" selected in Market Watch and NOT Visible.
(DE40.a,H1)    Symbol "EURUSD" selected in Market Watch and NOT Visible.

The first time I got 0, which is 'normal' and can always happen if the underlying data feed are not ready. Then I got correct values each time. I didn't add any additional symbol myself, only the tested symbol.

So I can't reproduce your issue, as you said you always got 0.0 returned by OrderCalcProfit() (except adding some symbol manually).

Thanks for looking @Alain Verleyen.

When you say it is "normal" to get profit of 0 the first time OrderCalcProfit() is called, perhaps because our terminal is missing data, what is the most appropriate handling of this?

  • Do we need to have code to force the fetching of data (e.g. a call to CopyRates()), or will this have been triggered for us? I assume this is for current FX rates between the traded symbol and our account currency?
  • Should we just try again later to submit an order? i.e. next tick 
  • A sleep/retry loop?
  • Something else?
Thanks again for all your help so far.
 
Bill M #:

Thanks for looking @Alain Verleyen.

When you say it is "normal" to get profit of 0 the first time OrderCalcProfit() is called, perhaps because our terminal is missing data, what is the most appropriate handling of this?

  • Do we need to have code to force the fetching of data (e.g. a call to CopyRates()), or will this have been triggered for us? I assume this is for current FX rates between the traded symbol and our account currency?
  • Should we just try again later to submit an order? i.e. next tick 
  • A sleep/retry loop?
  • Something else?
Thanks again for all your help so far.

I am just waiting next tick.

You can explore other methods if you need it.