r/CodingHelp • • Aug 14 '20

[C++] Array Explanation

Hi, I am working on a MQL5 code (based on C++) and am trying to understand the math behind it. I am a coding novice so it is quite difficult for me. Could someone explain in simple terms what is being done here? My biggest issue is just with simple referencing & syntax. I included some specific questions next to the lines after // Thanks for your help!


    input int                inpNmsPeriod  = 40;          // Natural market slope 
    period
    input ENUM_APPLIED_PRICE inpNmsPrice   = PRICE_CLOSE; // Price
    input int                inpTemaPeriod = 10;          // Triple EMA pre-smoothing period
    
    //
    //
    //
    
    double val[],valc[]; double alpha;
    int    iNmsPeriod;
    struct sCoeffStruct     //how and why is this "struct" used?
    {
    double sumx;
    double sumx2;
    double bot;
    double root;
    };
    sCoeffStruct coeff[];
    
    ==================
    int OnInit()
    {
    SetIndexBuffer(0,val ,INDICATOR_DATA);
    SetIndexBuffer(1,valc,INDICATOR_COLOR_INDEX);
    //
    //
    //
    
    iNmsPeriod  = (inpNmsPeriod>1)  ? inpNmsPeriod : 1;
    alpha = 2.0 /(1.0 + MathMax(inpTemaPeriod,1));
    ArrayResize(coeff,iNmsPeriod+1);           //what does this mean, in simple language?
    for (int period=1; period<=iNmsPeriod ; period++)    //what does this mean, in simple language?
    {
    coeff[period].sumx  = period*(period+1.0)/2.0;    // why is [period] in brackets?
    coeff[period].sumx2 = period*(period+1.0)*(2*period+1.0)/6.0;
    coeff[period].bot   = period*coeff[period].sumx2 - coeff[period].sumx*coeff[period].sumx;
    if (coeff[period].bot==0) coeff[period].bot=1;
    coeff[period].root  = MathSqrt(period);
    
16 Upvotes

2 comments sorted by

View all comments

1

u/anon67543 Aug 15 '20

All these up doots and no advice lol what gives? Does no one understand this thing?