"burada benim paramın %sel olarak ne kadarı ile alım satım yapmasına izin verdirebiliyormuyum." bunu strateji icerisine kodlayarak yapabilirsiniz. Forumda bakiye vb. terimleri aratarak, belirlenen miktarda bakiye kullanilmasi uzerine ornekler bulabilirsiniz.
Bakiyeye gore islem yapan bir kod ornegi de asagida bulabilirsiniz.
using System;
using System.Collections.Generic;
using System.Linq;
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
{
public class BakiyeyeGoreAlSat : MatriksAlgo
{
[SymbolParameter("TUPRS")]
public string Symbol;
[Parameter(SymbolPeriod.Min5)]
public SymbolPeriod SymbolPeriod;
[Parameter(3)]
public int Period;
[Parameter(2)]
public decimal Percentage;
MOST most;
[Parameter(10000)]
public decimal Balance;
[Parameter(0)]
public decimal StartQuantity;
public decimal Amount;
public decimal Quantity;
public bool BalanceControl = true;
[Parameter(true)]
public bool HisseSenedi;
public override void OnInit()
{
most = MOSTIndicator(Symbol, SymbolPeriod, OHLCType.Close, Period, Percentage, MovMethod.Exponential);
AddSymbol(Symbol, SymbolPeriod);
WorkWithPermanentSignal(true);
SendOrderSequential(false);
}
public override void OnDataUpdate(BarDataEventArgs barData)
{
var barDataModel = GetBarData();
var Close = barData.BarData.Close;
if (HisseSenedi)
{
BalanceControl = (Math.Floor(Balance / Close) >0) ? true: false;
}
if (Close>Ref(barDataModel, OHLCType.Close, 1) && BalanceControl == true && Balance > 0.00000001m)
{
if (HisseSenedi)
{
Quantity = Math.Floor(Balance / Close);
}else
{
Quantity = Balance / Close;
}
Amount = Quantity * Close;
Balance -= Amount;
SendMarketOrder(Symbol, Quantity, (OrderSide.Buy));
Quantity += StartQuantity;
StartQuantity = 0;
Debug("Alış Sinayli Oluştu. Fiyat: " + Close + " - Adet: " + Quantity + " - Tutar: " + Amount + " - Kalan Bakiye: " + Balance);
}
else if (Close>Ref(barDataModel, OHLCType.Close, 1) && (BalanceControl == false || Balance == 0))
{
Debug("Alış sinyali oluştu. Bakiyeniz yetersiz. Kalan Bakiye: " + Balance);
}
if (Close<Ref(barDataModel, OHLCType.Close, 1) && (Quantity != 0 || StartQuantity != 0))
{
Quantity += StartQuantity;
Amount = Quantity * Close;
Balance += Amount;
SendMarketOrder(Symbol, Quantity, (OrderSide.Sell));
Debug("Satış sinyali oluştu. Fiyat: " + Close + " - Adet: " + Quantity + " - Tutar: " + Amount + " - Kalan Bakiye: " + Balance);
Quantity = 0;
StartQuantity = 0;
}else if (Close<Ref(barDataModel, OHLCType.Close, 1) && Quantity == 0)
{
Debug("Satış sinyali oluştu. Satılacak enstrüman yok. Kalan Bakiye: " + Balance);
}
}
}
}