Is there a way to set the scale in code??
Thanks.
Code: Select all
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.