Download MetaTrader 5
To add comments, please log in or register
Share your program via Code Base. Gain access to millions of traders!
Wei Sun
698
Wei Sun 2014.06.28 13:20 
/+------------------------------------------------------------------+
//|                                                         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客户端内置的交易策略语言。语言允许编写您自己的自动交易系统,技术指标,脚本和函数程序库
Alain Verleyen
Moderator
28651
Alain Verleyen 2014.06.28 13:35  
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.

Laszlo Tormasi
2385
Laszlo Tormasi 2014.06.28 14:13  

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]+=".";
               }
            }

 
  }
Irwan Adnan
808
Irwan Adnan 2014.06.28 15:06  
       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!!!) 

Rodrigo Malacarne
Moderator
9604
Rodrigo Malacarne 2014.06.28 15:48  
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.


Wei Sun
698
Wei Sun 2014.06.28 21:31  
Thank you all ,and belido's code solve my problem directly.
Roberto Jacobs
45116
Roberto Jacobs 2014.06.30 09:09  
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;
            }
        }
  }
Wei Sun
698
Wei Sun 2014.07.27 13:45  
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.
/
To add comments, please log in or register