Array randomly losing data somehow?

To add comments, please log in or register
classyguy28
139
classyguy28  

Hi all, 

I don't have the greatest grasp on memory allocation so I'm wondering if this issue has something to do with that. Here is the problem I'm having:

I start with 3 user input strings:

input string currencyTickersString = "AUDCAD,AUDCHF,AUDJPY,AUDNZD,AUDUSD,CADCHF,CADJPY,CHFJPY,EURAUD,EURCAD,EURCHF,EURCZK,EURDKK,EURGBP,EURHKD,EURHUF,EURJPY,EURMXN,EURNOK,EURNZD,EURPLN,EURRUB,EURSEK,EURSGD,EURTRY,EURUSD,EURZAR,GBPAUD,GBPCAD,GBPCHF,GBPCZK,GBPDKK,GBPHKD,GBPHUF,GBPJPY,GBPMXN,GBPNOK,GBPNZD,GBPPLN,GBPSEK,GBPSGD,GBPTRY,GBPUSD,GBPZAR,NOKSEK,NZDCAD,NZDCHF,NZDJPY,NZDSGD,NZDUSD,USDCAD,USDCHF,USDCNH,USDCZK,USDDKK,USDHKD,USDHUF,USDJPY,USDMXN,USDNOK,USDPLN,USDRUB,USDSEK,USDSGD,USDTRY,USDZAR";
input string commodityTickersString = "XAGUSD,XAUUSD,UKOUSD,USOUSD,XNGUSD";
input string indexTickersString = "100GBP,200AUD,225JPY,D30EUR,E35EUR,E50EUR,F40EUR,H33HKD,NASUSD,SPXUSD,U30USD"; 
string currencyTickers[66];
string commodityTickers[5];
string indexTickers[11];


Then in the OnInit function I convert those strings to arrays to make it easier to loop over them later on:


for(int i=0;i<66;i++){
   currencyTickers[i] = StringSubstr(currencyTickersString,i*7,6);
   Print("-->Currency Pair: ", currencyTickers[i]);
}
for(int i=0;i<5;i++){
   commodityTickers[i] = StringSubstr(commodityTickersString,i*7,6);
   Print("-->Commodity Pair: ", commodityTickers[i]);
}
for(int i=0;i<11;i++){
   indexTickers[i] = StringSubstr(indexTickersString,i*7,6);
   Print("--> Indices Pair: ", indexTickers[i]);
}

For the two smaller arrays of commodityTickers[] and indexTickers[] everything always works fine and I have no issues, but for the larger array of currencyTickers[] everything will work completely fine for several runs and then all of a sudden the program will get run again and none of the info will be in the array and it's printing every item out as blank. I have another section in the code where I have a 300 item array that never has any issues and that is setup exactly the same way so I am totally at a loss for what is going on.

I have been stumbling over this for hours and cannot figure it out.

Any help would be greatly appreciated.

Lorentzos Roussos
29028
Lorentzos Roussos  

First , print out the length of the feed string on init .

//add this on init
ArrayFree(currencyTickers);
int str_len=StringLen(currencyTickersString);
Print("Loaded Length = "+IntegerToString(str_len));
if(str_len>0)
{
//Separate symbols 
string sep=",";
ushort sep_u=StringGetCharacter(sep,0);
int splits=StringSplit(currencyTickersString,sep_u,currencyTickers);
}
William Roeder
18310
William Roeder  
classyguy28:

Then in the OnInit function I convert those strings to arrays to make it easier to loop over them later on:

for(int i=0;i<66;i++){
   currencyTickers[i] = StringSubstr(currencyTickersString,i*7,6);
   Print("-->Currency Pair: ", currencyTickers[i]);
}
for(int i=0;i<5;i++){
   commodityTickers[i] = StringSubstr(commodityTickersString,i*7,6);
   Print("-->Commodity Pair: ", commodityTickers[i]);
}
for(int i=0;i<11;i++){
   indexTickers[i] = StringSubstr(indexTickersString,i*7,6);
   Print("--> Indices Pair: ", indexTickers[i]);
}


everything will work completely fine for several runs and then all of a sudden

  1. Simplify your code
    StringSplit(currencyTickersString,  ',', currencyTickers);
    StringSplit(commodityTickersString, ',', commodityTickers);
    StringSplit(indexTickersString,     ',', indexTickers);
    
  2. Do you really expect an answer when your problem is obviously not in the code you posted.
To add comments, please log in or register