Market Info Function not working

Back to topics list To post a new topic, please log in or register
avatar
112
peterhw1 2015.03.18 12:20
 

I thought I'd try a new broker and wanted to check out spreads using the code below.

Running the EA showed figures (screenshot below)  which don't seem realistic and they don't change (as on another broker where the spreads are always changing)

The broker doesn't appear to even understand the problem (probably speaks for itself!).  The broker appears to suggest I have the decimal point in the wrong place (should be 3 pips)

Obviously the EA sort of works - it creates the comment - but the Market Info does appear to generate incorrect data

Any ideas ?

Shows Spread

string   myc = "";      
string   My_Symbols[10];
double   My_Spread;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{  myc = "Good Morning";
   Comment(myc);
   My_Symbols [1]    =  "AUDUSD";     My_Symbols [2]     =  "EURGBP";     My_Symbols [3]     =  "EURUSD";
   My_Symbols [4]    =  "GBPUSD";     My_Symbols [5]     =  "USDCAD";     My_Symbols [6]     =  "USDCHF";
   My_Symbols [7]    =  "USDJPY";     My_Symbols [8]     =  "";           My_Symbols [9]     =  "";
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
  }
void OnTick()
  {
//---
   myc = "Testing Spread";
   for (int My_Index=1; My_Index < 10; My_Index++)
   {  My_Spread      = MarketInfo(My_Symbols[My_Index],MODE_SPREAD);
      myc = myc + "\nSpread for "+My_Symbols[My_Index]+" = "+DoubleToString(My_Spread,Digits);
   }
   Comment(myc);
   return;
  }
//+------------------------------------------------------------------+

avatar
Moderator
3418
GumRai 2015.03.18 12:49 #
 
Spread is in points, not pips
avatar
13001
WHRoeder 2015.03.18 13:45 #
 
peterhw1: The broker appears to suggest I have the decimal point in the wrong place (should be 3 pips)
  1. Initializing an array with constants can be done at compile time
    string My_Symbols[]={"",  "AUDUSD", "EURGBP", "EURUSD", "GBPUSD", "USDCAD"
                              "USDCHF", "USDJPY" };
  2.    for (int My_Index=1; My_Index < 10; My_Index++) 
    
    Also get in the habit of using zero based indexes. It will help you in the future. Don't hard code numbers ArraySize(My_Symbols).
  3. Mode_spread returns the number points (1, 2, 3,...) To display it as a price delta you multiply by that currency's mode_point.
  4. DoubleToString(My_Spread,Digits)
    Digits only applies to the current chart pair. You need the currency's mode_digits.
avatar
112
peterhw1 2015.03.18 14:39 #
 

Many thanks for response.

Point 1 understood - very usefuk

Point 2 understood again and appreciate

Points 3 & 4 understand just took a short cut for example

Have modified as suggested (I think) but still get 'fixed' spread on new broker - could this be possible ?



string   myc = "";      
double   My_Spread   = 0;
double   My_Mode_Pt  = 0;
string   My_Symbols[]={  "AUDUSD", "EURGBP", "EURUSD", "GBPUSD", "USDCAD","USDCHF", "USDJPY" };
string   My_Symbol= "";
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{  myc = "Good Morning";
   Comment(myc);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
  }
void OnTick()
  {
//---
   myc = "Testing Spread";
   myc = myc + "\nArraySize(My_Symbols) = "+IntegerToString(ArraySize(My_Symbols));
   for (int My_Index=0; My_Index < ArraySize(My_Symbols); My_Index++)
   {  My_Symbol      = My_Symbols[My_Index];
      My_Spread      = MarketInfo(My_Symbol,MODE_SPREAD);
      My_Mode_Pt     = MarketInfo(My_Symbol,MODE_POINT);
      myc = myc + "\nMy_Index = "+IntegerToString(My_Index) + " My_Symbol = "+My_Symbol;
      myc = myc + " My_Mode_Pt = "+DoubleToString(My_Mode_Pt,5)+" Spread = "+DoubleToString(My_Spread,5);
   }
   Comment(myc);
   return;
  }
avatar
8
SurtiTrader 2015.03.19 08:18 #
 
I guess you should take some break and restart the whole process after some time. In order to achieve good market working functions.
avatar
13001
WHRoeder 2015.03.19 13:32 #
 
peterhw1: Have modified as suggested (I think) but still get 'fixed' spread on new broker - could this be possible ?
  1. It's possible if the broker only uses fixed spreads.
  2. Your original code works as posted
  3.  Your modified code works as posted
  4. Are the symbols exactly what you have in your market watch?
       // Broker's use a variety of nameing patterns: EURUSD, EURUSDm, EURUSDi
       // "EURUSD.", "EURUSD..", "EUR.USD", "EUR/USD", "EURUSD.stp", EURUSDct,
       // "EURUSD.G", "EURUSD+", EURUSDpro at least.
    

Back to topics list  

To add comments, please log in or register