When does it make sense to keep part of the robot code in an indicator? - page 14

 
Integer:

In essence, let's transfer EMA calculation code to Expert Advisor.


Having rummaged through the archives, here's one of my ancient choices. Took it out of the Expert Advisor.

int GetSignal (int nMax, int shift, double& prevVals[])
//  prevVals[3] - [0] требуется для быстрого расчета SMA.
//                [1] пред. порог перехода
//                [2] пред. пред. порог перехода
{
    int j, k, pos;
    double currMA, sum;

    ///////////////////////////////////////////////////////
    //  Restore 
    if (prevVals[0] < 0.1) {

        pos = nMax;
        sum = 0;
        for(k = 0; k < paramMAperiod; k++, pos--) {
            sum += vPrice(paramMAprice, pos);
        }
        prevVals[0] = sum/paramMAperiod;

        for ( ; shift < pos; pos--) {
            currMA = (vPrice(paramMAprice, pos) + (paramMAperiod-1)*prevVals[0])/paramMAperiod;
            prevVals[0] = currMA;

            j = 0.5+MathAbs(prevVals[1]-currMA)/Point;
            if (j >= paramMAporog) {
                prevVals[2] = prevVals[1];
                prevVals[1] = currMA;
            }
        }
    }
    ///////////////////////////////////////////////////////

    pos = shift;
    currMA = (vPrice(paramMAprice, pos) + (paramMAperiod-1)*prevVals[0])/paramMAperiod;
    prevVals[0] = currMA;

    ///////////////////////////////////////////////////////
    pos = 0;
    j = 0.5+MathAbs(prevVals[1]-currMA)/Point;
    if (j >= paramMAporog) {

        if (prevVals[2] > prevVals[1] && prevVals[1] < currMA)
            pos = -1;

        if (prevVals[2] < prevVals[1] && prevVals[1] > currMA)
            pos = 1;

        prevVals[2] = prevVals[1];
        prevVals[1] = currMA;
    }

    if (IsOptimization() == false) {
        string szName = "ArrTest_";
        szName = szName+gObject;
        ObjectCreate(szName, OBJ_ARROW, 0, Time[shift], prevVals[1]);
        ObjectSet   (szName, OBJPROP_ARROWCODE, 159);
        ObjectSet   (szName, OBJPROP_COLOR,     Gold);
        gObject++;
   }
   return(pos);
}

Have I understood you correctly?

 
OneDepo:


Having rummaged through the archives, here's one of my ancient choices. Took it out of an expert.

Did I understand you correctly?


There will be an error after a perforation in connection, the lower the timeframe, the bigger the error.
 
Vinin:
By the way, Dimitri, you have provided an incorrect solution too. I was talking about the Expert Advisor.


I haven't finished all the windows yet, interrupted....

No, no, it's a good example. Why make something artificially complicated? I just don't understand what is "toyish" about my code?

 
Dmitry, I am not interested in the contest at all. I'm interested to know what would be faster of the two variants performed by an ordinary programmer. And for a more or less standard custom indicator and with the same calculation scheme. And your competition may end up with someone "inventing a watertight powder", and it will only indicate that he or she is a good programmer, but not that the EA's calculation is faster (or vice versa).
 
hrenfx:


Haven't finished all the windows yet, interrupted....

No, no, it's a good example. Why make something artificially complicated? I just don't understand, what is the "playfulness" of my code?


Just compare the values of your calculation and the standard EMA. See
 
granit77:
Dmitry, I am not interested in the contest at all. I'm interested to know what would be faster of the two variants performed by an ordinary programmer. And for a more or less standard custom indicator and with the same calculation scheme. And your competition may end up with someone "inventing a watertight powder", and it will only indicate that he or she is a good programmer, but not that the EA's calculation is faster (or vice versa).

As we can see, so far no one has provided a fully correct method for calculating EMA in EAs that is applicable in practice in reality, let alone faster.
 
Vinin:

Just compare the values of your calculation and the standard EMA. You will see

Well, it's not really a pickle, it all depends on where you start. For the same indicator the first bar will be exactly the same. But not to start an unnecessary argument, I will now make the simplest changes.

 
Vinin:

Just compare the values of your calculation with the standard EMA. See

I may have made a mistake with the coefficients, I will check them now, but the principle will not change.
 
Integer:

There will be an error after perforation, the lower the timeframe, the bigger the error.

No, it won't. You can see in the code that the signal calculation process is controlled (only last bar or given nMax bars) by parameter prevVals[0]. If it is 0, we restore the calculation by nMax bars. The value of prevVals[0] is controlled by another code.

But let's not get sidetracked, let's get to the point. There are two options above, which is faster in the tester? So

 

The red one is mine, the blue one above is the one built into the terminal.