Problem with FXCM and script?

 

Hi,


I am trying to write a simple script to place orders for me using the include file OrdersSuite.mqh and my own include file myfunctions.mqh. The code I have written works perfectly on my main broker Alpari UK. But I cannot seem to get it to work with FXCM. All values at calculated correctly from print out as far as I can tell. Both Alpari and FXCM use fractional pips. The error I get is-3 ("Account/MarketInfo=0").

Any thoughts?



#include <OrdersSuite.mqh>
#include <myfunctions.mqh>
#include <WinUser32.mqh>

extern int     ExpertID = 1235;//used for magicnumber 
extern bool    Debug = true;
extern double  dMaxRisk = 0.01;//percentage free margin to risk per trade
extern double  dDecreaseFactor = 0;//Percentage to decrease lot size after a loss
extern int     iSlippage = 5;//in points - converted in event of fractional pips
int            iMagicNumber;
int            PipFactor = 1;

//+------------------------------------------------------------------+
//| Initialization Function                                          |
//+------------------------------------------------------------------+
int init() {
//----Assign magic number based on symbol and period---+ 
   iMagicNumber = UniqueMagicNumber(ExpertID);
   if(Debug==true) Print("iMagicNumber = ",iMagicNumber); 
//----Take into account fractional pips---+ 
   PipFactor = FractionalPipCheck(Digits);
   if(Debug==true) Print("PipFactor = ",PipFactor); 
//----
   return(0);
}  
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start() {
//----Trading Checks-------------------------------------------------+
    if(TimeInRange(TimeCurrent(), "0 00:00", "5 23:00", 15)==0) {Comment("Market is not open"); return(0);}
    if(!IsConnected()) { Comment("Not connected to broker"); return(0);}
//----Declare Variables----------------------------------------------+
    double     OrderSize;
    string     sSymbol = Symbol();
    string     sOrderComment = "TSS BUY";
    int        iMsgBoxResponse = 0;
    double     iTicket1 = 0;
    double     iTicket2 = 0;
//----Calculate order lots based on stop loss size---------------------+
     OrderSize = Lots(sSymbol, dMaxRisk, dDecreaseFactor); 
     iSlippage = iSlippage * PipFactor;//Slippage is passed as points 
    //OrderSize = Lots(sSymbol, dMaxRisk, dDecreaseFactor, dSLPoints, PipFactor);  
    if(Debug==true) Print("OrderSize = " + DoubleToStr(OrderSize,2) + " lots");
    if(Debug==true) Print("Slippage = ",iSlippage, " pips");
//----Display Message confirming order---------------------+    
    iMsgBoxResponse = MessageBox("Buy " + sSymbol + " at " + DoubleToStr(Ask,Digits), 
                     "Confirm Operation", MB_YESNO|MB_ICONQUESTION); 
                     
    if(iMsgBoxResponse==7) return(0);                 


//----Send two orders, one TP, one to ride until exit by MA------------+
    iTicket1 = OrderSend2(sSymbol, OP_BUY, OrderSize, Ask, iSlippage, 0, 0, 
              sOrderComment, iMagicNumber, NULL, CLR_DEF);
    OrderError();
    RefreshRates();
    iTicket2 = OrderSend2(sSymbol, OP_BUY, OrderSize, Ask, iSlippage, 0, 0, 
              sOrderComment, iMagicNumber, NULL, CLR_DEF);  
    OrderError(); 
}
//+------------------------------------------------------------------+

int FractionalPipCheck(int iDigits) {
   
   int PipFactor = 1;
   if (iDigits==0) iDigits = Digits;
   if (iDigits == 3 || iDigits == 5) PipFactor = 10;
   return(PipFactor);
   
}
Reason: