Done, but not quite the way set out above...
I have 2 functions called "void tma_centred_value". One takes a look-back parameter, and is called during init, the other doesn't/isn't.
Here's the code to find the crossovers (slightly modified from Pips400's original code (so all errors are mine, I tell you! All mine! Ahahahahahaaaa!))...
Code: Select all
void tma_centred_value (int lookback)
{
x = 0;
y = 0;
samples = 0;
for (int z = 0; z <= lookback; z++)
{
if ( iCustom(NULL, CTF, "TMAcentered", 5, 0, z) < iCustom(NULL, CTF, "TMAcentered", 10, 0, z) )
{
direction = "below";
while ( iCustom(NULL, CTF, "TMAcentered", 5, 0, z) < iCustom(NULL, CTF, "TMAcentered", 10, 0, z) )
{
x++;
z++;
}
while ( iCustom(NULL, CTF, "TMAcentered", 5, 0, z + y) > iCustom(NULL, CTF, "TMAcentered", 10, 0, z + y) )
{
y++;
}
GetHurstInfo();
samples++;
if (samples == 14) break;
}
else
{
direction = "above";
while ( iCustom(NULL, CTF, "TMAcentered", 5, 0, z) > iCustom(NULL, CTF, "TMAcentered", 10, 0, z) )
{
x++;
z++;
}
while ( iCustom(NULL, CTF, "TMAcentered", 5, 0, z + y) < iCustom(NULL, CTF, "TMAcentered", 10, 0, z + y) )
{
y++;
}
GetHurstInfo();
samples++;
if (samples == 14) break;
}
}
return;
} // End void tma_centred_value ()
...and here's the code to get the extensions (again, modified version of Pips400's code)
Code: Select all
void GetHurstInfo()
{
datetime HPTime = 0; // Bar time of Highest High.
datetime LPTime = 0; // Bar time of Lowest Low.
bool UpdateAverage = false;
if (direction == "above")
{
LowPoint[TFCount] = iLow(NULL, CTF, iLowest(NULL, CTF, MODE_LOW, y, x)); // get price at lowest point of swing
LPTime = iTime(NULL, CTF, iLowest(NULL, CTF, MODE_LOW, y, x)); // get time of swing low
if (LPTime > LowPointTime[TFCount])
{
LowPointTime[TFCount] = LPTime;
UpdateAverage = true;
}
}
if (direction == "below")
{
HighPoint[TFCount] = iHigh (NULL, CTF, iHighest(NULL, CTF, MODE_HIGH, y, x)); // get price at highest point of swing
HPTime = iTime(NULL, CTF, iHighest(NULL, CTF, MODE_HIGH, y, x)); // get time of swing high
if (HPTime > HighPointTime[TFCount])
{
HighPointTime[TFCount] = HPTime;
UpdateAverage = true;
}
}
//Calculation of crossover value
double a,b,c,d;
a = iCustom (NULL, CTF, "TMAcentered", 5, 0, x - 1);
b = iCustom (NULL, CTF, "TMAcentered", 10, 0, x - 1);
c = iCustom (NULL, CTF, "TMAcentered", 5, 0, x);
d = iCustom (NULL, CTF, "TMAcentered", 10, 0, x);
CrossOverValue[TFCount] = NormalizeDouble (((((a+b)/2) + ((c+d)/2))/2), Digits); // get value at crossover
CrossOverTime1[TFCount] = iTime(NULL,CTF,x);
CrossOverTime2[TFCount] = iTime(NULL,CTF,x+y);
if (direction == "below")
{
HurstExtension[TFCount] = MathAbs(CrossOverValue[TFCount] - HighPoint[TFCount]);
}
if (direction == "above")
{
HurstExtension[TFCount] = MathAbs(CrossOverValue[TFCount] - LowPoint[TFCount]);
}
//Alert(TimeFrame2String(CTF), "Hurst = ", DoubleToString((HurstExtension[TFCount] * factor), 2));
if (!(ED)) // ED = Entry Detection
{
MATally += (HurstExtension[TFCount] * factor);
AvgExt[TFCount] = (MATally / 14);
gvs(cat(esp, "AvgExt"), AvgExt[TFCount]); // Set a GlobalVariable (only used for monitoring).
}
else if (UpdateAverage)
{
MATally = AvgExt[TFCount];
AvgExt[TFCount] = (MATally / 13) + (HurstExtension[TFCount] * factor);
gvs(cat(esp, "AvgExt"), AvgExt[TFCount]); // To be removed before EA release.
}
} // End void GetHurstInfo()
So now I can crunch the numbers required for trade management prior to entering a trade by using the average extension, and re-crunch them after a new crossover
I hope the code's right, and can be of some use to us all.
Have fun!
Radar =8^)