What's wrong with my code? Who can help me,Please?

 
/+------------------------------------------------------------------+
//|                                                         test.mq5 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
        string TradeSymbol[];
        ArrayResize(TradeSymbol,7);
         if(AccountInfoString(ACCOUNT_COMPANY) == "RoboForex LP")
           TradeSymbol[7] = {"EURUSD.e","GBPUSD.e","EURGBP.e","USDJPY.e","EURJPY.e","XAUUSD.e","XAGUSD.e"};
           else
             TradeSymbol[7] = {"EURUSD","GBPUSD","EURGBP","USDJPY","EURJPY","XAUUSD","XAGUSD"};
 
  }
//+------------------------------------------------------------------+

自动交易和策略测试
自动交易和策略测试
  • www.mql5.com
MQL5:MetaTrader 5客户端内置的交易策略语言。语言允许编写您自己的自动交易系统,技术指标,脚本和函数程序库
 
bcsunwww:

If your array has 7 items, they are indexed from 0 to 6. You can't use index [7].

You can't initialize all items at once with a dynamic array. You have to initialize each one individually.

 

Try this one:

void OnStart()
  {
//---
        string TradeSymbol[7] = {"EURUSD","GBPUSD","EURGBP","USDJPY","EURJPY","XAUUSD","XAGUSD"};
        
         if(AccountInfoString(ACCOUNT_COMPANY) == "RoboForex LP")
            {
            for(int i=ArraySize(TradeSymbol)-1;i>=0;i--)
               {
               TradeSymbol[i]+=".";
               }
            }

 
  }
 
       string TradeSymbol[];
        ArrayResize(TradeSymbol,7);
         if(AccountInfoString(ACCOUNT_COMPANY) == "RoboForex LP")
           {TradeSymbol[0] = "EURUSD.e";
           TradeSymbol[1] = "GBPUSD.e";
           ...
           ...
           TradeSymbol[6] = "XAGUSD.e";}
         else
           {TradeSymbol[0] = "EURUSD";
           TradeSymbol[1] = "GBPUSD";
           ...
           ...
           TradeSymbol[6] = "XAGUSD";}
 //----

You can not use array initialization in the process

 

(updated!!!) 

 
belido:
You can not use array initialization in the process

If your array has 7 items, they are indexed from 0 to 6. You can't use index [7].

You can't initialize all items at once with a dynamic array. You have to initialize each one individually.


 
Thank you all ,and belido's code solve my problem directly.
 
The use of arrays in your code is only useful if you want to detect whether trading symbol is to account "RoboForex LP" or "Standard".
Like this example:

void OnStart()
  {
//---
     string symbol = _Symbol;
     string account;
     string account_suf = "RoboForex LP";
     string account_std = "Standard";
     string pairs[] = {"EURUSD.e","GBPUSD.e","EURGBP.e","USDJPY.e","EURJPY.e","XAUUSD.e","XAGUSD.e"};
     string suffix = ".e";
     //--
     for(int x=0; x<7; x++)
        {
          if((pairs[x] == symbol) && (StringSubstr(pairs[x],6,2) == suffix))
            {
              account=account_suf;
            }
          else
            {
              account=account_std;
            }
        }
  }
 
3rjfx:
The use of arrays in your code is only useful if you want to detect whether trading symbol is to account "RoboForex LP" or "Standard".
Like this example:

void OnStart()
  {
//---
     string symbol = _Symbol;
     string account;
     string account_suf = "RoboForex LP";
     string account_std = "Standard";
     string pairs[] = {"EURUSD.e","GBPUSD.e","EURGBP.e","USDJPY.e","EURJPY.e","XAUUSD.e","XAGUSD.e"};
     string suffix = ".e";
     //--
     for(int x=0; x<7; x++)
        {
          if((pairs[x] == symbol) && (StringSubstr(pairs[x],6,2) == suffix))
            {
              account=account_suf;
            }
          else
            {
              account=account_std;
            }
        }
  }
Your code is excellent.
 
Wei Sun:
Your code is excellent.
Ok
Reason: