SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE) sometimes zero - page 2

 
Instead of using the Tick Value directly, consider using the function OrderCalcProfit, because it will apply the correct profit calculation method depending on the CALC_MODE for that symbol.
Documentation on MQL5: Trade Functions / OrderCalcProfit
Documentation on MQL5: Trade Functions / OrderCalcProfit
  • www.mql5.com
OrderCalcProfit - Trade Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Fernando Carreiro #:
Instead of using the Tick Value directly, consider using the function OrderCalcProfit instead, because it will apply the correct profit calculation method depending on the CALC_MODE for that symbol.


In my case SYMBOL_CALC_MODE_CFD

Thanks for your answer, I will try to replace my code with OrderCalcProfit()

I was using Tick Value to calculate a lot size, so I cannot provide a lot size to OrderCalcProfit()


I will try to rewrite my code other way, thanks

 
Philippe Pauleau #: In my case SYMBOL_CALC_MODE_CFD. Thanks for your answer, I will try to replace my code with OrderCalcProfit() I was using Tick Value to calculate a lot size, so I cannot provide a lot size to OrderCalcProfit().I will try to rewrite my code other way, thanks

You can! These are the steps I take. I supply the function with a lot size equal to the “Max Lot Size” allowed for the symbol in question, then calculate the ratio needed to achieve the fractional risk that I wish to apply, to get the correct volume for the order. I then align that with the “Lot Step” and finally check it against both the maximum and minimum allowed lots for the symbol.

The reason I use the “maximum” lots instead of just “1.0” lots as a reference value is because there is no guarantee that the value of 1.0 is within the minimum and maximum values allowed. Given that using 1.0, or the maximum, gives equivalent results anyway (by using the ratio method), I choose to use the “max lots” as the reference point which also offers the most precision for the calculation.

Something like this ...

// This code will not compile. It is only a example reference

if( OrderCalcProfit( eOrderType, _Symbol, dbLotsMax, dbPriceOpen, dbPriceStopLoss, dbProfit ) )
{
   dbOrderLots = fmin( fmax( round( dbRiskMax * dbLotsMax / ( -dbProfit * dbLotsStep ) )
               * dbLotsStep, dbLotsMin ), dbLotsMax ); 
      
   // the rest of the code ...
};
 
Fernando Carreiro #:

You can! These are the steps I take. I supply the function with a lot size equal to the “Max Lot Size” allowed for the symbol in question, then calculate the ratio needed to achieve the fractional risk that I wish to apply, to get the correct volume for the order. I then align that with the “Lot Step” and finally check it against both the maximum and minimum allowed lots for the symbol.

The reason I use the “maximum” lots instead of just “1.0” lots as a reference value is because there is no guarantee that the value of 1.0 is within the minimum and maximum values allowed. Given that using 1.0, or the maximum, gives equivalent results anyway (by using the ratio method), I choose to use the “max lots” as the reference point which also offers the most precision for the calculation.

Something like this ...


Thanks, I was thinking about using 1.0 lots but your idea makes sense.


PS: In fact my broker is returning a wrong TickValue on real account MT5 servers for DowJones symbol, whereas under the sames conditions the TickValue is good using their demo servers. So my EA works fine on demo servers only for now :)

In fact the TickValue returned by real account servers is 10 times less than what it should be (and the official value that is shown on their website for the symbol)


When I report the issue, they say they are aware but reluctant to fix it as this change would screw up the behavior of thousands of existing EAs that are already working with this setting.

 
Philippe Pauleau #: Thanks, I was thinking about using 1.0 lots but your idea makes sense. PS: In fact my broker is returning a wrong TickValue on real account MT5 servers for DowJones symbol, whereas under the sames conditions the TickValue is good using their demo servers. So my EA works fine on demo servers only for now :) In fact the TickValue returned by real account servers is 10 times less than what it should be (and the official value that is shown on their website for the symbol). When I report the issue, they say they are aware but reluctant to fix it as this change would screw up the behavior of thousands of existing EAs that are already working with this setting.

That does not seem like a very smart thing for a broker to say! That is like a car manufacture saying that they are NOT going to fix a problem in the gear shift because everyone is already used to shifting from 1st to 3rd, without using 2nd.

I suggest changing your broker.

 
Fernando Carreiro #:

You can! These are the steps I take. I supply the function with a lot size equal to the “Max Lot Size” allowed for the symbol in question, then calculate the ratio needed to achieve the fractional risk that I wish to apply, to get the correct volume for the order. I then align that with the “Lot Step” and finally check it against both the maximum and minimum allowed lots for the symbol.

The reason I use the “maximum” lots instead of just “1.0” lots as a reference value is because there is no guarantee that the value of 1.0 is within the minimum and maximum values allowed. Given that using 1.0, or the maximum, gives equivalent results anyway (by using the ratio method), I choose to use the “max lots” as the reference point which also offers the most precision for the calculation.

Something like this ...

Hi Fernando,

brilliant. I'm very happy about the resumed thread.

I've done a rework of my code and I use that cool onboard function 

OrderCalcProfit

now.

Thank you very much.

Lukas

 
lukas #:Hi Fernando, brilliant. I'm very happy about the resumed thread. I've done a rework of my code and I use that cool onboard function now. Thank you very much. Lukas
You are welcome!
 

Hi guys,


after some weeks of testing, it seems the Function OrderCalcProfit has the problem (CADJPY), too: It returns a zero value:


2022.11.01 03:00:38.794 Bot (CADJPY,D1) > Lot_Volumen_Berechnen: Starte OrderCalcProfit() mit direction: ORDER_TYPE_BUY, ASK_Preis: 109.088, StopLossPreis: 107.845
2022.11.01 03:00:38.795 Bot (CADJPY,D1) > Lot_Volumen_Berechnen: Starte OrderCalcProfit: GetLastError: 0, StopLoss_Ist_Betrag_riskiert_global: 0.000
2022.11.01 03:00:38.795 Bot (CADJPY,D1) > FEHLER: Lot_Volumen_Berechnen: Nicht gesetzt.

2022.11.01 04:00:38.717 Bot (CADJPY,D1) > Lot_Volumen_Berechnen: Starte OrderCalcProfit() mit direction: ORDER_TYPE_BUY, ASK_Preis: 109.204, StopLossPreis: 107.961
2022.11.01 04:00:38.717 Bot (CADJPY,D1) > Lot_Volumen_Berechnen: Starte OrderCalcProfit: GetLastError: 0, StopLoss_Ist_Betrag_riskiert_global: -845.960

As you see, the target variable 

StopLoss_Ist_Betrag_riskiert_global

is empty (0.0) after first try. One hour later, after bot's second try, it's magically filled.

The function OrderCalcProfit doesn't return an error nor _LastError is set.


So I guess I have too code a little loop, until 

OrderCalcProfit

returns a value.


What do you think?


regards,


Lukas

 
lukas #: Hi guys, after some weeks of testing, it seems the Function OrderCalcProfit has the problem (CADJPY), too: It returns a zero value: As you see, the target variable is empty (0.0) after first try. One hour later, after bot's second try, it's magically filled. The function OrderCalcProfit doesn't return an error nor _LastError is set. So I guess I have too code a little loop, until returns a value. What do you think?

@lukas, It seems you are using the function while your EA is running on a chart that is not CADJPY. And if so, you are forgetting to synchronise the data first. That is why you are getting zero on the first try.

Please read the following section so as to better understand the need to update and synchronise your symbols data ...

Documentation on MQL5: Timeseries and Indicators Access / Organizing Data Access
Documentation on MQL5: Timeseries and Indicators Access / Organizing Data Access
  • www.mql5.com
Organizing Data Access - Timeseries and Indicators Access - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Fernando Carreiro #:

@lukas, It seems you are using the function while your EA is running on a chart that is not CADJPY. And if so, you are forgetting to synchronise the data first. That is why you are getting zero on the first try.

Please read the following section so as to better understand the need to update and synchronise your symbols data ...

Hi Fernando, thanks for your help.

The EA does really run on chart CADJPY.

I've found a little test to check sync status in an other thread:


   Print("  *** 1.Date Chart: ", (datetime) SeriesInfoInteger(Symbol(), Period(), SERIES_FIRSTDATE));
   Print("  *** 1.Date Term:  ", (datetime) SeriesInfoInteger(Symbol(), Period(), SERIES_TERMINAL_FIRSTDATE));
   Print("  *** 1.Date Serv:  ", (datetime) SeriesInfoInteger(Symbol(), Period(), SERIES_SERVER_FIRSTDATE));
   Print("  *** isSync  ", (bool )SeriesInfoInteger(Symbol(), Period(), SERIES_SYNCHRONIZED));


I've insert it into my EA and looking forward for next trade log.

But I don't understand, when synchronisation _is really_ necessary. Is it just for history series in SeriesInfoInteger?

In my thinking a manual sync shouldn't be necessary for other functions like OrderCalcProfit? Not sure hm.

Sometimes I see some auto messages "has been syncronized" in terminal log.

regards,

Lukas