Average Daily Range Indicator for Timeframes 1 hr to 1 day displaying pips

Examples step by step how to make your own automated strategy or user indicator
Message
Author
Lonesome
Posts: 28
Joined: Fri Oct 21, 2016 9:04 am

Average Daily Range Indicator for Timeframes 1 hr to 1 day displaying pips

#1 Postby Lonesome » Thu Apr 13, 2017 7:05 am

Below is the script for an ADR that works in the Timeframes 1 hr to 1 day.
The ADR calculates pips.


Code: Select all

//---------------------------------------------------------------------------
// Average Daily Range
//
// The Indicator works in the 24, 12, 8, 6, 4, 3, 2, 1 hr TimeFrames
// The selected Period (in days) applies to all Timeframes
// The Indicator calculates pips
// The Indicator can distinguish between Yen pairs and non-Yen pairs
//---------------------------------------------------------------------------
library AverageDailyRangeManyTimeFrames;

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 Multiple Timeframes (ADR)');
  SetOutputWindow(ow_SeparateWindow);

  // register options
  AddSeparator('Common:  this Indicator works in TimeFrame 1 day and below');

  RegOption('Period (days)', 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);
  //SetFixedMinMaxValues(0, 400);
end;

//---------------------------------------------------------------------------
// Deinitialize indicator
//---------------------------------------------------------------------------
procedure Done; stdcall;
begin

end;

//---------------------------------------------------------------------------
// Calculate requested bar
//---------------------------------------------------------------------------
procedure Calculate(index: integer); stdcall;
var
  i, Position, Multiplier,TFMultiplier: integer;
  P_High, P_Low, sum: double;

begin

  if (Timeframe = 1440) or (Timeframe = 720) or (Timeframe = 480) or (Timeframe = 360)
    or (Timeframe = 240) or (Timeframe = 180) or (Timeframe = 120) or (Timeframe = 60) then
  begin

  end
  else
    Exit;

  if Timeframe = 1440 then TFMultiplier := 1;     //24 hrs
  if Timeframe = 720 then TFMultiplier := 2;      //12 hrs
  if Timeframe = 480 then TFMultiplier := 3;      //8 hrs
  if Timeframe = 360 then TFMultiplier := 4;      //6 hrs
  if Timeframe = 240 then TFMultiplier := 6;      //4 hrs
  if Timeframe = 180 then TFMultiplier := 8;      //3 hrs
  if Timeframe = 120 then TFMultiplier := 12;     //2 hrs
  if Timeframe = 60 then TFMultiplier := 24;      //1 hr

  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 * TFMultiplier) - 1) do
    sum := sum + TempBuffer[index + i];
  ADRBuffer[index] := (sum/(Period*TFMultiplier))*Multiplier;

end;

exports

  Init, Done, Calculate;

end.

Return to “Programming lessons”

Who is online

Users browsing this forum: No registered users and 2 guests