0 beğenilme 0 beğenilmeme
897 kez görüntülendi

Merhaba öncelikle darvas box indikatörüne %1 kar al ve stop ol demek istiyorum ama tam anlamıyla formüllleri bilmediğim icin yapamadım yardımcı olabilirmisiniz şimdiden teşekkür ederim.

Kodu:

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;

/*
FORMÜLÜ by KIVANÇ 

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

https://drive.google.com/drive/folders/0B4PaGyTCt4lDZllwSmx1M0FtWnM

*/
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"
		})]

	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 < 5)
			{
				//SetLine fonksiyonu indikatördeki noktaları kuran fonksiyondur
				//Ilk paramatre indicatordeki hangi çizginin güncelleneceği bilgisidir.
				//Ikinci parametre güncellenecek çizginin hangi indexinin güncelleneceği bilgisidir.
				//Ucüncü parametre güncellenecek çizginin indexinin alacağı değerdir.
				SetLine(0, currentBar, 0);
				SetLine(1, currentBar, 0);
				return ;
			}

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

		}
	}
}
Indikator Builder kategorisinde (31 puan) tarafından | 897 kez görüntülendi

1 cevap

0 beğenilme 0 beğenilmeme

Merhaba,

Kar al ve stop emirlerini strateji içerisinde ekleyebilirsiniz. Öncelikle attığınız indikatör ile strateji oluşturup kar al ve zarar durdur emirlerinizi pozisyona girdiğiniz(yani stratejide emir verdiğiniz kod satırları) yerden sonra eklemeniz gerekli.

Algoritma sihirbazında DarvasBox indikatörü için kolayca strateji oluşturabilirsiniz. Stratejinizi oluşturduktan sonra emir verdiğiniz satırların altına aşağıdaki kod parçasını ekleyebilirsiniz. Aşağıdaki Kar_Al ve Zarar_Durdur Fiyat miktari parametrelerini silip kar al ve stop seviyelerinin tetiklenmesini istediğiniz fiyat değişimini yazmalısınız. (Ör. Zarar durdur fiyat miktarını 0.1 yaparsanız fiyat 0.1 düştüğünde Zarar durdur emri tetiklenir.) 

TakeProfit(Symbol, SyntheticOrderPriceType.PricePoint, Kar_AL_FiyatMiktari);
StopLoss(Symbol, SyntheticOrderPriceType.PricePoint, Zarar_Durdur_FiyatMiktari);

İyi çalışmalar

(4,555 puan) tarafından
Hoş geldiniz, Matriks Destek Platformu sizlere sorularınızın hızlıca cevaplanması için bir ortam sağlar. Sorduğunuz ve cevapladığınız soruların ve yorumlarınızın aldığı oylar üzerinden puan kazanırsınız. Puan sistemine bağlı kampanyamızla ücretsiz kullanım avantajlarından faydalanabilirsiniz.



7,574 soru
7,580 cevap
4,427 yorum
10,098 kullanıcı