I've sent this question to support but I thought asking it here may get me an answer quicker or maybe some different suggestions.
I'm creating a TMA indicator and am trying to store the previous periods SMA values in an array type structure to calculate the final TMA line. Creating and adding values to the vector seems to work fine, but when I go to retrieve values with .at(i) FT errors out and asks me if I'd like to continue/abort...
My implementation is as below. I've also tried int as the dataType of the loops counter. I see there's an undocumented GetMA function which may work out as an alternative but I'm not sure how to use it in C++, besides storing the values has to be quicker than calculating them each and every period.
Code: Select all
#include <windows.h>
#include "IndicatorInterfaceUnit.h"
#include "TechnicalFunctions.h"
#include <vector>
using std::vector;
... Calculate () {
if (Bars() >= Len) {
for (i = 0; i < (Len); i++) {
totalClosePrice = totalClosePrice + Close(i);
}
//add SMA to the vector Arr
arr.push_back(totalClosePrice / Periods);
}
if (Bars() >= first) {
//get TMA of period.
//int x = 0;
double totalSMAPrice = 0;
for (std::vector<double>::size_type x = 0; x < Len; x++) {
//readSMA from the Vector Array
totalSMAPrice = totalSMAPrice + arr.at(x);
}
TMABuffer[index] = totalSMAPrice / Periods;
}
}
I'm just picking up C++ so this may be due to a misunderstanding of how the language works. Any suggestions or advice would be awesome.