Forex Tester Forum (Professional Training Software for Traders) Forum Index Forex Tester Forum (Professional Training Software for Traders)

Back to main site   Risk disclosure
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Mike, what's wrong with this?

 
Post new topic   Reply to topic    Forex Tester Forum (Professional Training Software for Traders) Forum Index -> FT API
View previous topic :: View next topic  
Author Message
Tantalus



Joined: 23 Mar 2007
Posts: 300

PostPosted: Sat Jan 12, 2008 12:26 am    Post subject: Mike, what's wrong with this? Reply with quote

Why does this indicator get bunched up at the top of the window? It should vary from -1 to 0 to 1 in discrete steps - sort of like a square wave... it looks like to output is OK but the scaling of the window is weird, but I can't see it well enough to be sure...

Is there a way to set the scale in code??

Thanks.

Code:
library HMADSD;

uses
  graphics,
  IndicatorInterfaceUnit,
  TechnicalFunctions;

var
  // External variables
  period: integer = 32;

  // Buffers
  WMA1, WMA2, WMADiff, HMA, DSD: TIndexBuffer;


//---------------------------------------------------------------------------
// Initialize indicator
//---------------------------------------------------------------------------
procedure Init; stdcall;
begin
  // define properties
  IndicatorShortName('HMADSD');
  SetOutputWindow(ow_SeparateWindow);
  {AddLevel(0, psSolid, 1, cl_GridColor);
  SetEmptyValue(0);}

  // register options
  AddSeparator('Common');
  RegOption('Period', ot_Integer, period);
  SetOptionRange('Period', 1, MaxInt);

  // create buffers
  DSD := CreateIndexBuffer;
  WMA1 := CreateIndexBuffer;
  WMA2 := CreateIndexBuffer;
  WMADiff := CreateIndexBuffer;
  HMA := CreateIndexBuffer;

  IndicatorBuffers(1);
  SetIndexBuffer(0, DSD);
  SetIndexStyle(0, ds_Line, psSolid, 1, clYellow);
  SetIndexLabel(0, 'DSD');
end;

//---------------------------------------------------------------------------
// Calculate requested bar
//---------------------------------------------------------------------------
procedure Calculate(index: integer); stdcall;
var
  halfperiod: integer;
  sqrtperiod: integer;
  sum: double;
  weight: integer;
  i: integer;

begin
  if index + period >= Bars then
    exit;

  halfperiod := Trunc(period / 2);
  sqrtperiod := Trunc(Sqrt(period));

  WMA1[index] := WMA(halfperiod, index) * 2;
  WMA2[index] := WMA(period, index);
  WMADiff[index] := WMA1[index] - WMA2[index];

  sum := 0;
  weight := 0;
  for i:=0 to sqrtperiod - 1 do
    begin
      sum := sum + WMADiff[index + i] * (sqrtperiod - i);
      weight := weight + (sqrtperiod - i);
    end;
  HMA[index] := sum / weight;

  DSD[index] := 0.0;

  if (HMA[index] - HMA[index + 2] > 0)
    and (HMA[index + 1] - HMA[index + 3] > 0)
    then DSD[index] := 1.0;

  if (HMA[index] - HMA[index + 2] < 0)
    and (HMA[index + 1] - HMA[index + 3] < 0)
    then DSD[index] := -1.0;

end;

exports

Init, Calculate;

end.


Last edited by Tantalus on Tue May 26, 2009 12:43 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
Terranin
Site Admin


Joined: 21 Oct 2006
Posts: 831

PostPosted: Sat Jan 12, 2008 2:45 am    Post subject: Reply with quote

Screenshot would help a lot. To set scale use SetFixedMaxMinValues in init procedure.
_________________
Hasta la vista
Mike
Back to top
View user's profile Send private message
Tantalus



Joined: 23 Mar 2007
Posts: 300

PostPosted: Sat Jan 12, 2008 3:10 am    Post subject: Reply with quote

OK, here's a screenshot. Maybe you could try running it on your machine to see what it does.

I'll try the function you suggested and some more debugging...

thx.



ind_up_top.jpg
 Description:
 Filesize:  52.71 KB
 Viewed:  3529 Time(s)

ind_up_top.jpg


Back to top
View user's profile Send private message Visit poster's website
Terranin
Site Admin


Joined: 21 Oct 2006
Posts: 831

PostPosted: Sat Jan 12, 2008 4:08 am    Post subject: Reply with quote

Also, empty value is 0, if you use this value in your indicator then set default to 0.000000123 for example with SetEmptyValue. Otherwise points with 0 value will not be painted at all.
_________________
Hasta la vista
Mike
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Forex Tester Forum (Professional Training Software for Traders) Forum Index -> FT API All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group