0 beğenilme 0 beğenilmeme
73 kez görüntülendi
using System;
using System.Collections.Generic;
using System.Linq;
using System.ComponentModel;
using Matriks.Data.Identifiers;
using Matriks.Data.Symbol;
using Matriks.Engines;
using Matriks.Indicators;
using Matriks.Symbols;
using Matriks.AlgoTrader;
using Matriks.Trader.Core;
using Matriks.Trader.Core.Fields;
using Matriks.Trader.Core.TraderModels;
using Matriks.Lean.Algotrader.AlgoBase;
using Matriks.Lean.Algotrader.Models;
using Matriks.Lean.Algotrader.Trading;

namespace Matriks.Lean.Algotrader
{
	[IndicatorInformationAttribute("Butterworth_v2", IndicatorDrawingArea.OnDataSeries)]
	[IndicatorLineInformationAttribute(new []
		{
			"Butterworth(0,1)"
		})]

	public class Butterworth_v2 : MatriksIndicator
	{
		[DefaultValue(15)]
		public int Period
		{
			get; set;
		}

		private float a1, b1, coef2, coef3, coef1;
		private Dictionary<int, float> Butter = new Dictionary<int, float>();

		public override void OnInit()
		{
			Butter.Add(0, 0); // Add initial values for currentBar 0 and 1
			Butter.Add(1, 0);
		}

		public override void OnDataUpdate(int currentBar, decimal close, DateTime barDateTime)
		{
			CalculateButterValues(currentBar, close);
		}

		private void CalculateButterValues(int currentBar, decimal close)
		{
			if (currentBar < 2)
			{
				return;
			}

			if (!Butter.ContainsKey(currentBar))
			{
				Butter.Add(currentBar, 0);
			}

			a1 = (float) Math.Exp(-1.414 * 3.14159 / Period);
			b1 = 2 * a1 * (float) Math.Cos(1.414 * 3.14159 / Period);
			coef2 = b1;
			coef3 = - a1 * a1;
			coef1 = Math.Min(coef1, float.MaxValue / 100);

			Butter[currentBar] = coef1 * (float) close + 2 * Butter[currentBar - 1] + Butter[currentBar - 2];

			SetLine(0, currentBar, (decimal) Butter[currentBar]);
		}
	}
}

 

int period = 15;

float a1 = (float)Math.Exp(-1.

414 * 3.14159 / period);
float b1 = 2 * a1 * (float)Math.Cos(1.414 * 3.14159 / period);
float coef2 = b1;
float coef3 = -a1 * a1;
float coef1 = (1 - b1 + a1 * a1) / 4;

var Butter=Sistem.Liste(V.Count,0);

for(int j=3; j<V.Count; j++){
  
  Butter[j]=coef1 * (C[j] + 2 * C[j-1] + C[j-2]) + coef2 * Butter[j-1] + coef3 * Butter[j-2];
  
}

Sorunun sebebini bilen varmıdır acaba ?

Algoritmik Trading kategorisinde (402 puan) tarafından | 73 kez görüntülendi

Bu soruya cevap vermek için lütfen giriş yapınız veya kayıt olunuz.

7,647 soru
7,642 cevap
4,448 yorum
11,124 kullanıcı