EMA slowing down testing

How to create strategies and indicators
Message
Author
allan21
Posts: 5
Joined: Mon Oct 08, 2007 4:53 am

EMA slowing down testing

#1 Postby allan21 » Sat Oct 13, 2007 6:30 pm

Hi Terranin,

I have built a strategy where I use the exponential moving average indicator (Ema 62). Here's how I calculate the function:

{-----Calculate EMA---------------------------------------}

function GetEMA(period: integer): double;

var

sum: double;

pr: double;

pos: integer;

begin

pr := 2/63;

pos := Bars -2;

while (pos>=0) do

begin

if (pos = Bars - 2) then sum := close (pos +1) else

sum := ((close(pos) - sum) * pr) + sum;

pos := pos -1;

end;


result := sum;

end;


I have notice that once Bars is > 2035, the testing of my strategy in ForexTester is slowed dramatically.

How can I get over this?

Thanks

User avatar
Terranin
Site Admin
Posts: 833
Joined: Sat Oct 21, 2006 4:39 pm

Re: EMA slowing down testing

#2 Postby Terranin » Sun Oct 14, 2007 10:20 am

allan21 wrote:Hi Terranin,

I have built a strategy where I use the exponential moving average indicator (Ema 62). Here's how I calculate the function:

{-----Calculate EMA---------------------------------------}

function GetEMA(period: integer): double;

var

sum: double;

pr: double;

pos: integer;

begin

pr := 2/63;

pos := Bars -2;

while (pos>=0) do

begin

if (pos = Bars - 2) then sum := close (pos +1) else

sum := ((close(pos) - sum) * pr) + sum;

pos := pos -1;

end;


result := sum;

end;


I have notice that once Bars is > 2035, the testing of my strategy in ForexTester is slowed dramatically.

How can I get over this?

Thanks


It would be better to use indicator MovingAverage in this strategy than calculating it by yourself.

Example:


Code: Select all

var
  EMA: integer;

...

procedure ResetStrategy; stdcall;
begin
  // create EMA 62 on Close indicator
  EMA := CreateIndicator('EURUSD', PERIOD_M15, 'MovingAverage', '62;0;0;' + StrMAType(ma_EMA) + ';Close');
end;

...

procedure GetSingleTick;
var
  value: double;
begin
   ...
   // 0 - bar index (0..Bars - 1), 1 - buffer index
   value := GetIndicatorValue(EMA, 0, 1);
   ...
end;
Hasta la vista
Mike


Return to “FT API”

Who is online

Users browsing this forum: No registered users and 22 guests