SymbolInfoDouble returning le-05

To add comments, please log in or register
bti4
52
bti4  

Hi,

My apologies if this has been addressed before:


Print(SymbolInfoDouble("EURUSD",SYMBOL_POINT)); is returning le-05

Print(SymbolInfoDouble("GBPJPY",SYMBOL_POINT)); is returning 0.001 which is correct


I cant understand why EURUSD and GBPUSD etc all return le-05?


MT5 version 5 build 1940.


Any help would be greatly appreciated

Fernando Carreiro
4798
Fernando Carreiro  

bti4: My apologies if this has been addressed before:

Print(SymbolInfoDouble("EURUSD",SYMBOL_POINT)); is returning le-05

Print(SymbolInfoDouble("GBPJPY",SYMBOL_POINT)); is returning 0.001 which is correct

I cant understand why EURUSD and GBPUSD etc all return le-05?

MT5 version 5 build 1940.

Any help would be greatly appreciated

"le-05" is just a different representation of "0.00001" which is correct fo EUR/USD. It is simply because you are using the default representation of "Print" instead of defining your own.
bti4
52
bti4  
Fernando Carreiro:
"le-05" is just a different representation of "0.00001" which is correct fo EUR/USD. It is simply because you are using the default representation of "Print" instead of defining your own.

thank you for your response.

problem is when i run this:


orderPriceCurrent = PositionGetDouble(POSITION_PRICE_CURRENT);

orderPips = (NormalizeDouble(((PositionGetDouble(POSITION_PRICE_OPEN) - orderPriceCurrent)/SymbolInfoDouble(POSITION_SYMBOL,SYMBOL_TRADE_TICK_VALUE)),SymbolInfoInteger(POSITION_SYMBOL,SYMBOL_DIGITS))/10);

i get an error for diving by zero. I have broken this down and everything gives a correct value except for SymbolInfoDouble("EURUSD",SYMBOL_POINT)); It works fine on symbols with 3 digits though.


works perfectly in MQL4 ?

Fernando Carreiro
4798
Fernando Carreiro  

bti4: thank you for your response. problem is when i run this:

orderPips = (NormalizeDouble(((PositionGetDouble(POSITION_PRICE_OPEN) - orderPriceCurrent)/SymbolInfoDouble(POSITION_SYMBOL,SYMBOL_TRADE_TICK_VALUE)),SymbolInfoInteger(POSITION_SYMBOL,SYMBOL_DIGITS))/10);

i get an error for diving by zero. I have broken this down and everything gives a correct value except for SymbolInfoDouble("EURUSD",SYMBOL_POINT)); It works fine on symbols with 3 digits though.

works perfectly in MQL4 ?

That is absolutely horrible code to read or debug. Use variables and break it up.

Plus that is MQL5 Code, not MQL4 Code. The functions PositionGetDouble() and the enumeration constants POSITION_SYMBOL, POSITION_PRICE_OPEN, etc. are only valid in a MQL5 environment, not MQL4.

bti4
52
bti4  
Fernando Carreiro:

That is absolutely horrible code to read or debug. Use variables and break it up.

Plus that is MQL5 Code, not MQL4 Code. The functions PositionGetDouble() and the enumeration constants POSITION_SYMBOL, POSITION_PRICE_OPEN, etc. are only valid in a MQL5 environment, not MQL4.

Sorry i wasnt very clear.. thats been adapted for MQL5. The MQL4 version:


orderPips = MathAbs((NormalizeDouble(((orderPriceCurrent - OrderOpenPrice())/MarketInfo(OrderSymbol(),MODE_POINT)),MarketInfo(OrderSymbol(),MODE_DIGITS)))/10);


That works with all symbols with no problem at all.


MQL5:

orderPips = (NormalizeDouble(((PositionGetDouble(POSITION_PRICE_OPEN) - orderPriceCurrent)/SymbolInfoDouble(POSITION_SYMBOL,SYMBOL_POINT)),SymbolInfoInteger(POSITION_SYMBOL,SYMBOL_DIGITS))/10);


Broken down:

double output = PositionGetDouble(POSITION_PRICE_OPEN) - orderPriceCurrent;

=  - 0.002200000 (correct)

double output_2 = SymbolInfoDouble("EURUSD",SYMBOL_POINT);

= le-05 <- this seems to break it down

int output_3 = SymbolInfoInteger("EURUSD",SYMBOL_DIGITS);

= 5 (correct)


Basically im trying to get the pip gain / loss on open orders in MQL5. Ive started converting my MQL4 scripts and have now run into this problem.

Fernando Carreiro
4798
Fernando Carreiro  

bti4: Sorry i wasnt very clear.. thats been adapted for MQL5. The MQL4 version:

orderPips = MathAbs((NormalizeDouble(((orderPriceCurrent - OrderOpenPrice())/MarketInfo(OrderSymbol(),MODE_POINT)),MarketInfo(OrderSymbol(),MODE_DIGITS)))/10);

That works with all symbols with no problem at all.

MQL5:

orderPips = (NormalizeDouble(((PositionGetDouble(POSITION_PRICE_OPEN) - orderPriceCurrent)/SymbolInfoDouble(POSITION_SYMBOL,SYMBOL_POINT)),SymbolInfoInteger(POSITION_SYMBOL,SYMBOL_DIGITS))/10);

Broken down:

double output = PositionGetDouble(POSITION_PRICE_OPEN) - orderPriceCurrent;

=  - 0.002200000 (correct)

double output_2 = SymbolInfoDouble("EURUSD",SYMBOL_POINT);

= le-05 <- this seems to break it down

int output_3 = SymbolInfoInteger("EURUSD",SYMBOL_DIGITS);

= 5 (correct)

Basically im trying to get the pip gain / loss on open orders in MQL5. Ive started converting my MQL4 scripts and have now run into this problem.

Your error is in the use of POSITION_SYMBOL, which is an enumeration constant. If you want to derive the actual symbol then you have use the function to get it and not the enumeration constant.

string position_symbol = PositionGetString( POSITION_SYMBOL );

Also, I was not suggesting that you break it down just for testing purposes, but telling you to properly structure and breakdown the code in the real implementation.

bti4
52
bti4  
Fernando Carreiro:

Your error is in the use of POSITION_SYMBOL, which is an enumeration constant. If you want to derive the actual symbol then you have use the function to get it and not the enumeration constant.

Also, I was not suggesting that you break it down just for testing purposes, but telling you to properly structure and breakdown the code in the real implementation.

sadly same result...

      string ticket = PositionGetTicket(219405612); (ticket that is currently open)

      double orderPriceCurrent = PositionGetDouble(POSITION_PRICE_CURRENT);

      string position_symbol = PositionGetString( POSITION_SYMBOL );

      double price_difference = PositionGetDouble(POSITION_PRICE_OPEN) - orderPriceCurrent;

      double point = SymbolInfoDouble(position_symbol,SYMBOL_POINT);

      int digits = SymbolInfoInteger(position_symbol,SYMBOL_DIGITS);

      Print("Difference: " + price_difference + " Point: " + point + " Digits: " + digits);


2018.11.09 17:01:11.995 Slave_Reader_CopyTrade_BTI_test (EURUSD,H1) Difference: 0.0 Point: 1e-05 Digits: 5


Fernando Carreiro
4798
Fernando Carreiro  
bti4:

sadly same result...

      string ticket = 219405612; (ticket that is currently open)

      double orderPriceCurrent = PositionGetDouble(POSITION_PRICE_CURRENT);

      string position_symbol = PositionGetString( POSITION_SYMBOL );

      double price_difference = PositionGetDouble(POSITION_PRICE_OPEN) - orderPriceCurrent;

      double point = SymbolInfoDouble(position_symbol,SYMBOL_POINT);

      int digits = SymbolInfoInteger(position_symbol,SYMBOL_DIGITS);

      Print("Difference: " + price_difference + " Point: " + point + " Digits: " + digits);

2018.11.09 17:01:11.995 Slave_Reader_CopyTrade_BTI_test (EURUSD,H1) Difference: 0.0 Point: 1e-05 Digits: 5

Your code is riddled with problems.

  1. Print out the value of each variable and step to see where it fails!
  2. The position ticket is a "ulong", not a "string".
  3. When printing the point size, use "digits" to properly format it.
  4. Where is the your code to select the position first?
ulong ticket = 219405612;

if( PositionSelectByTicket( ticket ) )
{
   // The rest of the code here

   Print( "Point Size: ", DoubleToString( point, digits ) );
}
nicholi shen
2195
nicholi shen  

In addition to Fernando's comments, why are you punishing yourself by using all super-verbose low-level abstractions when the standard library has well documented wrappers to handle all that unnecessary repeating yourself. This is how developing in MQL5 should be... 

#include <Trade\Trade.mqh>
void OnStart()
{  
   CSymbolInfo s;
   CPositionInfo p;
   for(int i=PositionsTotal()-1; i>=0; --i){
      if(p.SelectByIndex(i) && s.Name(p.Symbol())){
         double pips = p.PriceCurrent() - p.PriceOpen();
         if(p.PositionType() == POSITION_TYPE_SELL)
            pips = -pips;
         pips = s.NormalizePrice(pips / s.Point() / 10);
         printf("%s: %s = %.1f pips", 
            s.Name(), p.TypeDescription(), pips
         );
      }
   }
}   


 

bti4
52
bti4  
Fernando Carreiro:

Your code is riddled with problems.

  1. Printed out the value of each variable and step to see where it fails!
  2. The position ticket is a "ulong", not a "string".
  3. Where is the your code to select the position first?

I have extracted segments for testing.

      ulong ticket = PositionSelectByTicket(219405612);

      string position_symbol = PositionGetString(POSITION_SYMBOL);

      double orderPriceCurrent = PositionGetDouble(POSITION_PRICE_CURRENT);      

      double price_difference = PositionGetDouble(POSITION_PRICE_OPEN) - orderPriceCurrent;

      double point = SymbolInfoDouble(position_symbol,SYMBOL_POINT);

      int digits = SymbolInfoInteger(position_symbol,SYMBOL_DIGITS);

      Print("Difference: " + price_difference + " Point: " + point + " Digits: " + digits);

OUTPUT: 2018.11.09 17:14:02.667 Slave_Reader_CopyTrade_BTI_test (EURUSD,H1) Difference: -0.000220000000000109 Point: 1e-05 Digits: 5


All works up till then normally.


nicholi shen
2195
nicholi shen  
bti4:

I have extracted segments for testing.

      ulong ticket = PositionSelectByTicket(219405612);

      string position_symbol = PositionGetString(POSITION_SYMBOL);

      double orderPriceCurrent = PositionGetDouble(POSITION_PRICE_CURRENT);      

      double price_difference = PositionGetDouble(POSITION_PRICE_OPEN) - orderPriceCurrent;

      double point = SymbolInfoDouble(position_symbol,SYMBOL_POINT);

      int digits = SymbolInfoInteger(position_symbol,SYMBOL_DIGITS);

      Print("Difference: " + price_difference + " Point: " + point + " Digits: " + digits);

OUTPUT: 2018.11.09 17:14:02.667 Slave_Reader_CopyTrade_BTI_test (EURUSD,H1) Difference: -0.000220000000000109 Point: 1e-05 Digits: 5


All works up till then normally.


If it wasn't obvious, you cannot concatenate strings to doubles. Furthermore, you need to either use DoubleToString when casting double to string type OR use a format specifier in conjunction with StringFormat/printf

To add comments, please log in or register