VWMACDV2 - Volume Weighted Macd V2
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;
// Kıvanç Özbilgiç - https://www.tradingview.com/script/wVe6AfGA-VOLUME-WEIGHTED-MACD-V2-VWMACDV2Kripex-BY-KIVAN%C3%87-fr3762/
/*
//@version=3
//created by Buff DORMEIER
//author: KIVANC @fr3762 on twitter
study("VOLUME WEIGHTED MACD V2", shorttitle="VWMACDV2KripexV2")
fastperiod = input(12,title="fastperiod",type=integer,minval=1,maxval=500)
slowperiod = input(26,title="slowperiod",type=integer,minval=1,maxval=500)
signalperiod = input(9,title="signalperiod",type=integer,minval=1,maxval=500)
fastMA = ema(volume*close, fastperiod)/ema(volume, fastperiod)
slowMA = ema(volume*close, slowperiod)/ema(volume, slowperiod)
vwmacd = fastMA - slowMA
signal = ema(vwmacd, signalperiod)
hist= vwmacd - signal
plot(vwmacd, color=blue, linewidth=2)
plot(signal, color=red, linewidth=2)
plot(hist, color=green, linewidth=4, style=histogram)
plot(0, color=black)
*/
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("VWMACDV2Kripex", IndicatorDrawingArea.NewWindow)]
//Indikatörün çizgilerinin isimleri
[IndicatorLineInformationAttribute(new []
{
"VWMacd", "Signal", "Hist"
}, new []
{
"#DC0D52", "#00CCFF", "#16A13C"
}, new []
{
false, false, false
}, new []
{
0, 0, 5
}, new []
{
2, 2, 4
})]
public class VWMACDV2Kripex : MatriksIndicator
{
//Indicator opsiyon panelinde değerleri değiştirebildiğimiz parametreler. Int, Bool, Decimal ve Enum değerleri alabilir.Tüm değişken tiplerini DefaultValue ile tanımlarız.
[DefaultValue(12)]
public int FastPeriod
{
get; set;
}
[DefaultValue(26)]
public int SlowPeriod
{
get; set;
}
[DefaultValue(9)]
public int SignalPeriod
{
get; set;
}
EMA EmaVCFast, EmaVCSlow, EmaVFash, EmaVSlow, EmaVWMacd;
public sealed override void OnInit()
{
EmaVFash = EMAIndicator(Symbol, SymbolPeriod, OHLCType.Volume, FastPeriod);
EmaVSlow = EMAIndicator(Symbol, SymbolPeriod, OHLCType.Volume, SlowPeriod);
EmaVCFast = new EMA(FastPeriod);
EmaVCSlow = new EMA(SlowPeriod);
EmaVCSlow = new EMA(SlowPeriod);
EmaVWMacd = new EMA(SignalPeriod);
DrawHorizantal(0);
}
decimal fastMA, slowMA, VxC, vwmacd, signal, hist;
/// <summary>
/// Seçilen sembolün bardata'ları güncellendikçe bu fonksiyon tetiklenir.
/// </summary>
/// <param name="currentBar">Güncellenen bardata'nın indexteki sırası</param>
/// <param name="inputValue">Seçilen OHLC tipine göre gelen bardata'nın o anki değeri</param>
/// <param name="barDateTime">Bardata'ya gelen güncelleme zamanı</param>
public override void OnDataUpdate(int currentBar, decimal inputValue, DateTime barDateTime)
{
VxC = Instrument.SymbolBarData.Volume[currentBar] * Instrument.SymbolBarData.Close[currentBar];
EmaVCFast.Update(VxC, currentBar, barDateTime);
EmaVCSlow.Update(VxC, currentBar, barDateTime);
fastMA = EmaVFash.CurrentValue != 0? EmaVCFast.CurrentValue / EmaVFash.CurrentValue:0;
slowMA = EmaVSlow.CurrentValue != 0? EmaVCSlow.CurrentValue / EmaVSlow.CurrentValue:0;
vwmacd = fastMA - slowMA;
EmaVWMacd.Update(vwmacd, currentBar, barDateTime);
signal = EmaVWMacd.CurrentValue;
hist = vwmacd - signal;
if (currentBar < Period)
{
SetLine(0, currentBar, 0);
SetLine(1, currentBar, 0);
SetLine(2, currentBar, 0);
return ;
}
SetLine(0, currentBar, vwmacd);
SetLine(1, currentBar, signal);
SetLine(2, currentBar, hist);
}
}
}