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 FırsatcıTrendLong_ : MatriksAlgo
{
/// <summary>
/// Sadece LONG işlem yapmaktadır.
/// Strateji BIST - VIOP - BINANCE (timestamp kontrollü) için uygundur.
/// ZamanKullanilsinMI parametresi EVET seçildiğinde zamana göre çalışır. Hayır seçildiğinde zamandan bağımsız olrak çalışır.
/// MAJOR trend parametresi bir kez girilmektedir.
/// kaldıraç,AyniEmirKacSeferGonderilsin ve KacSaniyeSonraTekrarGonderilsin parametreleri sadece strateji Binance'de çalıştırıldığında geçerlidir.
///
/// Parametre Girişleri 4 bölge olarak girilmektedir.
///
/// _________________________________/ LONG \________________________________________1.BÖLGE
//if(MOV(C,15,VAR)>OTT(C,15,7),
//MOV(C,25,VAR)>OTT(C,25,0.6)*(1+0.025)
//AND STOSK(300,150,33,VAR)+1000>OTT(STOSK(300,150,33,VAR)+1000,2,0.4)
//AND H>OTT(HHV(H,16/2),2,0.4)
//AND H>REF(HHV(H,16),-1),
/// _________________________________________________________________________________2.BÖLGE
//MOV(C,15,VAR)>(OTT(C,15,3)+REF(OTT(C,15,3)-(OTT(C,15,7)-OTT(C,15,3)),-100))/2 AND
//MOV(C,15,VAR)>OTT(C,15,0.6)*(1+0.0006)
//AND STOSK(150,150,33,VAR)+1000>OTT(STOSK(150,150,33,VAR)+1000,2,0.3)
//AND H>OTT(HHV(H,22/2),2,0.4) AND H>REF(HHV(H,22),-1))
/// ____________________________/ LONG KAPAMA \_______________________________________3.BÖLGE
//if(MOV(C,15,VAR)>OTT(C,15,7),
//MOV(C,30,VAR)<OTT(C,30,0.6)*(1-0.025)
//AND STOSK(250,150,33,VAR)+1000<OTT(STOSK(250,150,33,VAR)+1000,2,0.2)
//AND L<OTT(LLV(L,46/2),2,0.4)
//AND L<REF(LLV(L,46),-1),
/// __________________________________________________________________________________4.BÖLGE
//MOV(C,15,VAR)<OTT(C,15,0.6)*(1-0.0008)
//AND STOSK(150,150,33,VAR)+1000<OTT(STOSK(150,150,33,VAR)+1000,2,0.4)
//AND L<OTT(LLV(L,46/2),2,0.4) AND L<REF(LLV(L,46),-1))
/// </summary>
[SymbolParameter("EREGL")]
public string Symbol1;
[Parameter(SymbolPeriod.Min)]
public SymbolPeriod SymbolPeriod1;
/// _________________________________/ LONG \________________________________________1.BÖLGE
// if(MOV(C,20,VAR)>OTT(C,20,7),
[Parameter(15)]
public int MajorTrend_OttPeriod;
[Parameter(7)]
public decimal MajorTrend_OttOPT;
//MOV(C,40,VAR)>OTT(C,40,0.6)*(1+0.0004)
[Parameter(25)]
public int MinorTrend_TottPeriod;
[Parameter(0.6)]
public decimal MinorTrend_TottOPT;
[Parameter(0.025)]
public decimal MinorTrend_TottTwinOttCoef;
//AND STOSK(300,200,33,VAR)+1000>OTT(STOSK(300,200,33,VAR)+1000,2,0.4)
[Parameter(300)]
public int MinorTrend_SottPeriodK;
[Parameter(150)]
public int MinorTrend_SottPeriodSlowK;
[Parameter(2)]
public int MinorTrend_SottOttPeriod;
[Parameter(0.4)]
public decimal MinorTrend_SottOttOPT;
//AND H>OTT(HHV(H,16/2),2,0.4)
[Parameter(16)] // buraya yazılan periyot kod içerisinde 2 ye bölünür. --> 16/2
public int MinorTrend_HHV;
[Parameter(2)]
public int MinorTrend_HOttPeriod;
[Parameter(0.4)]
public decimal MinorTrend_HOttOpt;
//AND H>REF(HHV(H,16),-1),
[Parameter(16)]
public int MinorTrend_REFHHV;
/// ______________________________________/ Fırsatçı Trend \___________________________________________2.BÖLGE
//MOV(C,20,VAR)>(OTT(C,20,3)+REF(OTT(C,20,3)-(OTT(C,20,7)-OTT(C,20,3)),-100))/2
[Parameter(15)]
public int FirsatciTrend_OttPeriod;
[Parameter(3)]
public decimal FirsatciTrend_OttOpt;
//AND MOV(C,20,VAR)>OTT(C,20,0.6)*(1+0.0006)
[Parameter(20)]
public int MinorTrend2_TottPeriod;
[Parameter(0.6)]
public decimal MinorTrend2_TottOpt;
[Parameter(0.0006)]
public decimal MinorTrend2_TottTwinOttCoef;
//AND STOSK(200,200,33,VAR)+1000>OTT(STOSK(200,200,33,VAR)+1000,2,0.3)
[Parameter(200)]
public int MinorTrend2_SottPeriodK;
[Parameter(200)]
public int MinorTrend2_SottPeriodSlowK;
[Parameter(2)]
public int MinorTrend2_SottOttPeriod;
[Parameter(0.3)]
public decimal MinorTrend2_SottOttOpt;
//AND H>OTT(HHV(H,22/2),2,0.4)
[Parameter(22)]
public int MinorTrend2_HHV;
[Parameter(2)]
public int MinorTrend2_HOttPeriod;
[Parameter(0.4)]
public decimal MinorTrend2_HOttOpt;
//AND H>REF(HHV(H,22),-1))
[Parameter(22)]
public int MinorTrend2_REFHHV;
///
/// ____________________________/ LONG KAPAMA \_______________________________________3.BÖLGE
// MOV(C,30,VAR)<OTT(C,30,0.6)*(1-0.0004)
[Parameter(30)]
public int MinorTrend3_TottPeriod;
[Parameter(0.6)]
public decimal MinorTrend3_TottOpt;
[Parameter(0.0004)]
public decimal MinorTrend3_TottTwinOttCoef;
//AND STOSK(250,200,33,VAR)+1000<OTT(STOSK(250,200,33,VAR)+1000,2,0.2)
[Parameter(250)]
public int MinorTrend3_SottPeriodK;
[Parameter(200)]
public int MinorTrend3_SottPeriodSlowK;
[Parameter(2)]
public int MinorTrend3_SottOttPeriod;
[Parameter(0.2)]
public decimal MinorTrend3_SottOttOpt;
//AND L<OTT(LLV(L,46/2),2,0.4)
[Parameter(46)]
public int MinorTrend3_LLV;
[Parameter(2)]
public int MinorTrend3_LOttPeriod;
[Parameter(0.4)]
public decimal MinorTrend3_LOttOpt;
// AND L<REF(LLV(L,46),-1),
[Parameter(46)]
public int MinorTrend3_REFLLV;
/// __________________________________________________________________________________4.BÖLGE
//MOV(C,20,VAR)<OTT(C,20,0.6)*(1-0.0008)
[Parameter(20)]
public int MinorTrend4_TottPeriod;
[Parameter(0.6)]
public decimal MinorTrend4_TottOpt;
[Parameter(0.0008)]
public decimal MinorTrend4_TottTwinOttCoef;
//AND STOSK(200,200,33,VAR)+1000<OTT(STOSK(200,200,33,VAR)+1000,2,0.4)
[Parameter(200)]
public int MinorTrend4_SottPeriodK;
[Parameter(200)]
public int MinorTrend4_SottPeriodSlowK;
[Parameter(2)]
public int MinorTrend4_SottOttPeriod;
[Parameter(0.4)]
public decimal MinorTrend4_SottOttOpt;
//AND L<OTT(LLV(L,46/2),2,0.4)
[Parameter(46)]
public int MinorTrend4_LLV;
[Parameter(2)]
public int MinorTrend4_LOttPeriod;
[Parameter(0.4)]
public decimal MinorTrend4_LOttOpt;
//AND L<REF(LLV(L,46),-1))
[Parameter(46)]
public int MinorTrend4_REFLLV;
[Parameter(1)]
public decimal OrderQuantity;
OTT ott;
TOTT tott;
HighestHigh highestHigh;
OTT ott2;
HighestHigh highestHigh2;
SOTT sott;
OTT ott3;
TOTT tott2;
SOTT sott2;
HighestHigh highestHigh3;
OTT ott4;
HighestHigh highestHigh4;
TOTT tott3;
SOTT sott3;
LowestLow lowestLow;
OTT ott5;
LowestLow lowestLow2;
TOTT tott4;
SOTT sott4;
LowestLow lowestLow3;
OTT ott6;
LowestLow lowestLow4;
// Gerekli zaman aralığı
public enum ZamanKullanilsinMI
{
EVET,
HAYIR
}
[Parameter(ZamanKullanilsinMI.EVET)]
public ZamanKullanilsinMI Zaman;
public bool ZamanKontrol;
[Parameter("10:03:00")]
public string Baslangic;
[Parameter("17:58:00")]
public string Bitis;
public bool FX_ZamanindaMI(DateTime zaman)
{
var bas = TimeSpan.Parse(Baslangic);
var bit = TimeSpan.Parse(Bitis);
return (zaman.TimeOfDay >= bas && zaman.TimeOfDay <= bit);
}
// # Gerekli zaman aralığı
[Parameter(3)]
public int Kaldirac;
public override void OnDataUpdate(BarDataEventArgs barData)
{
var ZamanKontrol = Zaman == ZamanKullanilsinMI.EVET ? FX_ZamanindaMI(barData.BarData.Dtime) == true? true:false: true;
var barData1 = GetBarData(Symbol1, SymbolPeriod1);
var ohlcData1 = GetSelectedValueFromBarData(barData1, OHLCType.High);
var ohlcData2 = GetSelectedValueFromBarData(barData1, OHLCType.Low);
// LONG
if (ZamanKontrol && ott.Value[1][ott.CurrentIndex] > ott.Value[0][ott.CurrentIndex])
{
if (LastOrderSide.Obj != Side.Buy
&& tott.Value[0][tott.CurrentIndex] > tott.Value[1][tott.CurrentIndex]
&& sott.Value[0][sott.CurrentIndex] > sott.Value[1][sott.CurrentIndex]
&& ott2.Value[0][ott2.CurrentIndex] < ohlcData1
&& highestHigh2.Value[0][highestHigh2.CurrentIndex - 1] < ohlcData1)
{
SendMarketOrder(Symbol1, OrderQuantity, OrderSide.Buy, includeAfterSession:false);
Debug("****LONG ****");
}
}else if (ZamanKontrol && LastOrderSide.Obj != Side.Buy
&& ott3.Value[1][ott3.CurrentIndex] > (ott3.Value[0][ott3.CurrentIndex] + ott3.Value[0][ott3.CurrentIndex -100] - ott.Value[0][ott.CurrentIndex -100] + ott3.Value[0][ott3.CurrentIndex - 100]) / 2
&& tott2.Value[0][tott2.CurrentIndex] > tott2.Value[1][tott2.CurrentIndex]
&& sott2.Value[0][sott2.CurrentIndex] > sott2.Value[1][sott2.CurrentIndex]
&& ott4.Value[0][ott4.CurrentIndex] < ohlcData1
&& highestHigh4.Value[0][highestHigh4.CurrentIndex - 1] < ohlcData1)
{
SendMarketOrder(Symbol1, OrderQuantity, OrderSide.Buy, includeAfterSession:false);
Debug("****LONG ****");
}
// LONG KAPAT
if (ZamanKontrol && ott.Value[1][ott.CurrentIndex] > ott.Value[0][ott.CurrentIndex])
{
if (LastOrderSide.Obj != Side.Sell
&& tott3.Value[0][tott3.CurrentIndex] < tott3.Value[2][tott3.CurrentIndex]
&& sott3.Value[0][sott3.CurrentIndex] < sott3.Value[1][sott3.CurrentIndex]
&& ott5.Value[0][ott5.CurrentIndex] > ohlcData2
&& lowestLow2.Value[0][lowestLow2.CurrentIndex - 1] > ohlcData2)
{
SendMarketOrder(Symbol1, OrderQuantity, OrderSide.Sell, includeAfterSession:false);
Debug("****LONG KAPAMA ****");
}
}
else if (ZamanKontrol && LastOrderSide.Obj != Side.Sell
&& tott4.Value[0][tott4.CurrentIndex] < tott4.Value[2][tott4.CurrentIndex]
&& sott4.Value[0][sott4.CurrentIndex] < sott4.Value[1][sott4.CurrentIndex]
&& ott6.Value[0][ott6.CurrentIndex] > ohlcData2
&& lowestLow4.Value[0][lowestLow4.CurrentIndex - 1] > ohlcData2)
{
SendMarketOrder(Symbol1, OrderQuantity, OrderSide.Sell, includeAfterSession:false);
Debug("****LONG KAPAMA ****");
}
}
public override void OnInit()
{
ott = OTTIndicator(Symbol1, SymbolPeriod1, OHLCType.Close, MajorTrend_OttPeriod, MajorTrend_OttOPT, MovMethod.VAR, true);
tott = TOTTIndicator(Symbol1, SymbolPeriod1, OHLCType.Close, MinorTrend_TottPeriod, MinorTrend_TottOPT, MinorTrend_TottTwinOttCoef, MovMethod.VAR);
highestHigh = HighestHighIndicator(Symbol1, SymbolPeriod1, MinorTrend_HHV / 2);
ott2 = OTTIndicator(highestHigh, MinorTrend_HOttPeriod, MinorTrend_HOttOpt, MovMethod.VAR, true);
highestHigh2 = HighestHighIndicator(Symbol1, SymbolPeriod1, MinorTrend_REFHHV);
sott = SOTTIndicator(Symbol1, SymbolPeriod1, OHLCType.Close, MinorTrend_SottPeriodK, MinorTrend_SottPeriodSlowK, MinorTrend_SottOttPeriod, MinorTrend_SottOttOPT, MovMethod.VAR, MovMethod.VAR);
ott3 = OTTIndicator(Symbol1, SymbolPeriod1, OHLCType.Close, FirsatciTrend_OttPeriod, FirsatciTrend_OttOpt, MovMethod.VAR, true);
tott2 = TOTTIndicator(Symbol1, SymbolPeriod1, OHLCType.Close, MinorTrend2_TottPeriod, MinorTrend2_TottOpt, MinorTrend2_TottTwinOttCoef, MovMethod.VAR);
sott2 = SOTTIndicator(Symbol1, SymbolPeriod1, OHLCType.Close, MinorTrend2_SottPeriodK, MinorTrend2_SottPeriodSlowK, MinorTrend2_SottOttPeriod, MinorTrend2_SottOttOpt, MovMethod.VAR, MovMethod.VAR);
highestHigh3 = HighestHighIndicator(Symbol1, SymbolPeriod1, MinorTrend2_HHV / 2);
ott4 = OTTIndicator(highestHigh3, MinorTrend2_HOttPeriod, MinorTrend2_HOttOpt, MovMethod.VAR, true);
highestHigh4 = HighestHighIndicator(Symbol1, SymbolPeriod1, MinorTrend2_REFHHV);
tott3 = TOTTIndicator(Symbol1, SymbolPeriod1, OHLCType.Close, MinorTrend3_TottPeriod, MinorTrend3_TottOpt, MinorTrend3_TottTwinOttCoef, MovMethod.VAR);
sott3 = SOTTIndicator(Symbol1, SymbolPeriod1, OHLCType.Close, MinorTrend3_SottPeriodK, MinorTrend3_SottPeriodSlowK, MinorTrend3_SottOttPeriod, MinorTrend3_SottOttOpt, MovMethod.VAR, MovMethod.VAR);
lowestLow = LowestLowIndicator(Symbol1, SymbolPeriod1, MinorTrend3_LLV / 2);