Hi there,
I would like to create my own calculated index with Norgate data and save it as a composite. The index should logically only be calculated for the current members. This works without problems with data from another provider.
I am using the following code ...
procedure CreateIndex(lNorgateData, sNorgateIndexName, sCompositName)
{
wlnum = GetOption( "FilterIncludeWatchlist" );
List = CategoryGetSymbols( categoryWatchlist, wlnum );
IndexCount = 0;
IndexClose = 0;
//IndexHigh = 0;
//IndexLow = 0;
//IndexOpen = 0;
//IndexVol = 0;
for (f = 0; ( Symbol = StrExtract(List, f ) ) != ""; f++)
{
SetForeign (symbol);
if (lNorgateData)
{
inIndexNorgate = NorgateIndexConstituentTimeSeries(sNorgateIndexName, Symbol);
IndexClose += IIf(Nz(inIndexNorgate),Nz(Close), 0);
//IndexHigh += IIf(Nz(inIndexNorgate),Nz(High), 0);
//IndexLow += IIf(Nz(inIndexNorgate),Nz(Low), 0);
//IndexOpen += IIf(Nz(inIndexNorgate),Nz(Open), 0);
//IndexVol += IIf(Nz(inIndexNorgate),Nz(Volume), 0);
IndexCount += IIf(Nz(inIndexNorgate), 1, 0);
}
else
{
IndexClose += Nz(Close);
//IndexHigh += Nz(High);
//IndexLow += Nz(Low);
//IndexOpen += Nz(Open);
//IndexVol += Nz(Volume);
IndexCount += IIf(Nz(Close) == 0, 0, 1);
}
RestorePriceArrays();
}
AddToComposite(IndexClose / IndexCount,sCompositName,"x", 1|2|8|32|64|128);
//AddToComposite(IndexCount,sCompositName,"X", 1|2|8|32|64|128); // !!!!! Test !!!!!!
//AddToComposite(IndexClose / IndexCount,sCompositName,"C", 1|2|8|32|64|128);
//AddToComposite(IndexHigh / IndexCount,sCompositName,"H", 1|2|8|32|64|128);
//AddToComposite(IndexLow / IndexCount,sCompositName,"L", 1|2|8|32|64|128);
//AddToComposite(IndexOpen / IndexCount,sCompositName,"O", 1|2|8|32|64|128);
//AddToComposite(IndexVol / IndexCount,sCompositName,"V", 1|2|8|32|64|128);
}
I get the following result
IndexCount works correctly ... I get the following result ...
I've tried everything. I don't know what to do next. Maybe someone can help me. Thanks in advance.