2 registered members (AndrewAMD, ozgur),
1,415
guests, and 7
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
MT4 Indicator Conversion
#437779
02/26/14 02:58
02/26/14 02:58
|
Joined: Feb 2014
Posts: 11
Mandark
OP
Newbie
|
OP
Newbie
Joined: Feb 2014
Posts: 11
|
Greetings, I've been playing around with converting an indicator popular on Steve Hopwoods and other sites, TMA_CG. Essentially using TMA bands + and - some Band deviation as a building block for the EA. Here is the link to the strategy and indicator: http://www.stevehopwoodforex.com/phpBB3/viewtopic.php?f=5&t=3372I'm running into some confusing times converting arrays from MT4 into series in Zorro. Here is the offending code:
void calculateTma(int limit)
{
int i,j,k;
double FullLength = 2.0*HalfLength+1.0;
for (i=limit; i>=0; i--)
{
double sum = (HalfLength+1)*iMA(NULL,0,1,0,MODE_SMA,Price,i);
double sumw = (HalfLength+1);
for(j=1, k=HalfLength; j<=HalfLength; j++, k--)
{
sum += k*iMA(NULL,0,1,0,MODE_SMA,Price,i+j);
sumw += k;
if (j<=i)
{
sum += k*iMA(NULL,0,1,0,MODE_SMA,Price,i-j);
sumw += k;
}
}
tmBuffer[i] = sum/sumw;
double diff = iMA(NULL,0,1,0,MODE_SMA,Price,i)-tmBuffer[i];
if (i> (Bars-HalfLength-1)) continue;
if (i==(Bars-HalfLength-1))
{
upBuffer[i] = tmBuffer[i];
dnBuffer[i] = tmBuffer[i];
if (diff>=0)
{
wuBuffer[i] = MathPow(diff,2);
wdBuffer[i] = 0;
}
else
{
wdBuffer[i] = MathPow(diff,2);
wuBuffer[i] = 0;
}
continue;
}
if(diff>=0)
{
wuBuffer[i] = (wuBuffer[i+1]*(FullLength-1)+MathPow(diff,2))/FullLength;
wdBuffer[i] = wdBuffer[i+1]*(FullLength-1)/FullLength;
}
else
{
wdBuffer[i] = (wdBuffer[i+1]*(FullLength-1)+MathPow(diff,2))/FullLength;
wuBuffer[i] = wuBuffer[i+1]*(FullLength-1)/FullLength;
}
upBuffer[i] = tmBuffer[i] + BandsDeviations*MathSqrt(wuBuffer[i]);
dnBuffer[i] = tmBuffer[i] - BandsDeviations*MathSqrt(wdBuffer[i]);
}
}
I've attempted to convert this code and I get a nice crash on Zorro My problem is that I get confused on when to use a Zorro series as a whole, just use the last bar of it with [0], or when I should actually be performing operations in a for loop... Also, how in the world do I represent the i+j portion of the above code:
iMA(NULL,0,1,0,MODE_SMA,Price,i+j);
Print statements help but haven't been sure-fire. Appreciate any thoughts.
Last edited by Mandark; 02/27/14 01:10. Reason: Added full function code for comparison
|
|
|
Re: MT4 Indicator Conversion
[Re: Mandark]
#437827
02/27/14 01:07
02/27/14 01:07
|
Joined: Feb 2014
Posts: 11
Mandark
OP
Newbie
|
OP
Newbie
Joined: Feb 2014
Posts: 11
|
Had some time to digest... Is this close?
BarPeriod = 240;
int HalfLength = 56;
double BandsDeviations = 2.5;
double FullLength = 2.0*HalfLength+1.0;
vars Price = series(price());
vars Trimavar = series(Trima(Price,5));
var upper = Trimavar[0]+BandsDeviations*sqrt(((FullLength-1)/FullLength)*pow(SMA(Price,1)-Trimavar[0],2));
var lower = Trimavar[0]-BandsDeviations*sqrt(((FullLength-1)/FullLength)*pow(SMA(Price,1)-Trimavar[0],2));
plot("Trimavar1",Trimavar[0],0,GREEN);
plot("upper1",upper,BAND1,RED);
plot("lower1",lower,BAND2,RED);
Key questions: -How to calculate the upper and lower bands from the Trima. Right now I am not so sure I have it. -What to use in the Trima Period variable, the MT4 doesn't look at the period in the calculation. -While i believe that the previous C code could compile with a few changes, I think it doesn't translate well due to the array handling differences between the platforms. Prefer to stick to series. -Does the Trima function actually emulate the MT4 code. Looking at the source code, i'm not so sure. Asking these questions has been a learning process, sometimes asking the right question is the hard part!
|
|
|
|