İndikatör adı: KDJG
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("KDJG", IndicatorDrawingArea.NewWindow)]
[IndicatorLineInformationAttribute(new []
{
"KDJG(0,1,2)", "D", "J"
})]
public class KDJG : MatriksIndicator
{
[DefaultValue(9)]
public int Period
{
get; set;
}
[DefaultValue(3)]
public int K
{
get; set;
}
[DefaultValue(3)]
public int D
{
get; set;
}
SMA smaK, smaD;
public override void OnInit()
{
smaK = new SMA(K);
smaD = new SMA(D);
}
private decimal GetTypicalPrice(int barIndex)
{
return (Instrument.SymbolBarData.Close[barIndex] + Instrument.SymbolBarData.High[barIndex] + Instrument.SymbolBarData.Low[barIndex]) / 3;
}
private decimal GetRSV(int barIndex, int period)
{
// RSV:(CLOSE - LLV(LOW, N)) / (HHV(HIGH, N) - LLV(LOW, N)) * 100;
return (Instrument.SymbolBarData.Close[barIndex] - LowestLow(Instrument.SymbolBarData, OHLCType.Low, period)) / (HighestHigh(Instrument.SymbolBarData, OHLCType.High, period) - LowestLow(Instrument.SymbolBarData, OHLCType.Low, period)) * 100;
}
public override void OnDataUpdate(int currentBar, decimal inputValue, DateTime barDateTime)
{
// K:SMA(RSV, M1, 1);
// D:SMA(K, M2, 1);
// J:3 * K -2 * D;
SetLine(0, currentBar, 0);
SetLine(1, currentBar, 0);
SetLine(2, currentBar, 0);
var rsv = GetRSV(currentBar, Period);
smaK.Update(rsv, currentBar, barDateTime);
var kValue = smaK.CurrentValue;
smaD.Update(kValue, currentBar, barDateTime);
var dValue = smaD.CurrentValue;
var jValue = 3 * kValue - 2 * dValue;
if (currentBar < Period - 1) return ;
SetLine(0, currentBar, kValue);
SetLine(1, currentBar, dValue);
SetLine(2, currentBar, jValue);
}
}
}