BB7sma for FT2
LazarusでBollinger Bands(7本)を作成しましたがファイルサイズが大きすぎて、Forumにアップロードできませんでした。//------------------------------------------// BB7sma//------------------------------------------library BB7sma;usesInterfaces, graphics, IndicatorInterfaceUnit, TechnicalFunctions;var// External variablesperiod: integer = 21;Shift: integer = 0;Dev1: double = 1;Dev2: double = 2;Dev3: double = 3;ApplyToPrice: integer;// BuffersUp3, Up2, Up1, SMA, Low1, Low2, Low3: TIndexBuffer;//------------------------------------------// Initialize indicator//------------------------------------------procedure Init; stdcall;begin// define propertiesIndicatorShortName('BB7sma');SetOutputWindow(ow_ChartWindow);// register optionsAddSeparator('Common');RegOption('Period', ot_Integer, period);SetOptionRange('Period', 1, MaxInt);RegOption('Deviaton1', ot_Double, Dev1);SetOptionRange('Deviation1', 0.1, 200);RegOption('Deviation2', ot_Double, Dev2);SetOptionRange('Deviation2', 0.1, 200);RegOption('Deviation3', ot_Double, Dev3);SetOptionRange('Deviation3', 0.1, 200);RegOption('Shift', ot_Integer, Shift);RegApplyToPriceOption(ApplyToPrice);// create buffersUp3 := CreateIndexBuffer;Up2 := CreateIndexBuffer;Up1 := CreateIndexBuffer;SMA := CreateIndexBuffer;Low1 := CreateIndexBuffer;Low2 := CreateIndexBuffer;Low3 := CreateIndexBuffer;IndicatorBuffers(7);SetIndexBuffer(0, Up3);SetIndexStyle(0, ds_Line, psSolid, 1, clTeal);SetIndexLabel(0, 'Upper3');SetIndexBuffer(1, Up2);SetIndexStyle(1, ds_Line, psSolid, 1, clTeal);SetIndexLabel(1, 'Upper2');SetIndexBuffer(2, Up1);SetIndexStyle(2, ds_Line, psSolid, 1, clTeal);SetIndexLabel(2, 'Upper1');SetIndexBuffer(3, SMA);SetIndexStyle(3, ds_Line, psSolid, 2, clTeal);SetIndexLabel(3, 'SMA');SetIndexBuffer(4, Low1);SetIndexStyle(4, ds_Line, psSolid, 1, clTeal);SetIndexLabel(4, 'Lower1');SetIndexBuffer(5, Low2);SetIndexStyle(5, ds_Line, psSolid, 1, clTeal);SetIndexLabel(5, 'Lower2');SetIndexBuffer(6, Low3);SetIndexStyle(6, ds_Line, psSolid, 1, clTeal);SetIndexLabel(6, 'Lower3');end;//------------------------------------------ //parameters changed//------------------------------------------procedure OnParamsChange; stdcall;beginSetBufferShift(1, Shift);SetBufferShift(2, Shift);SetBufferShift(3, Shift);SetBufferShift(4, Shift);SetBufferShift(5, Shift);SetBufferShift(6, Shift);end;//------------------------------------------// Calculate requested bar//------------------------------------------procedure Calculate(index: integer); stdcall;vari: integer;sum, value, sd1, sd2, sd3: double;function GetPrice(index: integer): double;beginresult := TechnicalFunctions.GetPrice(index, TPriceType(ApplyToPrice));end;beginif (index + period) >= Bars thenexit;value := GetMA(index, 0, period, ma_SMA, TPriceType(ApplyToPrice), SMA[index + 1]);SMA[index] := value;// calculate bandsif value <> 0 thenbeginsum := 0;for i:=index to index + period - 1 dosum := sum + sqr(abs(GetPrice(i) - value));sd1 := sqrt(sum/period)*Dev1;sd2 := sqrt(sum/period)*Dev2;sd3 := sqrt(sum/period)*Dev3;Up1[index] := SMA[index] + sd1;Low1[index] := SMA[index] - sd1;Up2[index] := SMA[index] + sd2;Low2[index] := SMA[index] - sd2;Up3[index] := SMA[index] + sd3;Low3[index] := SMA[index] - sd3;endelsebeginUp1[index] := 0;Low1[index] := 0;Up2[index] := 0;Low2[index] := 0;Up3[index] := 0;Low3[index] := 0;end;end;exportsInit, OnParamsChange, Calculate;end.