diff --git a/samples/sources/processors/atr/AtrProcessor.cpp b/samples/sources/processors/atr/AtrProcessor.cpp index a11191d..9cb2b2d 100644 --- a/samples/sources/processors/atr/AtrProcessor.cpp +++ b/samples/sources/processors/atr/AtrProcessor.cpp @@ -34,23 +34,27 @@ TaskArray AtrProcessor::Evaluate( for(size_t id=0; id < symbolsCount; ++id) { size_t j = id * nfields + 1; // add 1 to skip first column timestamp + int numColumns = dataRef.ohlcvRecord->num_columns(); //std::iota(std::begin(colIds), std::end(colIds), j); - dataRef.lock.Lock(); - auto highColumn = dataRef.ohlcvRecord->column(j+field+1); - auto lowColumn = dataRef.ohlcvRecord->column(j+field+2); - auto closeColumn = dataRef.ohlcvRecord->column(j+field+3); - dataRef.lock.Unlock(); - if(highColumn && lowColumn && closeColumn && outdata) + if((j+field) < static_cast(numColumns)) { - const double* highs = castTableColumn(highColumn); - const double* lows = castTableColumn(lowColumn); - const double* closes = castTableColumn(closeColumn); - std::vector fieldsValues = {highs,lows,closes}; - - bool result = AverageTrueRange( - id, fieldsValues, numSamples, aSize, outdata, winSize, field, nfields, - &errorVal, atrCache.prevAtrs.data(), atrCache.prevCloses.data(), normalized, scale); - counter += (int)result; + dataRef.lock.Lock(); + auto highColumn = dataRef.ohlcvRecord->column(j+field+1); + auto lowColumn = dataRef.ohlcvRecord->column(j+field+2); + auto closeColumn = dataRef.ohlcvRecord->column(j+field+3); + dataRef.lock.Unlock(); + if(highColumn && lowColumn && closeColumn && outdata) + { + const double* highs = castTableColumn(highColumn); + const double* lows = castTableColumn(lowColumn); + const double* closes = castTableColumn(closeColumn); + std::vector fieldsValues = {highs,lows,closes}; + + bool result = AverageTrueRange( + id, fieldsValues, numSamples, aSize, outdata, winSize, field, nfields, + &errorVal, atrCache.prevAtrs.data(), atrCache.prevCloses.data(), normalized, scale); + counter += (int)result; + } } } } diff --git a/samples/sources/processors/ema/EmaProcessor.cpp b/samples/sources/processors/ema/EmaProcessor.cpp index 8dffb24..59507cc 100644 --- a/samples/sources/processors/ema/EmaProcessor.cpp +++ b/samples/sources/processors/ema/EmaProcessor.cpp @@ -34,17 +34,21 @@ TaskArray EmaProcessor::Evaluate( for(size_t id=0; id < symbolsCount; ++id) { size_t j = id * nfields + 1; // add 1 to skip first column timestamp + int numColumns = dataRef.ohlcvRecord->num_columns(); //std::iota(std::begin(colIds), std::end(colIds), j); - dataRef.lock.Lock(); - auto fieldColumn = dataRef.ohlcvRecord->column(j+field); - dataRef.lock.Unlock(); - if(fieldColumn && outdata) + if((j+field) < static_cast(numColumns)) { - const double* fieldValues = castTableColumn(fieldColumn); - bool result = ExpMovingAverage( - id, fieldValues, numSamples, aSize, outdata, winSize, field, - nfields, &errorVal, emaCache.values.data(), normalized, scale); - counter += (int)result; + dataRef.lock.Lock(); + auto fieldColumn = dataRef.ohlcvRecord->column(j+field); + dataRef.lock.Unlock(); + if(fieldColumn && outdata) + { + const double* fieldValues = castTableColumn(fieldColumn); + bool result = ExpMovingAverage( + id, fieldValues, numSamples, aSize, outdata, winSize, field, + nfields, &errorVal, emaCache.values.data(), normalized, scale); + counter += (int)result; + } } } } diff --git a/samples/sources/processors/roc/RocProcessor.cpp b/samples/sources/processors/roc/RocProcessor.cpp index c857a1f..2fc6405 100644 --- a/samples/sources/processors/roc/RocProcessor.cpp +++ b/samples/sources/processors/roc/RocProcessor.cpp @@ -37,17 +37,21 @@ TaskArray RocProcessor::Evaluate( for(size_t id=0; id < symbolsCount; ++id) { size_t j = id * nfields + 1; // add 1 to skip first column timestamp + int numColumns = dataRef.ohlcvRecord->num_columns(); //std::iota(std::begin(colIds), std::end(colIds), j); - dataRef.lock.Lock(); - auto fieldColumn = dataRef.ohlcvRecord->column(j+field); - dataRef.lock.Unlock(); - if(fieldColumn && outdata) + if((j+field) < static_cast(numColumns)) { - const double* fieldValues = castTableColumn(fieldColumn); - bool result = RateOfChange( - id, fieldValues, numSamples, aSize, outdata, winSize, - field, nfields, &errorVal, rocCache.values, scale); - counter += (int)result; + dataRef.lock.Lock(); + auto fieldColumn = dataRef.ohlcvRecord->column(j+field); + dataRef.lock.Unlock(); + if(fieldColumn && outdata) + { + const double* fieldValues = castTableColumn(fieldColumn); + bool result = RateOfChange( + id, fieldValues, numSamples, aSize, outdata, winSize, + field, nfields, &errorVal, rocCache.values, scale); + counter += (int)result; + } } } } diff --git a/samples/sources/processors/rsi/RsiProcessor.cpp b/samples/sources/processors/rsi/RsiProcessor.cpp index 5d9520a..58ae7cf 100644 --- a/samples/sources/processors/rsi/RsiProcessor.cpp +++ b/samples/sources/processors/rsi/RsiProcessor.cpp @@ -33,18 +33,22 @@ TaskArray RsiProcessor::Evaluate( for(size_t id=0; id < symbolsCount; ++id) { size_t j = id * nfields + 1; // add 1 to skip first column timestamp + int numColumns = dataRef.ohlcvRecord->num_columns(); //std::iota(std::begin(colIds), std::end(colIds), j); - dataRef.lock.Lock(); - auto fieldColumn = dataRef.ohlcvRecord->column(j+field); - dataRef.lock.Unlock(); - if(fieldColumn && outdata) + if((j+field) < static_cast(numColumns)) { - const double* fieldValues = castTableColumn(fieldColumn); - bool result = RelativeStrengthIndex( - id, fieldValues, numSamples, aSize, outdata, winSize, field, - nfields, &errorVal, caches.upAvgs.data(), caches.downAvgs.data(), - caches.prevRsis.data(), caches.prevPrices.data(), scale); - counter += (int)result; + dataRef.lock.Lock(); + auto fieldColumn = dataRef.ohlcvRecord->column(j+field); + dataRef.lock.Unlock(); + if(fieldColumn && outdata) + { + const double* fieldValues = castTableColumn(fieldColumn); + bool result = RelativeStrengthIndex( + id, fieldValues, numSamples, aSize, outdata, winSize, field, + nfields, &errorVal, caches.upAvgs.data(), caches.downAvgs.data(), + caches.prevRsis.data(), caches.prevPrices.data(), scale); + counter += (int)result; + } } } }