29.02.2024
0
1
374
100
/*
=============== DarvasBox ===============
= Geliştirici: Kıvanç Özbilgiç 
= Yazar: Kripex
=========================================

LowL:=If(L=LLV(L,5),L,If (Ref(L,-1)=LLV(L,5),Ref(L,-1), If(Ref(L,-2)=LLV(L,5),Ref(L,-2),If(Ref(L,-3)=LLV(L,5),Ref(L,-3), If(Ref(L,-4)=LLV(L,5),Ref(L,-4),0)))));
NewH:=ValueWhen(1,H>Ref(HHV (H,5),-1),H);
box1:=HHV(H,3)<HHV(H,4);
box2:=ValueWhen(1,BarsSince(H>Ref(HHV(H,5),-1))=3 AND box1=true,NewH);
box3:=ValueWhen(1,BarsSince(H>Ref(HHV(H,5),-1))=3 AND box1=true,LowL);
TopBox:=box2;
BottomBox:=box3;
TopBox;
BottomBox

FORMÜLÜ by KIVANÇ 
https://drive.google.com/drive/folders/0B4PaGyTCt4lDZllwSmx1M0FtWnM

*/

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
{
	//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("DarvasBoxKripex", IndicatorDrawingArea.OnDataSeries)]
	//Indikatörün çizgilerinin isimleri
	[IndicatorLineInformationAttribute(new []
		{
			"Top", "Bottom"
		}, new []
		{
			"#00CCFF", "#e600de"
		}, new []
		{
			false, false
		}, new []
		{
			0, 0
		}, new []
		{
			1, 1
		}
	)]

	public class DarvasBoxKripex : MatriksIndicator
	{
		public sealed override void OnInit()
		{
		}

		Dictionary<int, decimal> llvList = new Dictionary<int, decimal>();
		Dictionary<int, decimal> hhvList = new Dictionary<int, decimal>();

		decimal lowL, llv5;

		decimal low, lowPrev1, lowPrev2, lowPrev3, lowPrev4;

		decimal high, hhv3, hhv4, hhv5, newH;

		decimal box2, box3;

		int _currentBar;


		bool bayrak = false;

		/// <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)
		{
			var barDataModel = GetBarData();

			/* LowL:=If(L=LLV(L,5),L,
					If (Ref(L,-1)=LLV(L,5),Ref(L,-1), 
						If(Ref(L,-2)=LLV(L,5),Ref(L,-2),
							If(Ref(L,-3)=LLV(L,5),Ref(L,-3), 
								If(Ref(L,-4)=LLV(L,5),Ref(L,-4),0)))));*/

			low = Instrument.SymbolBarData.Low[currentBar];
			llv5 = LowestLow(barDataModel, OHLCType.Low, 5);

			high = Instrument.SymbolBarData.High[currentBar];
			hhv3 = HighestHigh(barDataModel, OHLCType.High, 3);
			hhv4 = HighestHigh(barDataModel, OHLCType.High, 4);
			hhv5 = HighestHigh(barDataModel, OHLCType.High, 5);

			hhvList[currentBar] = hhv5;



			if (currentBar<5)
			{
				lowL = 0;
				llv5 = 0;
			}else
			{
				lowPrev1 = Instrument.SymbolBarData.Low[currentBar -1];
				lowPrev2 = Instrument.SymbolBarData.Low[currentBar -2];
				lowPrev3 = Instrument.SymbolBarData.Low[currentBar -3];
				lowPrev4 = Instrument.SymbolBarData.Low[currentBar -4];

				if (low == llv5)
				{
					lowL = low;
				}else if (lowPrev1 == llv5)
				{
					lowL = lowPrev1;
				}else if (lowPrev2 == llv5)
				{
					lowL = lowPrev2;
				}else if (lowPrev3 == llv5)
				{
					lowL = lowPrev3;
				}else if (lowPrev4 == llv5)
				{
					lowL = lowPrev4;
				}else
				{
					lowL = 0;
				}

				// NewH:=ValueWhen(1,H>Ref(HHV (H,5),-1),H);				
				if (high>hhvList[currentBar -1])
				{
					newH = high;
					_currentBar = currentBar;
				}
			}

			// box1:=HHV(H,3)<HHV(H,4);
			bayrak = hhv3<hhv4 ? true:false;

			// box2:=ValueWhen(1,BarsSince(H>Ref(HHV(H,5),-1))=3 AND box1=true,NewH);
			box2 = (currentBar - _currentBar) == 3 && bayrak ? newH:box2;

			// box3:=ValueWhen(1,BarsSince(H>Ref(HHV(H,5),-1))=3 AND box1=true,LowL);
			box3 = (currentBar - _currentBar) == 3 && bayrak ? lowL:box3;




			if (currentBar < 18)
			{
				SetLine(0, currentBar, 0);
				SetLine(1, currentBar, 0);
				return;
			}

			SetLine(0, currentBar, box2);
			SetLine(1, currentBar, box3);

		}
	}
}

0 Yorum