I have definied the symbol as below
string [] symbol = new string[] { "V","AAPL","MA","IBM","MSFT"};
Add the symbol in as MultiInstrument in State.Configure
for (int i = 0; i < symbol.Length; ++i)
{
AddDataSeries(symbol[i], Data.BarsPeriodType.Day, 1, Data.MarketDataType.Last);
}
In OnBarUpdate, I would like to calculate the Relative Strength Ratio
MySeries[0] = new []{
2*Closes[1][0] / Closes[1][63] +Closes[1][0] / Closes[1][126]+Closes[1][0] / Closes[1][189]+Closes[1][0] / Closes[1][252] ,
2*Closes[2][0] / Closes[2][63] +Closes[2][0] / Closes[2][126]+Closes[2][0] / Closes[2][189]+Closes[2][0] / Closes[2][252] ,
2*Closes[3][0] / Closes[3][63] +Closes[3][0] / Closes[3][126]+Closes[3][0] / Closes[3][189]+Closes[3][0] / Closes[3][252] ,
2*Closes[4][0] / Closes[4][63] +Closes[4][0] / Closes[4][126]+Closes[4][0] / Closes[4][189]+Closes[4][0] / Closes[4][252] ,
2*Closes[5][0] / Closes[5][63] +Closes[5][0] / Closes[5][126]+Closes[5][0] / Closes[5][189]+Closes[5][0] / Closes[5][252]
};
After Calculate the Relative Strength Ratio, I would like to sort the MySeries[0] array in every bar and hence the MyStockName.
for (int i = 1; i < n; ++i) {
double key = MySeries[0][i];
string intkey = MyStockName[0][i];
int j = i - 1;
// Move elements of arr[0..i-1],
// that are greater than key,
// to one position ahead of
// their current position
while (j >= 0 && MySeries[0][j] < key) {
MySeries[0][j + 1] = MySeries[0][j];
MyStockName[0][j + 1] = MyStockName[0][j];
j = j - 1;
}
MySeries[0][j + 1] = key;
MyStockName[0][j + 1] = intkey;
}
But I find the symbol and MyStockName value keep changing. The most weird is the symbol array, i didn't do anything about it,just assigned the value to MyStockName, When I print symbol value, the position is kept changing.
for (int i = 0; i < n; ++i)
{
// Print(MyStockName[0][i] );
Print(symbol[i] );
}
Thanks.
----------
The printed result:
6/2/2021 5:00:00
MSFT
MA
IBM
AAPL
V
9/2/2021 5:00:00
MA
V
IBM
MSFT
AAPL
10/2/2021 5:00:00
V
AAPL
IBM
MA
MSFT
11/2/2021 5:00:00
AAPL
MSFT
IBM
V
MA
12/2/2021 5:00:00
MSFT
MA
IBM
AAPL
V

Comment