Merhabalar,
Örnek olması açısından Trailing Stoploss için aşağıdaki örneği hazırladık.
using System;
using System.Collections.Generic;
using System.Linq;
using Matriks.Data.Symbol;
using System.Windows.Media;
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 TrailingStopLoss : MatriksAlgo
{
[SymbolParameter("XU100")]
public string Symbol;
[Parameter(SymbolPeriod.Day)]
public SymbolPeriod SymbolPeriod;
[Parameter(5)]
public int SMAPeriod;
[Parameter(5)]
public decimal OrderQuantity;
[Parameter(5)]
public decimal Percent;
[Parameter(0.01)]
public decimal PricePoint;
[Parameter(true)]
public bool PricePoint_or_Percent;
SMA sma;
public override void OnInit()
{
sma = SMAIndicator(Symbol, SymbolPeriod, OHLCType.Close, SMAPeriod);
AddSymbol(Symbol, SymbolPeriod);
WorkWithPermanentSignal(true);
}
SyntheticOrderPriceType type;
decimal stopLevel;
ISyntheticOrderPrices trailingstop = null;
public override void OnDataUpdate(BarDataEventArgs barData)
{
var barDataModel = GetBarData();
var close = barDataModel.Close[barData.BarDataIndex];
if (PricePoint_or_Percent)
{
stopLevel = PricePoint;
type = SyntheticOrderPriceType.PricePoint;
}
if (!PricePoint_or_Percent)
{
stopLevel = Percent;
type = SyntheticOrderPriceType.Percent;
}
if (CrossAbove(barDataModel, sma, OHLCType.Close))
{
SendMarketOrder(Symbol, OrderQuantity, (OrderSide.Buy));
Debug("Alış Emri Gönderildi");
Debug("Close : " + close);
Debug("Sma : " + sma.CurrentValue);
trailingstop = TrailingStopLoss(barDataModel.SymbolName, type, stopLevel);
Debug("TrailingStopLoss => " + trailingstop);
Debug("*****************************************************");
}
if (CrossBelow(barDataModel, sma, OHLCType.Close))
{
SendMarketOrder(Symbol, OrderQuantity, (OrderSide.Sell));
Debug("Satış Emri Gönderildi");
Debug("Close : " + close);
Debug("Sma : " + sma.CurrentValue);
trailingstop = TrailingStopLoss(barDataModel.SymbolName, type, stopLevel);
Debug("TrailingStopLoss => " + trailingstop);
Debug("*****************************************************");
}
}
}
}
İyi çalışmalar