Merhabalar,
Dilerseniz aşağıdaki yapıyı inceleyebilirsiniz.
using System;
using System.Collections.Generic;
using System.Linq;
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 Test2 : MatriksAlgo
{
[SymbolParameter("GARAN")]
public string Symbol;
[Parameter(SymbolPeriod.Min5)]
public SymbolPeriod SymbolPeriod;
[Parameter(10)]
public decimal BuyOrderQuantity;
[Output]
public bool AktifMI = false;
OTT ott;
public override void OnInit()
{
ott = OTTIndicator(Symbol, SymbolPeriod, OHLCType.Close, 2, 1.4m, MovMethod.VAR, true);
SendOrderSequential(true, Side.Buy);
WorkWithPermanentSignal(true);
SetTimerInterval(1);
}
public override void OnTimer()
{
if (AktifMI)
{
var barDataModel = GetBarData();
var close = barDataModel.Close[barDataModel.Close.Count];
var tut=kademeliKarAlListesi.Where(x=> x.Key>=close);
if(tut.Count()>0){
foreach(var deger in tut){
LastOrderSide.Obj=Side.Buy;
SendMarketOrder(Symbol,deger.Value,OrderSide.Sell);
kalanLot-=deger.Value;
kademeliKarAlListesi.Remove(deger.Key);
LastOrderSide.Obj=Side.Buy;
}
}
}
}
public override void OnDataUpdate(BarDataEventArgs barData)
{
if (CrossAbove(ott, ott, 1, 0))
{
SendMarketOrder(Symbol, BuyOrderQuantity, OrderSide.Buy);
Debug("Alış gönderildi.");
AktifMI=true;
}
if (CrossBelow(ott, ott, 1, 0) && kalanLot>0)
{
SendMarketOrder(Symbol, kalanLot, OrderSide.Sell);
Debug("Satış gönderildi.");
AktifMI=false;
kalanLot=decimal.MinValue;
}
}
decimal kalanLot = decimal.MinValue;
Dictionary<decimal, decimal> kademeliKarAlListesi = new Dictionary<decimal, decimal>();
public override void OnOrderUpdate(IOrder order)
{
if (order.OrdStatus.Obj == OrdStatus.Filled && order.Side.Obj == Side.Buy)
{
kademeliKarAlListesi[order.Price * 1.10m] = Math.Ceiling(order.OrderQty * 0.25m);
kademeliKarAlListesi[order.Price * 1.30m] = Math.Ceiling(order.OrderQty * 0.25m);
kalanLot = order.OrderQty;
}
}
}
}
İyi çalışmalar.