Программирование - это просто
Advertisement
arrow arrow , , arrow momentum ( AfterConstruction
07.02.2023 .
1:
C#
Delphi
Web-
Excel-
.
momentum ( AfterConstruction E-mail
megabax   
30.07.2009 .
New Page 1

momentum ( AfterConstruction, TObject)

.

. , " ". www.easyprog.ru (PASSBaseObj PASSIndicators). Delphi , *:

Delphi 7:     class momentum AfterConstruction

 

uses PASSIndicators, PASSBaseObj:

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, PASSIndicators, PASSBaseObj;
 

" " - TPASSMomentum.  :

TPASSMomentum=class(TPASSIndicator)
private
           FDT:integer; //
           FPriceFieldType:string; // (Open, High, Low, Close);
           procedure UpdateParameters; virtual;
           procedure AfterConstruction; override;
protected
           FParameters:TPASSParameters; // .
           FPriceSource:TPASSPriceSource; // .
public
          constructor Create(ADT:integer; APriceFieldType:string);
          function GetResultByFieldName(AFieldName:string):double; override;
          function GetResultByFieldNameAndIndex(AFieldName:string; Index:LongInt):double; override;
          function GetResultByFieldNum(AFieldNum:integer):double; override;
          function GetResultByFieldNumAndIndex(AFieldNum:integer; Index:LongInt):double; override;
          procedure First; override;
          procedure Last; override;
          function Next:boolean; override;
          function Prev:boolean; override;
          function GetIndicatorName:string; override;
end;
 

TPASSIndicator - . PASSIndicators TPASSAverageIndicator, PASSIndicators,  TPASSMASimple TPASSADX, Moving Average. ADX . momentum, , TPASSIndicator.

TPASSIndicator UpdateParameters, . private, . ? , PASSBaseObj PASSIndicators , , Metatrader Metastock. , , , . , .

AfterConstruction, TObject, ,   UpdateParameters, TPASSIndicator . , AfterConstruction TPASSIndicator, , .

, .   TPASSIndicator . , FParameters   FPriceSource private protected, protected .  , .

. UpdateParameters

procedure TPASSMomentum.UpdateParameters;
var i,cn:integer;
begin
  cn:=FParameters.Count-1;
  for i:=0 to cn do
    begin
      if UpperCase(FParameters[i].Name)='DT' then FDT:=FParameters[i].Value else
      begin
          if UpperCase(FParameters[i].Name)='PRICEFIELDTYPE' then FPriceFieldType:=FParameters[i].Value else
                raise Exception.Create('No correct parameter name '+FParameters[i].Name);
      end;
    end;
end;   

. , , . . .

AfterConstruction :

procedure TPASSMomentum.AfterConstruction;
begin
    UpdateParameters;
end;

constructor TPASSMomentum.Create(ADT:integer; APriceFieldType:string);
begin
  inherited Create;
  FParameters.Add('DT',ADT);
  FParameters.Add('PriceFieldType',APriceFieldType);
end;

GetResultByFieldName GetResultByFieldNameAndIndex ( , ADX DI+, DI- ADX). - Value. :

function TPASSMomentum.GetResultByFieldName(AFieldName:string):double;
begin
   if UpperCase(AFieldName)<>'VALUE' then Raise Exception.Create('TPASSMomentum.GetResultByFieldName:     - '+AFieldName);
   Result:=GetResultByFieldNum(0);
end;

function TPASSMomentum.GetResultByFieldNameAndIndex(AFieldName:string; Index:LongInt):double;
begin
   if UpperCase(AFieldName)<>'VALUE' then Raise Exception.Create('TPASSMomentum.GetResultByFieldNameAndIndex:     - '+AFieldName);
   Result:=GetResultByFieldNumAndIndex(0,index);
end;

, :

function TPASSMomentum.GetResultByFieldNum(AFieldNum:integer):double;
var Pend,Pbeg:double;
begin
   if FDT=0 then Raise  Exception.Create('TPASSMomentum.GetResultByFieldNum:    DT');
   if FPriceSource.CurrentItemIndex<=FDT then raise Exception.Create('TPASSMomentum.GetResultByFieldNum:    ');
   if AFieldNum<>0 then Raise Exception.Create('TPASSMomentum.GetResultByFieldNum:    - '+IntToStr(AFieldNum));
   Pend:=FPriceSource.GetDataByFieldName(FPriceFieldType);
   Pbeg:=FPriceSource.GetDataByFieldNameAndIndex('PriceFieldType',FPriceSource.CurrentItemIndex-FDT);
   if Pbeg=0 then raise Exception.Create('TPASSMomentum.GetResultByFieldNum:      '+
        FPriceFieldType+'   '+IntToStr(FPriceSource.CurrentItemIndex-FDT)+'     '+
        DateTimeToStr(FPriceSource.GetDataByFieldNameAndIndex('DateTime',FPriceSource.CurrentItemIndex-FDT)));
   Result:=(Pend-Pbeg)/Pbeg*100/FDT;
end;

function TPASSMomentum.GetResultByFieldNumAndIndex(AFieldNum:integer; Index:LongInt):double;
var Pend,Pbeg:double;
begin
   if AFieldNum<>0 then Raise Exception.Create('TPASSMomentum.GetResultByFieldNumAndIndex:    - '+IntToStr(AFieldNum));
   if FDT=0 then raise Exception.Create('TPASSMomentum.GetResultByFieldNumAndIndex:    DT');
   if index<=FDT then Raise  Exception.Create('TPASSMomentum.GetResultByFieldNumAndIndex:    ');
   Pend:=FPriceSource.GetDataByFieldNameAndIndex(FPriceFieldType,Index);
   Pbeg:=FPriceSource.GetDataByFieldNameAndIndex(FPriceFieldType,Index-FDT);
   if Pbeg=0 then raise Exception.Create('TPASSMomentum.GetResultByFieldNumAndIndex:      '+
        FPriceFieldType+'   '+IntToStr(index-FDT)+'     '+
        DateTimeToStr(FPriceSource.GetDataByFieldNameAndIndex('DateTime',index-FDT)));
   Result:=(Pend-Pbeg)/Pbeg*100/FDT;
end;   

, .

:

procedure TPASSMomentum.Last;
begin
   FPriceSource.Last;
end;

procedure TPASSMomentum.First;
begin
   FPriceSource.CurrentItemIndex:=FDT+1;
end;

function TPASSMomentum.Next:boolean;
begin
   Result:=FPriceSource.NextItem;
end;

function TPASSMomentum.Prev:boolean;
begin
   Result:=FPriceSource.PrevItem;
end;

function TPASSMomentum.GetIndicatorName:string;
begin
  Result:='Momentum';
end;

. momentum. .

 


, * ,   . 1274 "Delphi", "Borland Software Corporation".

 

( 20.07.2013 . )
 
« .   . »
 
© 2023 Программирование - это просто
Joomla! - , GNU/GPL.
© 2005-2008 Joom.Ru - Joomla!
Design by Mamboteam.com | Powered by Mambobanner.de
  .