22.08.2022
4
2
0
100

Anıl Özekşi tarafından oluşturulan bu sistemde fırsatçı trend diye adlandırdığı OTT indikatörü kullanılan formülü ile, klasik olarak IF'li sistemi birleştirilmiştir.

Sistem sadece al-sat yapar.

Hem BIST hem kriptoda kullanılabilir.

Vadeli semboller ve spot sembollerde de kullanabilirsiniz.

Ayarlanabilir kaldıraç oranı vardır.



using System;
using System.Collections.Generic;
using System.Linq;
using Matriks;
using Matriks.Data.Symbol;
using Matriks.Engines;
using Matriks.Indicators;
using Matriks.Symbols;
using Matriks.Trader.Core;
using Matriks.Trader.Core.Fields;
using Matriks.Lean.Algotrader.AlgoBase;
using Matriks.Lean.Algotrader.Models;
using Matriks.Lean.Algotrader.Trading;
using Matriks.AI;
using Matriks.AI.AiParameters;
using Matriks.AI.Data;
using Matriks.Trader.Core.TraderModels;

namespace Matriks.Lean.Algotrader
{
	public class FirsatciTrendAlSat : MatriksAlgo
	{
		// Strateji çalıştırılırken kullanacağımız parametreler. Eğer sembolle ilgili bir parametre ise,
		// "SymbolParameter" ile, değilse "Parameter" ile tanımlama yaparız. Parantez içindeki değerler default değerleridir.


		[SymbolParameter("GARAN")]
			public string Symbol1;


		[Parameter(SymbolPeriod.Day)]
			public SymbolPeriod SymbolPeriod1;



		[Parameter(2)]
			public int OttPeriod1;

		[Parameter(1.4)]
			public decimal OttOpt1;

		[Parameter(MovMethod.VAR)]
			public MovMethod OttMovMethod1;

		[Parameter(true)]
			public bool OttSupportLine1;

		[Parameter(40)]
			public int TottPeriod1;

		[Parameter(1)]
			public decimal TottOpt1;

		[Parameter(0.001)]
			public decimal TottTwinOttCoef1;

		[Parameter(MovMethod.VAR)]
			public MovMethod TottMovMethod1;

		[Parameter(500)]
			public int SottPeriodK1;

		[Parameter(200)]
			public int SottPeriodSlowK1;

		[Parameter(2)]
			public int SottOttPeriod1;

		[Parameter(0.5)]
			public decimal SottOttOpt1;

		[Parameter(MovMethod.VAR)]
			public MovMethod SottOttMethod1;

		[Parameter(MovMethod.VAR)]
			public MovMethod SottStosKMethod1;

		[Parameter(2)]
			public int HottlottPeriod1;

		[Parameter(1.4)]
			public decimal HottlottOpt1;

		[Parameter(10)]
			public int HottlottBarSayisi1;

		[Parameter(MovMethod.VAR)]
			public MovMethod HottlottMovMethod1;

		[Parameter(5)]
			public int HighesthighPeriod1;

		[Parameter(2)]
			public int OttPeriod2;

		[Parameter(1.5)]
			public decimal OttOpt2;

		[Parameter(MovMethod.VAR)]
			public MovMethod OttMovMethod2;

		[Parameter(true)]
			public bool OttSupportLine2;

		[Parameter(2)]
			public int OttPeriod3;

		[Parameter(1.5)]
			public decimal OttOpt3;

		[Parameter(MovMethod.VAR)]
			public MovMethod OttMovMethod3;

		[Parameter(true)]
			public bool OttSupportLine3;

		[Parameter(50)]
			public int TottPeriod2;

		[Parameter(1)]
			public decimal TottOpt2;

		[Parameter(0.001)]
			public decimal TottTwinOttCoef2;

		[Parameter(MovMethod.VAR)]
			public MovMethod TottMovMethod2;

		[Parameter(200)]
			public int SottPeriodK2;

		[Parameter(200)]
			public int SottPeriodSlowK2;

		[Parameter(2)]
			public int SottOttPeriod2;

		[Parameter(0.5)]
			public decimal SottOttOpt2;

		[Parameter(MovMethod.VAR)]
			public MovMethod SottOttMethod2;

		[Parameter(MovMethod.VAR)]
			public MovMethod SottStosKMethod2;

		[Parameter(2)]
			public int HottlottPeriod2;

		[Parameter(1.4)]
			public decimal HottlottOpt2;

		[Parameter(5)]
			public int HottlottBarSayisi2;

		[Parameter(MovMethod.VAR)]
			public MovMethod HottlottMovMethod2;

		[Parameter(10)]
			public int HighesthighPeriod2;

		[Parameter(2)]
			public int OttPeriod4;

		[Parameter(2.6)]
			public decimal OttOpt4;

		[Parameter(MovMethod.VAR)]
			public MovMethod OttMovMethod4;

		[Parameter(true)]
			public bool OttSupportLine4;

		[Parameter(60)]
			public int TottPeriod3;

		[Parameter(1)]
			public decimal TottOpt3;

		[Parameter(0.001)]
			public decimal TottTwinOttCoef3;

		[Parameter(MovMethod.VAR)]
			public MovMethod TottMovMethod3;

		[Parameter(200)]
			public int SottPeriodK3;

		[Parameter(250)]
			public int SottPeriodSlowK3;

		[Parameter(2)]
			public int SottOttPeriod3;

		[Parameter(0.5)]
			public decimal SottOttOpt3;

		[Parameter(MovMethod.VAR)]
			public MovMethod SottOttMethod3;

		[Parameter(MovMethod.VAR)]
			public MovMethod SottStosKMethod3;

		[Parameter(2)]
			public int HottlottPeriod3;

		[Parameter(1.4)]
			public decimal HottlottOpt3;

		[Parameter(8)]
			public int HottlottBarSayisi3;

		[Parameter(MovMethod.VAR)]
			public MovMethod HottlottMovMethod3;

		[Parameter(5)]
			public int LowestlowPeriod1;

		[Parameter(60)]
			public int TottPeriod4;

		[Parameter(1.2)]
			public decimal TottOpt4;

		[Parameter(0.001)]
			public decimal TottTwinOttCoef4;

		[Parameter(MovMethod.VAR)]
			public MovMethod TottMovMethod4;

		[Parameter(200)]
			public int SottPeriodK4;

		[Parameter(250)]
			public int SottPeriodSlowK4;

		[Parameter(2)]
			public int SottOttPeriod4;

		[Parameter(0.2)]
			public decimal SottOttOpt4;

		[Parameter(MovMethod.VAR)]
			public MovMethod SottOttMethod4;

		[Parameter(MovMethod.VAR)]
			public MovMethod SottStosKMethod4;

		[Parameter(2)]
			public int HottlottPeriod4;

		[Parameter(1.4)]
			public decimal HottlottOpt4;

		[Parameter(11)]
			public int HottlottBarSayisi4;

		[Parameter(MovMethod.VAR)]
			public MovMethod HottlottMovMethod4;

		[Parameter(10)]
			public int LowestlowPeriod2;

		[Parameter(1)]
			public decimal OrderQuantity1;

		[Parameter(1)]
			public decimal OrderQuantity2;

		[Parameter(3)]
		public int Kaldirac;

		OTT ott;
		TOTT tott;
		SOTT sott;
		MatriksIndicator HottLott;
		HighestHigh highestHigh;
		OTT ott2;
		TOTT tott2;
		SOTT sott2;
		MatriksIndicator HottLott2;
		HighestHigh highestHigh2;
		OTT ott3;
		TOTT tott3;
		SOTT sott3;
		MatriksIndicator HottLott3;
		LowestLow lowestLow;
		TOTT tott4;
		SOTT sott4;
		MatriksIndicator HottLott4;
		LowestLow lowestLow2;
		OTT ott4;






		public override void OnInit()
		{

			ott = OTTIndicator(Symbol1, SymbolPeriod1, OHLCType.Close, OttPeriod1, OttOpt1, OttMovMethod1, OttSupportLine1);
			tott = TOTTIndicator(Symbol1, SymbolPeriod1, OHLCType.Close, TottPeriod1, TottOpt1, TottTwinOttCoef1, TottMovMethod1);
			sott = SOTTIndicator(Symbol1, SymbolPeriod1, OHLCType.Close, SottPeriodK1, SottPeriodSlowK1, SottOttPeriod1, SottOttOpt1, SottOttMethod1, SottStosKMethod1);
			HottLott = new HottLott();

			HottLott.SetIndicatorParameters("Period", HottlottPeriod1);
			HottLott.SetIndicatorParameters("Opt", HottlottOpt1);
			HottLott.SetIndicatorParameters("BarSayisi", HottlottBarSayisi1);
			HottLott.SetIndicatorParameters("MovMethod", HottlottMovMethod1); RegisterUserIndicator(HottLott, Symbol1, SymbolPeriod1, OHLCType.Close, 5);

			highestHigh = HighestHighIndicator(Symbol1, SymbolPeriod1, HighesthighPeriod1);
			ott2 = OTTIndicator(Symbol1, SymbolPeriod1, OHLCType.Close, OttPeriod2, OttOpt2, OttMovMethod2, OttSupportLine2);
			tott2 = TOTTIndicator(Symbol1, SymbolPeriod1, OHLCType.Close, TottPeriod2, TottOpt2, TottTwinOttCoef2, TottMovMethod2);
			sott2 = SOTTIndicator(Symbol1, SymbolPeriod1, OHLCType.Close, SottPeriodK2, SottPeriodSlowK2, SottOttPeriod2, SottOttOpt2, SottOttMethod2, SottStosKMethod2);
			HottLott2 = new HottLott();

			HottLott2.SetIndicatorParameters("Period", HottlottPeriod2);
			HottLott2.SetIndicatorParameters("Opt", HottlottOpt2);
			HottLott2.SetIndicatorParameters("BarSayisi", HottlottBarSayisi2);
			HottLott2.SetIndicatorParameters("MovMethod", HottlottMovMethod2); RegisterUserIndicator(HottLott2, Symbol1, SymbolPeriod1, OHLCType.Close, 5);

			highestHigh2 = HighestHighIndicator(Symbol1, SymbolPeriod1, HighesthighPeriod2);
			ott3 = OTTIndicator(Symbol1, SymbolPeriod1, OHLCType.Close, OttPeriod3, OttOpt3, OttMovMethod3, OttSupportLine3);
			tott3 = TOTTIndicator(Symbol1, SymbolPeriod1, OHLCType.Close, TottPeriod3, TottOpt3, TottTwinOttCoef3, TottMovMethod3);
			sott3 = SOTTIndicator(Symbol1, SymbolPeriod1, OHLCType.Close, SottPeriodK3, SottPeriodSlowK3, SottOttPeriod3, SottOttOpt3, SottOttMethod3, SottStosKMethod3);
			HottLott3 = new HottLott();

			HottLott3.SetIndicatorParameters("Period", HottlottPeriod3);
			HottLott3.SetIndicatorParameters("Opt", HottlottOpt3);
			HottLott3.SetIndicatorParameters("BarSayisi", HottlottBarSayisi3);
			HottLott3.SetIndicatorParameters("MovMethod", HottlottMovMethod3); RegisterUserIndicator(HottLott3, Symbol1, SymbolPeriod1, OHLCType.Close, 5);

			lowestLow = LowestLowIndicator(Symbol1, SymbolPeriod1, LowestlowPeriod1);
			tott4 = TOTTIndicator(Symbol1, SymbolPeriod1, OHLCType.Close, TottPeriod4, TottOpt4, TottTwinOttCoef4, TottMovMethod4);
			sott4 = SOTTIndicator(Symbol1, SymbolPeriod1, OHLCType.Close, SottPeriodK4, SottPeriodSlowK4, SottOttPeriod4, SottOttOpt4, SottOttMethod4, SottStosKMethod4);
			HottLott4 = new HottLott();

			HottLott4.SetIndicatorParameters("Period", HottlottPeriod4);
			HottLott4.SetIndicatorParameters("Opt", HottlottOpt4);
			HottLott4.SetIndicatorParameters("BarSayisi", HottlottBarSayisi4);
			HottLott4.SetIndicatorParameters("MovMethod", HottlottMovMethod4); RegisterUserIndicator(HottLott4, Symbol1, SymbolPeriod1, OHLCType.Close, 5);

			lowestLow2 = LowestLowIndicator(Symbol1, SymbolPeriod1, LowestlowPeriod2);
			ott4 = OTTIndicator(Symbol1, SymbolPeriod1, OHLCType.Close, OttPeriod4, OttOpt4, OttMovMethod4, OttSupportLine4);




			SendOrderSequential(true, Side.Buy);
			WorkWithPermanentSignal(true);

			// Gerekli - Kaldıraç			
			SetLeverage(Symbol1, Kaldirac); // kaldıraç oranı			
			SetLeverageType(Symbol1, true); // kaldıraç tipi - true isolated, false cross
			// #Gerekli - Kaldıraç

			// Gerekli - Timestamp
			SetTimerInterval(1);
			// #Gerekli - Timestamp

		}


		public override void OnDataUpdate(BarDataEventArgs barData)
		{


			var barData1 = GetBarData(Symbol1, SymbolPeriod1);
			var ohlcData1 = GetSelectedValueFromBarData(barData1, OHLCType.High);
			var ohlcData2 = GetSelectedValueFromBarData(barData1, OHLCType.Low);

			if (ott.Value[1][ott.CurrentIndex] > ott.Value[0][ott.CurrentIndex])
			{
				if (tott.Value[0][tott.CurrentIndex] > tott.Value[1][tott.CurrentIndex]
					&& sott.Value[0][sott.CurrentIndex] > sott.Value[1][sott.CurrentIndex]
					&& HottLott.Value[0][HottLott.CurrentIndex] < ohlcData1
					&& highestHigh.Value[0][highestHigh.CurrentIndex - 1] < ohlcData1)
				{
					SendMarketOrder(Symbol1, OrderQuantity1, OrderSide.Buy, includeAfterSession:false);
				}
			}
			else
			{
				if (ott2.Value[1][ott2.CurrentIndex] > (ott2.Value[0][ott2.CurrentIndex] + ott2.Value[0][ott2.CurrentIndex -100] - ott3.Value[0][ott3.CurrentIndex -100] + ott2.Value[0][ott2.CurrentIndex - 100]) / 2
					&& tott2.Value[0][tott2.CurrentIndex] > tott2.Value[1][tott2.CurrentIndex]
					&& sott2.Value[0][sott2.CurrentIndex] > sott2.Value[1][sott2.CurrentIndex]
					&& HottLott2.Value[0][HottLott2.CurrentIndex] < ohlcData1
					&& highestHigh2.Value[0][highestHigh2.CurrentIndex - 1] < ohlcData1)
				{
					SendMarketOrder(Symbol1, OrderQuantity1, OrderSide.Buy, includeAfterSession:false);
				}
			}

			if (ott4.Value[1][ott4.CurrentIndex] > ott4.Value[0][ott4.CurrentIndex])
			{
				if (tott3.Value[0][tott3.CurrentIndex] < tott3.Value[2][tott3.CurrentIndex]
					&& sott3.Value[0][sott3.CurrentIndex] < sott3.Value[1][sott3.CurrentIndex]
					&& HottLott3.Value[1][HottLott3.CurrentIndex] > ohlcData2
					&& lowestLow.Value[0][lowestLow.CurrentIndex - 1] > ohlcData2)
				{
					SendMarketOrder(Symbol1, OrderQuantity2, OrderSide.Sell, includeAfterSession:false);
				}
			}
			else
			{
				if (tott4.Value[0][tott4.CurrentIndex] < tott4.Value[2][tott4.CurrentIndex]
					&& sott4.Value[0][sott4.CurrentIndex] < sott4.Value[1][sott4.CurrentIndex]
					&& HottLott4.Value[1][HottLott4.CurrentIndex] > ohlcData2
					&& lowestLow2.Value[0][lowestLow2.CurrentIndex - 1] > ohlcData2)
				{
					SendMarketOrder(Symbol1, OrderQuantity2, OrderSide.Sell, includeAfterSession:false);
				}
			}

		}

		// Gerekli - Timestamp
		public class OrderListTimestamp
		{
			public string ID;
			public string Sembol;
			public decimal Adet;
			public decimal Fiyat;
			public OrdType EmirTipi;
			public OrderSide orderSide;
			public string EmirYonu;
			public DateTime TetiklenmeZamani;
			public int Sayac;
			public bool AktifMI;
		}

		Dictionary<string, OrderListTimestamp> timestampDict = new Dictionary<string, OrderListTimestamp>();

		[Parameter(3)]
		public int AyniEmirKacSeferGonderilsin;

		[Parameter(10)]
		public int KacSaniyeSonraTekrarGonderilsin;

		string orderIDTimestamp = string.Empty;
		// #Gerekli - Timestamp


		public override void OnTimer()
		{
			// Gerekli - Timestamp
			var tutt = timestampDict.Where(x => x.Value.AktifMI == true && DateTime.Now >= x.Value.TetiklenmeZamani);

			if (tutt.Count() >0)
			{
				foreach (var deger in tutt)
				{
					LastOrderSide.Obj = deger.Value.orderSide == OrderSide.Buy? Side.Sell:Side.Buy;

					if (deger.Value.EmirTipi.Obj == OrdType.Limit)
					{
						orderIDTimestamp = SendLimitOrder(deger.Value.Sembol, deger.Value.Adet, deger.Value.orderSide, deger.Value.Fiyat);
						Debug(deger.Value.EmirYonu + " emri tekrar gönderildi.");
					}else if (deger.Value.EmirTipi.Obj == OrdType.Market)
					{
						orderIDTimestamp = SendMarketOrder(deger.Value.Sembol, deger.Value.Adet, deger.Value.orderSide);
						Debug(deger.Value.EmirYonu + " emri tekrar gönderildi.");
					}

					deger.Value.ID = orderIDTimestamp;
					deger.Value.AktifMI = false;
					timestampDict[orderIDTimestamp] = deger.Value;
					timestampDict.Remove(deger.Key);

				}
			}
		}
		// #Gerekli - Timestamp

		public override void OnOrderUpdate(IOrder order)
		{
			// Gerekli - Timestamp
			if (order.OrdStatus.Obj == OrdStatus.Filled)
			{
				if (timestampDict.ContainsKey(order.CliOrdID))
				{
					timestampDict.Remove(order.CliOrdID);
					Debug("Timestamp hatasına takılan emriniz gerçekleşti.");
				}
			}

			if (order.OrdStatus.Obj == OrdStatus.Rejected)
			{
				if (!timestampDict.ContainsKey(order.CliOrdID))
				{
					OrderListTimestamp orderList = new OrderListTimestamp();
					orderList.ID = order.CliOrdID;
					orderList.Sembol = order.Symbol;
					orderList.Adet = order.OrderQty;
					orderList.Fiyat = order.Price;
					orderList.EmirTipi = order.OrdType;
					orderList.TetiklenmeZamani = DateTime.Now;
					orderList.Sayac = 0;
					orderList.AktifMI = false;

					if (order.Side.Obj == Side.Buy)
					{
						orderList.orderSide = OrderSide.Buy;
						orderList.EmirYonu = "Alış";
					}else
					{
						orderList.orderSide = OrderSide.Sell;
						orderList.EmirYonu = "Satış";
					}

					timestampDict[order.CliOrdID] = orderList;
				}

				if (order.Text.Contains("Timestamp"))
				{
					if (timestampDict.ContainsKey(order.CliOrdID))
					{
						if (timestampDict[order.CliOrdID].Sayac < AyniEmirKacSeferGonderilsin)
						{
							timestampDict[order.CliOrdID].TetiklenmeZamani = DateTime.Now.AddSeconds(KacSaniyeSonraTekrarGonderilsin);
							timestampDict[order.CliOrdID].Sayac++;
							timestampDict[order.CliOrdID].AktifMI = true;

							Debug("Emir Timestamp hatasından dolayı iptal oldu tekrar gönderilecek");
						}else
						{
							timestampDict.Remove(order.CliOrdID);
							Debug("Aynı emir üst üste " + AyniEmirKacSeferGonderilsin + " defa gönderildi.");
						}
					}
				}
			}
			// #Gerekli - Timestamp			
		}
	}
}

4 Yorum

Merhaba, kripto için değer girişleri neler olmalıdır? yardımcı olursanız sevınırım

  • 29.08.2022 18:06
  • 0

merhabalar, bu sistem ile Anıl Bey'in diğer sistemleri ile ilgili sitenizde toplam 3 adet sistem var. Hepsi TOTT ve SOTT yapısı ile kurgulanmış. Ancak aralarında şöyle bir farklılık var; if'li cümle kalıplarında [] ifadesi içine aynı kalıplar için bazen 0,1 veya 2 giriliyor. Bu konuda bir sistematik yok ve bu nedenle Prime'da yaptığım backtestler ile İQ'da yaptığım testler uyuşmuyor, ilgisiz sonuçlar geliyor karşıma. Bu kalıpların doğrusu nedir ?

  • 31.08.2022 01:13
  • 1

Ben de açıkçası daha prime'daki optleri buraya taşıyamadım... Zira fırsatçı için giriş değerleri yok...

  • 07.09.2022 22:43
  • 0

Merhaba, alternatif olarak buradaki sistemleri inceleyebilirsiniz. https://www.algokutuphanesi.com/Sistem/detay/MatriksIq/FirsatciTrend 4Bölge LONG https://www.algokutuphanesi.com/Sistem/detay/MatriksIq/FirsatciTrend 4Bölge SHORT

  • 04.11.2022 10:52
  • 1