Simple Average Daily Range Indicator
Posted: Sun Jan 15, 2017 9:21 am
Below is the script for a simple Average Daily Range Indicator.
This Indicator works only in the 1day TimeFrame.
It creates a line graph in its own window. The ADR is given in pips.
The Indicator can distinguish between Yen contains pairs and pairs not containing Yen.
This Indicator works only in the 1day TimeFrame.
It creates a line graph in its own window. The ADR is given in pips.
The Indicator can distinguish between Yen contains pairs and pairs not containing Yen.
Code: Select all
//---------------------------------------------------------------------------
// Average Daily Range
//
// The Indicator works only in the 1 day TimeFrame
// The Indicator calculates pips
// The Indicator can distinguish between Yen pairs and non-Yen pairs
//---------------------------------------------------------------------------
library AverageDailyRange;
uses
SysUtils,
Math,
Graphics,
IndicatorInterfaceUnit,
TechnicalFunctions;
var
// External variables
Period: integer;
// Buffers
ADRBuffer: TIndexBuffer;
TempBuffer: TIndexBuffer;
//---------------------------------------------------------------------------
// Initialize indicator
//---------------------------------------------------------------------------
procedure Init; stdcall;
begin
// define properties
IndicatorShortName('Average Daily Range (ADR)');
SetOutputWindow(ow_SeparateWindow);
// register options
AddSeparator('Common: this Indicator works only in the 1 day TimeFrame');
RegOption('Period', ot_Integer, Period);
SetOptionRange('Period', 1, MaxInt);
Period := 14;
// create buffers
ADRBuffer := CreateIndexBuffer;
TempBuffer := CreateIndexBuffer;
IndicatorBuffers(1);
SetIndexBuffer(0, ADRBuffer);
SetIndexStyle(0, ds_Line, psSolid, 3, clLime);
SetIndexLabel(0, 'Pips');
IndicatorDigits(2);
end;
//---------------------------------------------------------------------------
// Deinitialize indicator
//---------------------------------------------------------------------------
procedure Done; stdcall;
begin
end;
//---------------------------------------------------------------------------
// Calculate requested bar
//---------------------------------------------------------------------------
procedure Calculate(index: integer); stdcall;
var
i, Position, Multiplier: integer;
P_High, P_Low, sum: double;
begin
if Timeframe <> 1440 then exit;
Position := AnsiPos('JPY', Symbol);
if Position <> 0
then Multiplier := 100
else Multiplier := 10000;
P_High := High(index);
P_Low := Low(index);
TempBuffer[index] := P_High - P_Low;
sum:=0;
for i:=0 to Period - 1 do
sum := sum + TempBuffer[index + i];
ADRBuffer[index] := (sum/Period)*Multiplier;
end;
exports
Init, Done, Calculate;
end.