Page 1 of 1

Financial functions by code

Posted: Thu Aug 20, 2015 12:34 pm
by 16475102
Good day,

I am trying to find in your documentation for examples of creating functions by code, the help file are referring to the following

"Function is a component. When you add a new function you are adding a Series, defining a new function and setting it as FunctionType for the Series.

Series1.SetFunction(TAddTeeFunction.Create(Self));
See the online help for a description of how to add each of the different types of function. Each function uses the same Series method, SetFunction.
"



I have created the following stockhastic function by code, but I would like to see different examples like for :

:MACD
:RSI
:Boilinger bands
:RVI

Please if possible point me to the right help file or examples to use the function properly by code.


here is my code on stockhastic :

Code: Select all

with chart1 do
   begin
      tmpStockhastic := TLineSeries.Create(self);
      addSeries(tmpStockhastic);
      tmpStockhastic.SetFunction(TStochasticFunction.Create(self));
      tmpStockhastic.DataSources.Clear;
      tmpStockhastic.DataSources.Add( candleSeries );
      tmpStockhastic.FunctionType.Period := StrToInt(edtSeries.Text);
      tmpAxis:=Chart1.CustomAxes.Add as TChartAxis;
      tmpStockhastic.CustomVertAxis:=tmpAxis;
      tmpAxis.Axis.Color:=Color;
   end;
Thank you.

Re: Financial functions by code

Posted: Fri Aug 21, 2015 11:11 am
by yeray
Hello,
Gucci wrote::MACD
:RSI
:Boilinger bands
:RVI
You can find examples of how to use those functions in the features demo shipped with the binary installation:
functions.png
functions.png (189.73 KiB) Viewed 4808 times
To create them at runtime, the process is very similar in all them. A part from the source series, you also need a series associated to the function.
Also note in general you want to associate this second series to a custom axis or to a different chart because it will probably have a different range of values then the source series. Here note the function may create extra series internally so you should assign this custom axis to the series' function before assigning the datasource.

Code: Select all

uses CandleCh, Series, StatChar;

var SourceSeries: TCandleSeries;
    SeriesFunc: TLineSeries;
    TeeFunction: TRVIFunction; //TMACDFunction, TRSIFunction, TBollingerFunction, TRVIFunction

procedure TForm1.FormCreate(Sender: TObject);
var tmpAxis: TChartAxis;
begin
  Chart1.View3D:=false;
  Chart1.Legend.Visible:=false;

  SourceSeries:=TCandleSeries.Create(Self);
  Chart1.AddSeries(SourceSeries);
  SourceSeries.FillSampleValues(25);
  Chart1.Axes.Left.EndPosition:=50;

  SeriesFunc:=Chart1.AddSeries(TLineSeries) as TLineSeries;
  tmpAxis:=Chart1.CustomAxes.Add as TChartAxis;
  tmpAxis.StartPosition:=50;
  SeriesFunc.CustomVertAxis:=tmpAxis;
  TeeFunction:=TRVIFunction.Create(Self); //TMACDFunction, TRSIFunction, TBollingerFunction, TRVIFunction
  SeriesFunc.SetFunction(TeeFunction);
  SeriesFunc.DataSources.Add(SourceSeries);
end;