Squeeze Momentum Indicator [LazyBear]
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;
using System.Windows.Media;
/*
BBfactor:=Input("BBfactor",0,20,1.5);
KCfactor:=Input("KCfactor",0,20,1.5);
BBperiod:=Input("BBperiod",1,500,20);
KCperiod:=Input("KCperiod",1,500,20);
bb:=bband(c,BBperiod,s,BBfactor);
bbdw:=bbandbot(c,BBperiod,s,BBfactor);
bbup:=bbandtop(c,BBperiod,s,BBfactor);
KCma:=mov(c,KCperiod,s);
range:=H-L;
rangema:=mov(range,KCperiod,s);
upperKC:=KCma+rangema*KCfactor;
lowerKC:=KCma-rangema*KCfactor;
SQMI:=LINEARREG(C-((HHV(H,KCperiod)+LLV(L,KCperiod))/2+KCma)/2,KCperiod);
SQMI
*/
namespace Matriks.Lean.Algotrader
{
//Ilk parametre indikatörün adı, sınıfın adıyla aynı olmalıdır.
//Ikinci parametre indikatörün Dataserisinin üzerine mi yeni pencereye mi ekleneceğini belirtir. Yeni pencere için ->IndicatorDrawingArea.NewWindow , Data Serisi için IndicatorDrawingArea.OnDataSeries
[IndicatorInformationAttribute("SQMIKripex", IndicatorDrawingArea.NewWindow)]
//Indikatörün çizgilerinin isimleri
[IndicatorLineInformationAttribute(new []
{
"SQMI(0,1)"
}, new []
{
"#ffffff"
}, new []
{
false
}, new []
{
5
}, new []
{
1
}
)]
public class SQMIKripex : MatriksIndicator
{
[DefaultValue(20)]
public int KCperiod
{
get; set;
}
[DefaultValue(1.5)]
public decimal KCfactor
{
get; set;
}
LRL lrl;
MOV KCma, rangema;
BOLLINGER bb;
public sealed override void OnInit()
{
lrl = new LRL(KCperiod);
KCma = MOVIndicator(Symbol, SymbolPeriod, OHLCType.Close, KCperiod, MovMethod.Simple);
rangema = new MOV(KCperiod, MovMethod.Simple);
DrawHorizantal(0);
}
decimal close, range, upperKC, lowerKC, SQMI;
public override void OnDataUpdate(int currentBar, decimal inputValue, DateTime barDateTime)
{
if (Instrument.SymbolBarData.Close.ContainsKey(currentBar))
{
range = Instrument.SymbolBarData.High[currentBar] - Instrument.SymbolBarData.Low[currentBar];
close = Instrument.SymbolBarData.Close[currentBar];
}
rangema.Update(range, currentBar, barDateTime);
lrl.Update(close - (((HighestHigh(OHLCType.High, KCperiod) + LowestLow(OHLCType.Low, KCperiod)) / 2) + KCma.CurrentValue) / 2, currentBar, barDateTime);
if (currentBar < KCperiod)
{
SetLine(0, currentBar, 0);
return;
}
SetLine(currentBar, lrl.CurrentValue);
if (lrl.CurrentValue>0)
{
PaintPoint(currentBar, lrl.Value[0][lrl.CurrentIndex -1] >lrl.Value[0][lrl.CurrentIndex] ? "#3c6300":"#98fb00", 0);
}else
{
PaintPoint(currentBar, lrl.Value[0][lrl.CurrentIndex -1] <lrl.Value[0][lrl.CurrentIndex] ? "#3c6300":"#98fb00", 0);
}
}
}
}