0 beğenilme 0 beğenilmeme
250 kez görüntülendi
Merhaba ott-slow stratejisine stoploss ekledim fakat backtestte çalışıyor fakat test ortamında çalışmıyor.

yardımcı olurmusunuz teşkkür ederim...

 

 

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 OTT_STOKASTIK_SLOW : MatriksAlgo

{

// Strateji çalıştırılırken kullanacağımız parametreler. Eğer sembolle ilgili bir parametre ise,

// "SymbolParameter" ile, değilse "Parameter" ile tanımlama yaparız. Parantez içindeki değerler default değerleridir.

 

[SymbolParameter("GARAN")]

public string Symbol;

 

 

[Parameter(SymbolPeriod.Min5)]

public SymbolPeriod SymbolPeriod;

 

[Parameter(1000)]

public decimal BuyOrderQuantity;

 

[Parameter(1000)]

public decimal SellOrderQuantity;

 

[Parameter(1)]

public int Period;

 

[Parameter(1.7)]

public decimal Percentage;

 

[Parameter(1)]

public int StosPeriodK;

 

[Parameter(2)]

public int StosPeriodD;

 

[Parameter(2)]

public int StosPeriodSlowK;

 

[Parameter(true)]

public bool AcigaSatisYapilsin;

 

//Burdaki değer ile yüzdeli stoploss kurulur.

[Parameter(1.5)]

public decimal Zarar_Durdur_Yuzdesi;

 

public int FirstRun = 0;

int realposition = 0;

public int systemposition = 0;

 

 

OTT ott;

 

 

bool islemde = false;

 

StochasticSlow stos;

 

 

public override void OnInit()

{

stos = StochasticSlowIndicator(Symbol, SymbolPeriod, OHLCType.Close, StosPeriodK, StosPeriodD, StosPeriodSlowK, MovMethod.Exponential);

 

ott = OTTIndicator(Symbol, SymbolPeriod, OHLCType.Close, Period, Percentage, MovMethod.VAR, true);

 

 

AddSymbol(Symbol, SymbolPeriod);

 

 

// Algoritmanın kalıcı veya geçici sinyal ile çalışıp çalışmayacağını belirleyen fonksiyondur.

// true geçerseniz algoritma sadece yeni bar açılışlarında çalışır, bu fonksiyonu çağırmazsanız veya false geçerseniz her işlem olduğunda algoritma tetiklenir.

WorkWithPermanentSignal(true);

 

//Eger backtestte emri bir al bir sat seklinde gonderilmesi isteniyor bu true set edilir.

//Alttaki satırı silerek veya false geçerek emirlerin sirayla gönderilmesini engelleyebilirsiniz.

SendOrderSequential(!AcigaSatisYapilsin);

}

 

 

/// <summary>

/// Eklenen sembollerin bardata'ları ve indikatorler güncellendikçe bu fonksiyon tetiklenir.

/// </summary>

/// <param name="barData">Bardata ve hesaplanan gerçekleşen işleme ait detaylar</param>

public override void OnDataUpdate(BarDataCurrentValues barDataCurrentValues)

{

if (!AcigaSatisYapilsin) FirstRun = 0;

 

bool stosAlSignal = stos.StochasticSlowK.CurrentValue > stos.StochasticSlowD.CurrentValue ? true:false;

 

bool buy = (stosAlSignal) ? true:false;

 

 

//bool kanalustu =(ottH.ottSupportLine.CurrentValue>ottH.ottLine.CurrentValue && ottL.ottSupportLine.CurrentValue>ottL.ottLine.CurrentValue) ? true: false ;

 

 

if (CrossAbove(ott.ottSupportLine, ott) && buy && !islemde)

{

if (FirstRun == 0)

{

 

SendMarketOrder(Symbol, BuyOrderQuantity, (OrderSide.Buy));

StopLoss(Symbol, SyntheticOrderPriceType.Percent, Zarar_Durdur_Yuzdesi);

Debug("Alış emri gonderildi.");

FirstRun = 1;

Debug("OTT_SupportLine:" + ott.ottSupportLine.CurrentValue);

Debug("OTTLine:" + ott.ottLine.CurrentValue);

islemde = true;

}

else

{

SendMarketOrder(Symbol, BuyOrderQuantity * 2, (OrderSide.Buy));

StopLoss(Symbol, SyntheticOrderPriceType.Percent, Zarar_Durdur_Yuzdesi);

Debug("Alış emri gonderildi.");

Debug("OTT_SupportLine:" + ott.ottSupportLine.CurrentValue);

Debug("OTTLine:" + ott.ottLine.CurrentValue);

islemde = true;

}

}

 

 

if (CrossBelow(ott.ottSupportLine, ott) && islemde)

{

if (FirstRun == 0)

{

SendMarketOrder(Symbol, SellOrderQuantity, (OrderSide.Sell));

StopLoss(Symbol, SyntheticOrderPriceType.Percent, Zarar_Durdur_Yuzdesi);

FirstRun = 1;

Debug("Satış emri gonderildi.");

Debug("OTT_SupportLine:" + ott.ottSupportLine.CurrentValue);

Debug("OTTLine:" + ott.ottLine.CurrentValue);

islemde = false;

}

else

{

SendMarketOrder(Symbol, SellOrderQuantity * 2, (OrderSide.Sell));

StopLoss(Symbol, SyntheticOrderPriceType.Percent, Zarar_Durdur_Yuzdesi);

Debug("Satış emri gonderildi.");

Debug("OTT_SupportLine:" + ott.ottSupportLine.CurrentValue);

Debug("OTTLine:" + ott.ottLine.CurrentValue);

islemde = false;

}

}

}

 

public override void OnOrderUpdate(IOrder order)

{

//Gercek zamanli pozisyon takibi

if (order.OrdStatus.Obj == OrdStatus.Filled && order.Side.Obj == Side.Buy)

{

var positionChange = order.OrderQty;

realposition += (int) positionChange;

Debug("[ONORDERUPDATE]: Pozisyon = " + realposition);

if (realposition == 0) FirstRun = 0;

}

 

if (order.OrdStatus.Obj == OrdStatus.Filled && order.Side.Obj == Side.Sell)

{

var positionChange = order.OrderQty;

realposition -= (int) positionChange;

Debug("[ONORDERUPDATE]: Pozisyon = " + realposition);

if (realposition == 0) FirstRun = 0;

}

 

}

 

}

 

}
Algoritmik Trading kategorisinde (51 puan) tarafından | 250 kez görüntülendi

Bu soruya cevap vermek için lütfen giriş yapınız veya kayıt olunuz.

Hoş geldiniz, Matriks Destek Platformu sizlere sorularınızın hızlıca cevaplanması için bir ortam sağlar. Sorduğunuz ve cevapladığınız soruların ve yorumlarınızın aldığı oylar üzerinden puan kazanırsınız. Puan sistemine bağlı kampanyamızla ücretsiz kullanım avantajlarından faydalanabilirsiniz.



7,633 soru
7,639 cevap
4,448 yorum
10,858 kullanıcı