Download MetaTrader 5
To add comments, please log in or register
Do you want to learn MQL5? 300 articles will help you!
moonsboy
889
moonsboy 2015.08.11 09:41 

Who knows whether there is a function or code that can read out the commission of a forex symbol before opening orders?  

moonsboy
889
moonsboy 2015.08.13 02:32  

Besides, is there a way to read out all the symbol names of a broker automatically?  

Keith Watford
Moderator
7960
Keith Watford 2015.08.13 04:55  
   int number = SymbolsTotal(true);        //If true all symbols, if false just those in the Market Watch window
   string SymbolArray[];
   ArrayResize(SymbolArray,number);
   for(int index=0;index<number;index++)
      SymbolArray[index]= SymbolName(index,true);  // must be true or false, the same as above
This will put them in an array
moonsboy
889
moonsboy 2015.08.14 01:09  
GumRai:
This will put them in an array
Thank you very much !
Carl Schreiber
5954
Carl Schreiber 2015.08.16 09:17  
GumRai:
...
//If true all symbols, if false just those in the Market Watch window

I read in the reference:

SymbolsTotal

Returns the number of available (selected in Market Watch or all) symbols.

int  SymbolsTotal(
   bool  selected      // True - only symbols in MarketWatch
   );

Parameters
selected  [in] Request mode. Can be true or false.
Return Value

If the 'selected' parameter is true, the function returns the number of symbols selected in MarketWatch. If the value is false, it returns the total number of all symbols.

Which is the exactly the opposite.

Keith Watford
Moderator
7960
Keith Watford 2015.08.16 10:08  
gooly:

I read in the reference:

Which is the exactly the opposite.

Well done for spotting the deliberate mistake :)

No, seriously, I wrote that little snippet of code a long time ago and I must have made an error in my commenting 

Carl Schreiber
5954
Carl Schreiber 2015.08.16 12:14  
GumRai:

Well done for spotting the deliberate mistake :)

No, seriously, I wrote that little snippet of code a long time ago and I must have made an error in my commenting 

May be it is not your fault - but a mistake in their reference.

Look at MqlRates and CopyRates():

Gets history data of MqlRates structure of a specified symbol-period 
in specified quantity into the rates_array array. The elements ordering 
of the copied data is from present to the past, i.e., starting position of 0 means the current bar.

"0 means current bar" which should have the highest time stamp but is is exactly the opposite:

//+------------------------------------------------------------------+
//|                                                Test_MqlRates.mq4 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+

void OnStart()  {
//---
   MqlRates Rates2[2];
   int i = Bars -3;
   while(i-->0) {
      int anz = CopyRates(_Symbol,_Period,i,2,Rates2);
      Comment("Mt4-Ref: The elements ordering of the copied data is from present to the past, "+
              "i.e., starting position of 0 means the current bar.\n",
              (string)i,"] 1=prevBar: ",Rates2[1].time,"   0=currentBar: ",Rates2[0].time
      );
      DebugBreak();
   }
}
//+------------------------------------------------------------------+



Try that in the debugger!



whroeder1
13627
whroeder1 2015.08.16 18:00  
No matter what is the property of the target array - as_series=true or as_series=false. Data will be copied so that the oldest element will be located at the start of the physical memory allocated for the array. -- CopyRates - MQL4 Documentation

Results exactly as documented.

Unless you want to modify the array use ArrayCopyRates - MQL4 Documentation only need one call in OnInit, auto-updates, contains all bars, no copying actually performed, in series order.



/
To add comments, please log in or register