kullandığım strateji içerisine iz süren stoploss ekledim ancak çalışmadığını fark ettim. Nerede hata yapıyorum söyler misiniz ?
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;
namespace Matriks.Lean.Algotrader
{
public class AlphaTrendAlgo : MatriksAlgo
{
[SymbolParameter("FGARAN")]
public string Symbol;
[Parameter(SymbolPeriod.Min5)]
public SymbolPeriod SymbolPeriod;
[Parameter(5)]
public decimal BuyOrderQuantity;
[Parameter(5)]
public decimal SellOrderQuantity;
[Parameter(1)]
public decimal AlphatrendCoeff1;
[Parameter(14)]
public int AlphatrendPeriod1;
[Parameter(Momentum.MFI)]
public Momentum AlphatrendMomentum1;
[Parameter(3)]
public int KaldiracOrani;
[Parameter(6)]
public decimal TrailingStopLevel1;
[Parameter(1)]
public decimal StopLevel1;
MatriksIndicator AlphaTrend_IQ;
public override void OnDataUpdate(BarDataEventArgs barData)
{
if (CrossBelow(AlphaTrend_IQ, AlphaTrend_IQ, 0, 1))
{
TrailingStopLoss(Symbol, SyntheticOrderPriceType.Percent, TrailingStopLevel1);
TakeProfit(Symbol, SyntheticOrderPriceType.Percent, StopLevel1);
FX_Alis();
}
if (CrossAbove(AlphaTrend_IQ, AlphaTrend_IQ, 0, 1))
{
TrailingStopLoss(Symbol, SyntheticOrderPriceType.Percent, TrailingStopLevel1);
TakeProfit(Symbol, SyntheticOrderPriceType.Percent, StopLevel1);
FX_Satis();
}
}
public override void OnInit()
{
AddSymbol(Symbol, SymbolPeriod);
AlphaTrend_IQ = new AlphaTrend_IQ();
AlphaTrend_IQ.SetIndicatorParameters("Coeff", AlphatrendCoeff1);
AlphaTrend_IQ.SetIndicatorParameters("Period", AlphatrendPeriod1);
AlphaTrend_IQ.SetIndicatorParameters("Momentum", AlphatrendMomentum1); RegisterUserIndicator(AlphaTrend_IQ, Symbol, SymbolPeriod, OHLCType.Close, 5);
// Gerekli
WorkWithPermanentSignal(true);
if (AcigaSatisYapilsin)
{
SendOrderSequential(true, Side.All);
SendOrderSequentialForShort(true, Side.All);
}else
{
SendOrderSequential(true, Side.Buy);
}
// #Gerekli
// kaldıraç oranı
SetLeverage(Symbol, KaldiracOrani);
// kaldıraç tipi – true isolated, false cross
SetLeverageType(Symbol, true);
// Gerekli
}
[Parameter(false)]
public bool AcigaSatisYapilsin;
[Parameter(false)]
public bool AksamSeansiniDahilEt;
List<string> orderIDList = new List<string>();
public void FX_Alis()
{
string _orderID = string.Empty; ;
decimal _quantity = 0;
if (LastOrderSide.Obj != Side.Buy)
{
if (LastOrderSide.Obj == Side.All || !AcigaSatisYapilsin)
{
_orderID = SendMarketOrder(Symbol, BuyOrderQuantity, OrderSide.Buy, includeAfterSession:AksamSeansiniDahilEt);
_quantity = BuyOrderQuantity;
}else
{
if (LastOrderSideForShort.Obj == Side.All)
{
_orderID = SendMarketOrder(Symbol, BuyOrderQuantity, OrderSide.Buy, includeAfterSession:AksamSeansiniDahilEt);
_quantity = BuyOrderQuantity;
}else
{
_orderID = SendMarketOrder(Symbol, BuyOrderQuantity * 2, OrderSide.Buy, includeAfterSession:AksamSeansiniDahilEt);
_quantity = BuyOrderQuantity * 2;
}
}
if (_orderID != string.Empty && _quantity != 0)
{
orderIDList.Add(_orderID);
Debug("Alış emri gönderildi.[ " + _quantity + " adet ]");
LastOrderSide.Obj = Side.Buy;
LastOrderSideForShort.Obj = Side.Buy;
}
}
}
public void FX_Satis()
{
string _orderID = string.Empty; ;
decimal _quantity = 0;
if (LastOrderSide.Obj != Side.Sell)
{
if (LastOrderSide.Obj == Side.All || !AcigaSatisYapilsin)
{
_orderID = SendMarketOrder(Symbol, SellOrderQuantity, OrderSide.Sell, includeAfterSession:AksamSeansiniDahilEt);
_quantity = SellOrderQuantity;
}else
{
if (LastOrderSideForShort.Obj == Side.All)
{
_orderID = SendMarketOrder(Symbol, SellOrderQuantity, OrderSide.Sell, includeAfterSession:AksamSeansiniDahilEt);
_quantity = SellOrderQuantity;
}else
{
_orderID = SendMarketOrder(Symbol, SellOrderQuantity * 2, OrderSide.Sell, includeAfterSession:AksamSeansiniDahilEt);
_quantity = SellOrderQuantity * 2;
}
}
if (_orderID != string.Empty && _quantity != 0)
{
orderIDList.Add(_orderID);
Debug("Satış emri gönderildi.[ " + _quantity + " adet ]");
LastOrderSide.Obj = Side.Sell;
LastOrderSideForShort.Obj = Side.Sell;
}
}
}
public override void OnOrderUpdate(IOrder order)
{
if (order.OrdStatus.Obj == OrdStatus.Filled)
{
// Senntetik emirler tanımlanıyor
// StopLoss(Symbol, SyntheticOrderPriceType.Percent, 1);
// TakeProfit(Symbol, SyntheticOrderPriceType.Percent, 1);
if (!orderIDList.Contains(order.CliOrdID) && AcigaSatisYapilsin)
{
LastOrderSideForShort.Obj = Side.All;
Debug("Sentetik emir tetiklendi");
}
}
}
// #Gerekli
}
}