Download MetaTrader 5
To add comments, please log in or register
Publish your article. Millions of traders are looking for good ideas!
luis
23
luis 2014.06.25 17:34 

I'm trying to get the current quote for a symbol not in current window. Unfortunately it doesn't work.

I have tried with iClose(mySymbolString, 0, 0), MarketInfo(mySymbolString, MODE_BID), and even SymbolInfoDouble(mySymbolString, SYMBOL_BID).

What I have tried so far:

1.- Any of the 3 above mentioned functions work when using Symbol() (that means, it works with symbol in current chart), but not with other Symbols NOT in current chart.

2.- When using iClose with a symbol NOT using Symbol() (even if the symbol is in current chart!) , but part of "Market Watch", then I get the quote BUT without decimals! (example: EURJPY should be 138.78, but I get 13878 (without decimal))

3.- For MarketInfo() and SymbolInfoDouble(), what I get is just "0", even when using a string with the symbol in current window.

My EA code:

#property copyright "Copyright 2014, RRR@RRR.com"
#property link      ""
#property strict
#property show_inputs

//! includes
#include <stdlib.mqh>
#include <WinUser32.mqh>
//!

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
  
  Print(StringConcatenate(iClose(Symbol(), 0, 0), " <-- YYYY ")); // Is: 1.3634 - Should be: 1.3634 OK
  Print(StringConcatenate(iClose("EURUSD", 0, 0), " <-- YYYY ")); // Is: 136344 - Should be: 1.3634
  Print(StringConcatenate(iClose("EURJPY", 0, 0), " <-- YYYY ")); // Is: 138785 - Should be: 138.78
  Print(StringConcatenate(iClose("EURCHF", 0, 0), " <-- YYYY ")); // Is: 121590 - Should be: 1.2159
  Print(StringConcatenate(iClose("EURGBP", 0, 0), " <-- YYYY ")); // Is: 80277  - Should be: 0.8027
  Print(SymbolInfoDouble(Symbol(), SYMBOL_BID)); // Is: 1.3634 - Should be: 1.3634 OK
  Print(SymbolInfoDouble("EURUSD", SYMBOL_BID)); // Is: 0      - Should be: 1.3634
  Print(SymbolInfoDouble("EURJPY", SYMBOL_BID)); // Is: 0      - Should be: 138.78
  Print(SymbolInfoDouble("EURCHF", SYMBOL_BID)); // Is: 0      - Should be: 1.2159
  Print(SymbolInfoDouble("EURGBP", SYMBOL_BID)); // Is: 0      - Should be: 0.8027
  Print(StrToDouble(MarketInfo(Symbol(), MODE_BID))); // Is: 1.3634 - Should be: 1.3634 OK
  Print(StrToDouble(MarketInfo("EURUSD", MODE_BID))); // Is: 0      - Should be: 1.3634
  Print(StrToDouble(MarketInfo("EURJPY", MODE_BID))); // Is: 0      - Should be: 138.78
  Print(StrToDouble(MarketInfo("EURCHF", MODE_BID))); // Is: 0      - Should be: 1.2159
  Print(StrToDouble(MarketInfo("EURGBP", MODE_BID))); // Is: 0      - Should be: 0.8027
  Print(iClose(Symbol(), 0, 0)); // Is: 1.3634 - Should be: 1.3634 OK
  Print(iClose("EURUSD", 0, 0)); // Is: 136344 - Should be: 1.3634
  Print(iClose("EURJPY", 0, 0)); // Is: 138785 - Should be: 138.78
  Print(iClose("EURCHF", 0, 0)); // Is: 121590 - Should be: 1.2159
  Print(iClose("EURGBP", 0, 0)); // Is: 80277  - Should be: 0.8027
  Print("  -- ");

  return(0);
};

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
  return(0);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{

  return(0);
}
qjol
3243
qjol 2014.06.25 20:51  
indicators "can not" open or close orders
Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2014.06.25 23:00  
luis_js:

I'm trying to get the current quote for a symbol not in current window. Unfortunately it doesn't work.

I have tried with iClose(mySymbolString, 0, 0), MarketInfo(mySymbolString, MODE_BID), and even SymbolInfoDouble(mySymbolString, SYMBOL_BID).

What I have tried so far:

1.- Any of the 3 above mentioned functions work when using Symbol() (that means, it works with symbol in current chart), but not with other Symbols NOT in current chart.

2.- When using iClose with a symbol NOT using Symbol() (even if the symbol is in current chart!) , but part of "Market Watch", then I get the quote BUT without decimals! (example: EURJPY should be 138.78, but I get 13878 (without decimal))

3.- For MarketInfo() and SymbolInfoDouble(), what I get is just "0", even when using a string with the symbol in current window.

My EA code:


Please show the excerpt from the log file . . . and then repeat with your code moved from init() to start() and show the excerpt from the log file again.
luis
23
luis 2014.06.26 06:16  
RaptorUK:

Please show the excerpt from the log file . . . and then repeat with your code moved from init() to start() and show the excerpt from the log file again.


I execute the code as an script.

One more info: my compiler version:

MQL4/MQL5 Compiler build 914 (21 Mar 2014)

my MetaTrader 4 version:

Version: 4.00 Build 646 (30 Apr 2014)



With the same code (copy-paste)  in both, start() and init() + "Hello/Goodbye, from ..." messages to identify where it is being called:

Terminal > Journal Tab output:

2014.06.26 08:05:48.559    Script g_test EURUSDdd,H4: removed
2014.06.26 08:05:48.515    Script a_active\g_test EURUSDdd,H4: loaded successfully

Terminal > Experts Tab output:

2014.06.26 08:05:48.559    Script g_test EURUSDdd,H4: removed
2014.06.26 08:05:48.558    g_test EURUSDdd,H4: uninit reason 0
2014.06.26 08:05:48.558    g_test EURUSDdd,H4: Goodbye, from start()
2014.06.26 08:05:48.558    g_test EURUSDdd,H4:   --
2014.06.26 08:05:48.558    g_test EURUSDdd,H4: 80250
2014.06.26 08:05:48.558    g_test EURUSDdd,H4: 121677
2014.06.26 08:05:48.558    g_test EURUSDdd,H4: 138781
2014.06.26 08:05:48.558    g_test EURUSDdd,H4: 136365
2014.06.26 08:05:48.558    g_test EURUSDdd,H4: 1.3636
2014.06.26 08:05:48.558    g_test EURUSDdd,H4: 0
2014.06.26 08:05:48.558    g_test EURUSDdd,H4: 0
2014.06.26 08:05:48.558    g_test EURUSDdd,H4: 0
2014.06.26 08:05:48.558    g_test EURUSDdd,H4: 0
2014.06.26 08:05:48.558    g_test EURUSDdd,H4: 1.3636
2014.06.26 08:05:48.558    g_test EURUSDdd,H4: 0
2014.06.26 08:05:48.558    g_test EURUSDdd,H4: 0
2014.06.26 08:05:48.557    g_test EURUSDdd,H4: 0
2014.06.26 08:05:48.557    g_test EURUSDdd,H4: 0
2014.06.26 08:05:48.557    g_test EURUSDdd,H4: 1.3636
2014.06.26 08:05:48.557    g_test EURUSDdd,H4: 80250 <-- YYYY
2014.06.26 08:05:48.557    g_test EURUSDdd,H4: 121856 <-- YYYY
2014.06.26 08:05:48.557    g_test EURUSDdd,H4: 138781 <-- YYYY
2014.06.26 08:05:48.557    g_test EURUSDdd,H4: 136365 <-- YYYY
2014.06.26 08:05:48.557    g_test EURUSDdd,H4: 1.3633 <-- YYYY
2014.06.26 08:05:48.557    g_test EURUSDdd,H4: 1.3633 <-- YYYY
2014.06.26 08:05:48.557    g_test EURUSDdd,H4: Hello, from start()
2014.06.26 08:05:48.557    g_test EURUSDdd,H4: initialized
2014.06.26 08:05:48.557    g_test EURUSDdd,H4:   --
2014.06.26 08:05:48.557    g_test EURUSDdd,H4: Goodbye, from init()
2014.06.26 08:05:48.557    g_test EURUSDdd,H4: 80250
2014.06.26 08:05:48.556    g_test EURUSDdd,H4: 121677
2014.06.26 08:05:48.556    g_test EURUSDdd,H4: 138781
2014.06.26 08:05:48.556    g_test EURUSDdd,H4: 136365
2014.06.26 08:05:48.556    g_test EURUSDdd,H4: 1.3636
2014.06.26 08:05:48.556    g_test EURUSDdd,H4: 0
2014.06.26 08:05:48.556    g_test EURUSDdd,H4: 0
2014.06.26 08:05:48.556    g_test EURUSDdd,H4: 0
2014.06.26 08:05:48.556    g_test EURUSDdd,H4: 0
2014.06.26 08:05:48.556    g_test EURUSDdd,H4: 1.3636
2014.06.26 08:05:48.556    g_test EURUSDdd,H4: 0
2014.06.26 08:05:48.556    g_test EURUSDdd,H4: 0
2014.06.26 08:05:48.556    g_test EURUSDdd,H4: 0
2014.06.26 08:05:48.556    g_test EURUSDdd,H4: 0
2014.06.26 08:05:48.556    g_test EURUSDdd,H4: 1.3636
2014.06.26 08:05:48.556    g_test EURUSDdd,H4: 80250 <-- YYYY
2014.06.26 08:05:48.551    g_test EURUSDdd,H4: 121856 <-- YYYY
2014.06.26 08:05:48.549    g_test EURUSDdd,H4: 138781 <-- YYYY
2014.06.26 08:05:48.546    g_test EURUSDdd,H4: 136365 <-- YYYY
2014.06.26 08:05:48.541    g_test EURUSDdd,H4: 1.3633 <-- YYYY
2014.06.26 08:05:48.541    g_test EURUSDdd,H4: 1.3633 <-- YYYY
2014.06.26 08:05:48.540    g_test EURUSDdd,H4: Hello, from init()
2014.06.26 08:05:48.515    Script a_active\g_test EURUSDdd,H4: loaded successfully
luis
23
luis 2014.06.26 06:27  
qjol:
indicators "can not" open or close orders

I'm aware of that.

iClose https://docs.mql4.com/series/iclose doesn't try to open / close orders, just get the close price (or the latest bid price if current bar is used).

This code is not for an indicator, as there are no macros:

#property indicator_separate_window

// or

#property indicator_chart_window
qjol
3243
qjol 2014.06.26 10:09  
Print(iClose("EURGBP", NULL, 0)); 

or

Print(iClose("EURGBP", Period(), 0));
luis
23
luis 2014.06.26 12:03  
qjol:


or



Good try! But unfortunately it doesn't work either ...

But did you try to run the code in your computer just to see if you get the same results? If it works in yours, then I'll have to dig into how my mt4 is installed, because I don't see where is the problem in the code ... 


By the way, I run it as an script. That's what I'm working on

luis
23
luis 2014.06.26 12:42  
luis_js:

Good try! But unfortunately it doesn't work either ...

But did you try to run the code in your computer just to see if you get the same results? If it works in yours, then I'll have to dig into how my mt4 is installed, because I don't see where is the problem in the code ... 


By the way, I run it as an script. That's what I'm working on


Solved. Thanks.

I have mt4 installed twice in 2 different directories: default one and another. When running the script with default, using iClose works. When using the other installation not. All other scripts that I have work great on both. I also use hard links between them, so each installation is always up to date. As I said, iClose only works with script and mt4 are installed in the default directory.

Again, thanks for taking your time to review.

luis
23
luis 2014.07.02 14:45  
luis_js:

Solved. Thanks.

I have mt4 installed twice in 2 different directories: default one and another. When running the script with default, using iClose works. When using the other installation not. All other scripts that I have work great on both. I also use hard links between them, so each installation is always up to date. As I said, iClose only works with script and mt4 are installed in the default directory.

Again, thanks for taking your time to review.



UPDATE - Final Answer: the problem end up being wrong info when using a demo server (just a specific demo server, all other demo servers provide right data). All functions (iClose(), MarketInfo() and SymbolInfoDouble()) do their job as expected, even if mt4 installed multiple times in different directories. (I tested it after a clean OS installation installing mt4 twice on 2 different directories).

It is also important to remember to add to MarketWatch window, the symbols that are going to be queried.

Ian Venner
2583
Ian Venner 2014.07.02 14:51  
luis_js:

UPDATE - Final Answer: the problem end up being wrong info when using a demo server (just a specific demo server, all other demo servers provide right data). All functions (iClose(), MarketInfo() and SymbolInfoDouble()) do their job as expected, even if mt4 installed multiple times in different directories. (I tested it after a clean OS installation installing mt4 twice on 2 different directories).

It is also important to remember to add to MarketWatch window, the symbols that are going to be queried.



That was going to be my suggestion to the issue.
/
To add comments, please log in or register