help code ELD -->MQL4
Posted: Sun Dec 30, 2012 10:02 am
Hello sir.
sorry for my english I'm French.
I try desperately to translate the code "ELD" to "MQL4" I tried several forums (forexfactory, tsd, mql4forum etc ...) but nobody could you translate so I turn to you because you are the a rare tradeurs a program in "ELD" and "MQL4" so maybe that you can bring me.
I try it myself but I debuted in programming and I do not know MQL4 or ELD so it is very hard for me but when I even try but the results are completely false.
Here is the code "ELD" and my translation "MQL4."
if you have the time could you then tell me how to translate this into "MQL4"
Array_SetMaxIndex(Polynomial, DataSize*(MaxDegree+1)+1) ;---> MQ4 ?
Array_SetMaxIndex(SmoothedTimeSeries, DataSize);---> MQ4 ?
Array_SetMaxIndex(Coefficient, MaxDegree+1) ;---> MQ4 ?
LastBarOnChart=TRUE ---> MQ4 ?
if barnumber = 1 ---> MQ4 ?
Value1 ---> MQ4 ?
Value2 ---> MQ4 ?
so I can try to translate it myself properly because I would not annoy you because I know you are very busy.
thank you for your help.
friendly
cordially
CODE ELD
CODE MQL4 FALSE
sorry for my english I'm French.
I try desperately to translate the code "ELD" to "MQL4" I tried several forums (forexfactory, tsd, mql4forum etc ...) but nobody could you translate so I turn to you because you are the a rare tradeurs a program in "ELD" and "MQL4" so maybe that you can bring me.
I try it myself but I debuted in programming and I do not know MQL4 or ELD so it is very hard for me but when I even try but the results are completely false.
Here is the code "ELD" and my translation "MQL4."
if you have the time could you then tell me how to translate this into "MQL4"
Array_SetMaxIndex(Polynomial, DataSize*(MaxDegree+1)+1) ;---> MQ4 ?
Array_SetMaxIndex(SmoothedTimeSeries, DataSize);---> MQ4 ?
Array_SetMaxIndex(Coefficient, MaxDegree+1) ;---> MQ4 ?
LastBarOnChart=TRUE ---> MQ4 ?
if barnumber = 1 ---> MQ4 ?
Value1 ---> MQ4 ?
Value2 ---> MQ4 ?
so I can try to translate it myself properly because I would not annoy you because I know you are very busy.
thank you for your help.
friendly
cordially
CODE ELD
Code: Select all
Inputs:
TimeSeries((h+l)/2), // The original data to fit, put in whatever you want to look at of whatever time series
//
Width(126), // Length = 2*Width+1, the default gives a fit to one year (252) of daily bars
//
MaxDegree(6), // The degree of the polynomial fit. 0 <= MaxDegree <= 2*Width+1
//
ForwardExtension(10), // The number of bars the fit is to be extended forward in time,
// **you must have this many spaces in: "Format Window/Space to the Right" **
//
ShowLeadingEdge(FALSE), // The leading edge is the rightmost point of every fit in the timeseries
//
ShowPredictedEdge(FALSE), // The predicted edge is the extended from ForwardExtension bars ago
//
//
ShowSmoothedTimeSeries(TRUE), // This shows the entire fit over the interval 2*Width+1 for the last bar
// plus the ForwardExtension predictions
//
LeadingEdgeColor(Blue),
PredictedEdgeColor(Magenta),
SmoothedTimeSeriesColor(Red),
ExtendedTimeSeriesColor(Yellow);
Variables:
LeadingEdge(0),
PredictedEdge(0),
p(0),j(0),
DataSize((2*Width+1) + ForwardExtension);
Arrays:
Polynomial[](0),
Coefficient[](0),
SmoothedTimeSeries[](0);
if barnumber = 1 then begin
//Allocate memory for the arrays. Polynomial is a 2D array
Array_SetMaxIndex(Polynomial, DataSize*(MaxDegree+1)+1) ;
Array_SetMaxIndex(SmoothedTimeSeries, DataSize);
Array_SetMaxIndex(Coefficient, MaxDegree+1) ;
end;
//Now decompose data into the polynomial set and determine the overlap coefficients:
if ShowLeadingEdge=TRUE or ShowPredictedEdge=TRUE or (LastBarOnChart=TRUE and ShowSmoothedTimeSeries=TRUE ) then begin
//Decompose data into the polynomial set and determine the overlap coefficients:
for p = 0 to MaxDegree begin
Coefficient[p] = 0;
for j = -Width to +Width begin
Coefficient[p]= Coefficient[p] + Polynomial[p*DataSize+Width+j]*TimeSeries[Width-j];
end;
end;
//Recompose the original price as the truncated polynomial version - create the smoothed time series, including the
//forward extension
for j = -Width to Width + ForwardExtension begin
SmoothedTimeSeries[Width+j] = 0;
for p = 0 to MaxDegree begin
SmoothedTimeSeries[Width+j] = SmoothedTimeSeries[Width+j] + Coefficient[p]*Polynomial[p*DataSize+Width+j];
end;
end;
//The leading edge is at j = Width
LeadingEdge = SmoothedTimeSeries[Width+Width];
//The predicted edge is at j = Width+ForwardExtension
PredictedEdge = SmoothedTimeSeries[Width+Width+ForwardExtension];
Print(" PredictedEdge =" ,PredictedEdge :1:6 );
end;
//Plotting routines
if ShowLeadingEdge=TRUE and LeadingEdge<>0 then Plot1(LeadingEdge,"LdngEdge",LeadingEdgeColor);
if ShowPredictedEdge=TRUE and PredictedEdge<>0 then Plot2[-ForwardExtension](PredictedEdge,"FwrdEdge",PredictedEdgeColor);
if LastBarOnChart=TRUE and ShowSmoothedTimeSeries=TRUE then begin
for j = -Width to Width begin
plot3[Width-j](SmoothedTimeSeries[Width+j],"Fit",SmoothedTimeSeriesColor);
end;
if ForwardExtension > 0 then begin
for j = 1 to ForwardExtension begin
plot4[-j](SmoothedTimeSeries[Width+Width+j],"Prediction",ExtendedTimeSeriesColor);
end;
end;
end;
//////////////////////////////////////////////////////////////////////////////////////////////////
//
// Create the Orthoginal Legendre Polynomials during the first bar, including ForwardExtension data
//
//////////////////////////////////////////////////////////////////////////////////////////////////
if barnumber = 1 then begin
//The first polynomial is a constant, easy to create
for j = - Width to + Width + ForwardExtension begin
Polynomial[0*DataSize + Width+j] = 1;
end;
//The second polynomial is a line
if MaxDegree>=1 then begin
for j = -Width to +Width + ForwardExtension begin
Polynomial[1*DataSize + Width+j] = j;
end;
end;
//We use the discrete Legendre polynomial recurrence relations to create the rest
if MaxDegree > 1 then begin
for p = 1 to MaxDegree - 1 begin // create the polynomial for degree p+1
for j = -Width to Width + ForwardExtension begin // sum over the interval
Value1 = j*(2*p+1)/(p+1); //discrete Legendre polynomial solution
Value2 = - (p/(p+1))*(2*Width+1+p)*(2*Width+1-p)/4; //discrete Legendre polynomial solution
Polynomial[(p+1)*DataSize+Width+j] //The recurrence relation
= Value1 * Polynomial[p*DataSize+Width+j] + Value2 * Polynomial[(p-1)*DataSize+Width+j];
end;
end;
end;
//Now we have to normalize each polynomial, so that the sum of the square of the polynomial
//over the interval is 1. Instead of doing the calculation however, we apply the pre-determined answer[4]:
for p = 0 to MaxDegree begin
Value1 = Power(2,-2*p)/(2*p+1);
for j = -p to p begin Value1 = Value1 * (2*Width+1+j); end;
if Value1 > 0 then Value1 = 1/squareroot(Value1); //this is the normalization coefficient
for j = -Width to +Width + ForwardExtension begin
Polynomial[p*DataSize+Width+j] = Value1 * Polynomial[p*DataSize+Width+j];
end;
end;
//Done! We now have a orthogonal normalized set of polynomials
end;
CODE MQL4 FALSE
Code: Select all
//+------------------------------------------------------------------+
//| XCAP_POLIPREDICT.mq4 |
//| Copyright 2012, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, MetaQuotes Software Corp."
#property link "http: //www.metaquotes.net"
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
#import "kernel32.dll"
void OutputDebugStringA(string msg);
#import
int Width = 126;
double TimeSeries = 0.00;
int MaxDegree = 6;
int ForwardExtension = 10;
bool ShowLeadingEdge = false;
bool ShowPredictedEdge = FALSE;
bool ShowSmoothedTimeSeries = TRUE;
color LeadingEdgeColor = Blue;
color PredictedEdgeColor = Magenta;
color SmoothedTimeSeriesColor = Red;
color ExtendedTimeSeriesColor = Yellow;
double LeadingEdge;
double PredictedEdge;
int p, j, Value1, Value2;
int DataSize;
double Polynomial[263];
double Coefficient[7];
double SmoothedTimeSeries[];
int init()
{
//---- indicators
DataSize = ((2 * Width + 1) + ForwardExtension);
//ArrayResize(Polynomial,DataSize);
IndicatorBuffers(8);
SetIndexBuffer(0,Polynomial);
SetIndexBuffer(1,Coefficient);
SetIndexBuffer(2,SmoothedTimeSeries);//----
ArrayResize(Polynomial, DataSize*(MaxDegree+1)+1) ;
ArrayResize(SmoothedTimeSeries, DataSize);
ArrayResize(Coefficient, MaxDegree+1) ;
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
//***************************************************
if (ShowLeadingEdge == TRUE || ShowPredictedEdge == TRUE || ShowSmoothedTimeSeries==TRUE )
{
for (p = 0; p <= MaxDegree; p++)
{
Coefficient[p] = 0;
for (j = -Width; j < Width; j++)
{
TimeSeries = (High[Width - j] + Low[Width - j]) / 2;
Coefficient[p] = Coefficient[p] + Polynomial[p * DataSize + Width + j] * TimeSeries;
// Print( " Coefficient[p] = " ,DoubleToStr(Coefficient[p],7));
// Print(" j = ",DoubleToStr(j,2) );
// Log(j,TimeSeries,Coefficient[p],Polynomial[p * DataSize + Width + j]);
}
}
// Print( " TimeSeries = " ,TimeSeries);
// Print( " Coefficient[p] = " ,DoubleToStr(Coefficient[p],7));
// Print( " Polynomial[p * DataSize + Width + j] = " , DoubleToStr(Polynomial[p * DataSize + Width + j],8));
for (j = -Width; j < (Width + ForwardExtension); j++)
{
SmoothedTimeSeries[Width + j] = 0;
for (p = 0; p < MaxDegree; p++)
SmoothedTimeSeries[Width + j] = SmoothedTimeSeries[Width + j] + Coefficient[p] * Polynomial[p * DataSize + Width + j];
LeadingEdge = SmoothedTimeSeries[Width + Width];
PredictedEdge = SmoothedTimeSeries[Width + Width + ForwardExtension];
}
}
Print(" PredictedEdge = ", PredictedEdge);
Print(" LeadingEdge = ", LeadingEdge);
for (j = -Width; j < (Width + ForwardExtension); j++)
Polynomial[0 * DataSize + Width + j] = 1;
if (MaxDegree >= 1)
{
for (j = -Width; j < (Width + ForwardExtension); j++)
Polynomial[1 * DataSize + Width + j] = j;
}
if (MaxDegree > 1)
{
for (p = 1; p == MaxDegree - 1; p++)
{ // create the polynomial for degree p+1
for (j = -Width; j < (Width + ForwardExtension); j++)
{
Value1 = j * (2 * p + 1) / (p + 1); //discrete Legendre polynomial solution
Value2 = -(p / (p + 1)) * (2 * Width + 1 + p) * (2 * Width + 1 - p) / 4; //discrete Legendre polynomial solution
Polynomial[(p + 1) * DataSize + Width + j] = Value1 * Polynomial[p * DataSize + Width + j] + Value2 * Polynomial[(p - 1) * DataSize + Width + j];
}
}
}
for (p = 0; p < MaxDegree; p++)
{
Value1 = MathPow(2, -2 * p) / (2 * p + 1);
for (j = -p; j < p; j++)
{
Value1 = Value1 * (2 * Width + 1 + j);
}
if (Value1 > 0)
Value1 = 1 / MathSqrt(Value1); //this is the normalization coefficient
for (j = -Width; j < (Width + ForwardExtension); j++)
{
Polynomial[p * DataSize + Width + j] = Value1 * Polynomial[p * DataSize + Width + j];
}
}
//}
//****************************
//************************************************
if(Bars==1)
{
for (j = -Width; j < (Width + ForwardExtension); j++)
Polynomial[0 * DataSize + Width + j] = 1;
if (MaxDegree >= 1)
{
for (j = -Width; j < (Width + ForwardExtension); j++)
Polynomial[1 * DataSize + Width + j] = j;
}
if (MaxDegree > 1)
{
for (p = 1; p == MaxDegree - 1; p++)
{ // create the polynomial for degree p+1
for (j = -Width; j < (Width + ForwardExtension); j++)
{
Value1 = j * (2 * p + 1) / (p + 1); //discrete Legendre polynomial solution
Value2 = -(p / (p + 1)) * (2 * Width + 1 + p) * (2 * Width + 1 - p) / 4; //discrete Legendre polynomial solution
Polynomial[(p + 1) * DataSize + Width + j] = Value1 * Polynomial[p * DataSize + Width + j] + Value2 * Polynomial[(p - 1) * DataSize + Width + j];
}
}
}
}
for (p = 0; p < MaxDegree; p++)
{
Value1 = MathPow(2, -2 * p) / (2 * p + 1);
for (j = -p; j < p; j++)
{
Value1 = Value1 * (2 * Width + 1 + j);
}
if (Value1 > 0)
Value1 = 1 / MathSqrt(Value1); //this is the normalization coefficient
for (j = -Width; j < (Width + ForwardExtension); j++)
{
Polynomial[p * DataSize + Width + j] = Value1 * Polynomial[p * DataSize + Width + j];
}
}