FRAMA:
[CODE]using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
namespace WealthLab.Strategies
{
public class FRAMA : WealthScript
{
public StrategyParameter N;
public FRAMA()
{
N = CreateParameter("Length", 16, 4, 32, 2);
}
protected override void Execute()
{
int Length = N.ValueInt;
double N1; double N2; double N3; double Dim; double alpha;
DataSeries FRAMA = new DataSeries(Bars, "FRAMA" + "(" + Convert.ToString(Length) + ")");
DataSeries OHLC = Close; //(High + Low + Close + Open)/4;
FRAMA[0] = OHLC[0];
for(int bar = 1; bar < Length; bar++)
{
FRAMA[bar] = (bar * FRAMA[bar - 1] + OHLC[bar]) / (bar + 1);
}
for(int bar = Length; bar < Bars.Count; bar++)
{
N3 = (Highest.Value(bar, OHLC, Length) - Lowest.Value(bar, OHLC, Length)) / Length;
N1 = 2 * (Highest.Value(bar - (Length/2), OHLC, Length/2) - Lowest.Value(bar - Length/2, OHLC, Length/2)) / Length;
N2 = 2 * (Highest.Value(bar, OHLC, Length/2) - Lowest.Value(bar, OHLC, Length/2)) / Length;
if ((N1 > 0) && (N2 > 0) && (N3 > 0))
{
Dim = (Math.Log(N1 + N2) - Math.Log(N3)) / Math.Log(2);
}
else {Dim = 1;}
alpha = Math.Exp(-4.6 * (Dim - 1));
if (alpha < 0.01) { alpha = 0.01; }
else if (alpha > 1) { alpha = 1; }
FRAMA[bar] = alpha * OHLC[bar] + (1 - alpha) * FRAMA[bar - 1];
}
PlotSeries(PricePane, FRAMA, Color.Black, WealthLab.LineStyle.Solid, 2);
}
}
}[/CODE]
KAMA:
[CODE]using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
namespace WealthLab.Strategies
{
public class KAMA : WealthScript
{
private StrategyParameter FastSC;
private StrategyParameter SlowSC;
private StrategyParameter Period;
public KAMA()
{
FastSC = CreateParameter("Fast", 0.2, 0.01, 0.99, 0.01);
SlowSC = CreateParameter("Slow", 0.2, 0.01, 0.99, 0.01);
Period = CreateParameter("n", 10, 1, 100, 1);
if (FastSC.Value < SlowSC.Value)
{ throw new Exception("Slow smoothing constant must not exceed fast smoothing constant"); }
}
protected override void Execute()
{
int n = Period.ValueInt;
double Fast = FastSC.Value;
double Slow = SlowSC.Value;
DataSeries KAMA = new DataSeries(Bars, "Kaufmann AMA" + "(" + Convert.ToString(Fast) + "," + Convert.ToString(Slow) + "," + Convert.ToString(n) + ")");
DataSeries ema = EMA.Series(Close, n, WealthLab.Indicators.EMACalculation.Modern);
for(int bar = 0; bar < n; bar++)
{
KAMA[bar] = ema[bar];
}
double Dir;
double Volat = 0;
double C;
//Шаг: bar = n
Dir = Close[n] - Close[0];
for(int k = 0; k < n; k++)
{
Volat += Math.Abs(Close[n-k] - Close[n-k-1]);
}
C = (Dir/Volat)*(Fast - Slow) + Slow;
KAMA[n] = KAMA[n-1] + C*(Close[n] - KAMA[n-1]);
//Основной цикл:
for(int bar = n + 1; bar<Bars.Count;bar++)
{
Dir = Close[bar] - Close[bar-n];
Volat += Math.Abs(Close[bar] - Close[bar-1]) - Math.Abs(Close[bar-n] - Close[bar-n-1]);
C = (Dir/Volat)*(Fast - Slow) + Slow;
KAMA[bar] = KAMA[bar-1] + C*(Close[bar] - KAMA[bar-1]);
}
PlotSeries(PricePane, KAMA, Color.Black, WealthLab.LineStyle.Solid, 2);
}
}
}[/CODE]