DiNapoli's Preferred Stochastics Available

Indicators coded by community members
Message
Author
n00ti
Posts: 4
Joined: Mon Apr 06, 2009 1:53 am

DiNapoli's Preferred Stochastics Available

#1 Postby n00ti » Sat Apr 30, 2011 3:51 pm

I was able to configure DiNapoli's Preferred Stochastics according to the formulae in his book. Attached is .dll and source.

%Kslow = 3 period Modified Moving Average of %Kfast
%D = 3 period Modified Moving Average of %Kslow

I am not a programmer but I will try to get DiNapoli's MACD configured next.

Code: Select all


//---------------------------------------------------------------------------
// Stochastic indicator
//---------------------------------------------------------------------------
library Stochastic;

uses
  graphics, windows, TechnicalFunctions, IndicatorInterfaceUnit;

var
  // External variables
  KPeriod: integer;
  DPeriod: integer;
  Slowing: integer;
  ApplyTo: integer;

  // Buffers
  Kfast, Kslow, Dline, HighesBuffer, LowesBuffer: TIndexBuffer;


//---------------------------------------------------------------------------
// Initialize indicator
//---------------------------------------------------------------------------
procedure Init; stdcall;
begin
  // define properties
  IndicatorShortName('DiNapoli Preferred Stochastics');
  SetOutputWindow(ow_SeparateWindow);
  SetFixedMinMaxValues(0, 100);
  //AddLevel(20, psDot, 1, cl_GridColor);
  //AddLevel(80, psDot, 1, cl_GridColor);
  SetEmptyValue(105);

  // register options
  AddSeparator('Common');

  RegOption('%K period', ot_Integer, KPeriod);
  SetOptionRange('%K period', 1, MaxInt);
  KPeriod := 8;

  RegOption('%D period', ot_Integer, DPeriod);
  SetOptionRange('%D period', 1, MaxInt);
  DPeriod := 3;

  RegOption('Slowing', ot_Integer, Slowing);
  SetOptionRange('Slowing', 1, MaxInt);
  Slowing := 3;

  RegOption('Apply to', ot_EnumType, ApplyTo);
  AddOptionValue('Apply to', 'Low/High');
  AddOptionValue('Apply to', 'Close/Close');
  ApplyTo := 0;

  // create buffers
  Kfast := CreateIndexBuffer;
  Kslow := CreateIndexBuffer;
  Dline := CreateIndexBuffer;
  HighesBuffer := CreateIndexBuffer;
  LowesBuffer := CreateIndexBuffer;
  IndicatorBuffers(2);
  SetIndexBuffer(0, Kslow);
  SetIndexBuffer(1, Dline);
  SetIndexStyle(0, ds_line, psDot, 1, RGB($FF, $90, $1E));
  SetIndexLabel(0, 'K Line');
  SetIndexStyle(1, ds_Line, psSolid, 1, RGB($1E, $90, $FF));
  SetIndexLabel(1, 'D Line');
end;

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

end;

//--------------------------------------------------------------------------------
  function iMAonArray(buffer: TIndexBuffer; total:integer; period:integer; ma_shift:integer; MAType:integer; shift:integer; prev:double): double;
 var
  i, N: integer;
  sum, weight, q1, k: double;
begin
 case MAType of
 0:  //SMA
  begin
    sum := 0;
    for i:=shift to shift+period-1 do
     begin
      q1:= buffer[i];
      sum:=sum+q1;
      result :=sum/period;
     end;
  end; // case 0

   1:  //EMA
       begin
         k := 2/(period + 1);
         if prev = 0 then
          begin
           result := buffer[shift];
          end
         else
           begin
            q1:= buffer[shift];
            result := prev + k*(q1-prev);
           end;
       end;

   2:  // WMA
       begin
             sum := 0;
             weight := 0;
             for i:=shift to shift+period-1 do
               begin
                 q1:= buffer[i];
                 N:=(period - i+shift);
                 sum := sum + q1*N;
                 weight := weight + N;
               end;
            result  := sum/weight;

        end;

   3:   // SSMA
      begin
            if prev = 0 then
             result := GetMA(shift, 0, period, TMAType(MAType), TPriceType(0))
            else
              begin
               q1:= buffer[shift];
               result  := ((period-1)*prev+q1)/period;  //pas
              end;
      end;

 end; //case
end;
//---------------------------------------------------------------------------
// Calculate requested bar
//---------------------------------------------------------------------------
procedure Calculate(index: integer); stdcall;
var
  sumlow, sumhigh, Plow, Phigh: double;
  i: integer;

begin
  if (Bars < KPeriod) or (Bars < Slowing) or (Bars < DPeriod) then
    exit;

if ApplyTo = 0 then
 begin
  // find highest and lowest price for period KPeriod
  Phigh := High(index);
  Plow := Low(index);
  for i:=1 to KPeriod - 1 do
    begin
      if High(index + i) >= Phigh then
       begin
        Phigh := High(index + i);
       end;
      if Low(index + i) <= Plow then
       begin
        Plow := Low(index + i);
       end;
    end;
 end
else
 begin
  Phigh := Close(index);
  Plow := Close(index);
  for i:=1 to KPeriod - 1 do
    begin
      if Close(index + i) >= Phigh then
       begin
        Phigh := Close(index + i);
       end;
      if Close(index + i) <= Plow then
       begin
        Plow := Close(index + i);
       end;
    end;
 end;
        HighesBuffer[index] := Phigh;
        LowesBuffer[index] := Plow;
  // count Kfast line value
  sumlow := 0;
  sumhigh := 0;
  for i:=index+Slowing - 1 downto index do
   begin
    sumlow:=sumlow+Close(i)-LowesBuffer[i];
    sumhigh:=sumhigh+HighesBuffer[i]-LowesBuffer[i];
   end;
      if(sumhigh=0.0) then Kfast[index]:=100.0
      else Kfast[index]:=sumlow/sumhigh*100;

      Kslow[index]:=iMAOnArray(Kfast,Bars,DPeriod,0,3,index,Kslow[index+1]);
      Dline[index]:=iMAOnArray(Kslow,Bars,DPeriod,0,3,index,Dline[index+1]);
end;

exports

Init, Done, Calculate;
begin
end.
[/code]
Attachments
DiNapoliPreferredStochastics.zip
dll and source. no password
(1.68 MiB) Downloaded 764 times

Chris
Posts: 29
Joined: Fri Apr 29, 2011 2:00 pm

#2 Postby Chris » Tue Sep 20, 2011 5:14 am

Thanks you very for sharing!
I don't have his book
can you please tell me the levels for overbought/oversold?
I think it would be good to be able to add levels,
also if this is the original settings?
I read somwhere the K line is 20 periods?

KelvinHand
Posts: 103
Joined: Sun Jan 02, 2011 6:05 pm

#3 Postby KelvinHand » Mon Jan 02, 2012 4:55 am

Chris wrote:Thanks you very for sharing!
I don't have his book
can you please tell me the levels for overbought/oversold?
I think it would be good to be able to add levels,
also if this is the original settings?
I read somwhere the K line is 20 periods?


DiNapoli's Preferred Stochastics is using 8,3,3. very lag. it plot level 25 & 75.
However, he never use these levels for trading.


Return to “Indicators”

Who is online

Users browsing this forum: No registered users and 5 guests