工作已完成
![](https://c.mql5.com/i/avatar/avatar_na2.png)
指定
I have three versions of an Entropy indicator, but they have problems and need fixing.
One entropy indicator, after attaching it to the chart, after an hour or two disappears.
The other two entropy indicators stays at zero.
I have attached a picture to show what I mean.
So, they need to be remade from the C Language or recoded.
What is Entropy? "Entropy is a well-known measure of disorder or unavailability of energy in a (closed) system. More entropy generally means less predictability, hence one often tries to minimize it":
Here is the C language program of it:
http://www.foretrade.com/entropy.htm
Definition from http://mathworld.wolfram.com/Entropy.html
The source C code for this indicator which can be compiled with any (free) C compiler:
#include "math.h"
#include "stdlib.h"
__declspec(dllexport) void Entropy (double *price, double *entropy, long int size, long int numbars)
{
double *in, *out, P, G;
long int i,j;
double sumx = 0.0;
double sumx2 = 0.0;
double avgx = 0.0;
double rmsx = 0.0;
in=price;
out=entropy;
for (i=0; i<size; i++)
{
if (i < numbars+1) *out = 3.4e38;
else
{
sumx = sumx2 = avgx = rmsx = 0.0;
for (j=0;j<numbars+1;j++)
{
sumx += log(*(in-j) / *(in-j-1)) ;
sumx2 += log(*(in-j) / *(in-j-1)) * log(*(in-j) / *(in-j-1));
}
if (numbars==0)
{
avgx = *in;
rmsx = 0.0;
}
else
{
avgx = sumx / numbars;
rmsx = sqrt(sumx2/numbars);
}
P = ((avgx/rmsx)+1)/2.0;
G = P * log(1+rmsx) + (1-P) * log(1-rmsx);
*out=G;
}
in++; out++;
}
Here are three failed attempts at making the Entropy indicator attached. They either disappear and show only previous data, or they are stuck at zero while the previous bars display the correct value of entropy.