Bu kod hata veriyor, düzeltemiyorum, yardımcı olur musunuz ? Görüntülenme 149 görüntülenme
Durum Cevaplandı using System;
using System.Collections.Generic;
using System.Linq;
using Matriks.Lean.Algotrader.AlgoBase;
using Matriks.Trader.Core;
using Matriks.Indicators;
namespace Matriks.Lean.Algotrader
{
public class Ultimate_Fractal_Alligator : MatriksAlgo
{
// ===== PARAMETRELER =====
[Parameter(SymbolPeriod.Minute60)]
public SymbolPeriod Period;
[Parameter(0.01)]
public decimal RiskPercent;
[Parameter(0.03)]
public decimal MaxDailyLoss;
[Parameter(2)]
public int MaxPosition;
[Parameter(1.003)]
public decimal BreakoutMultiplier;
[Parameter(1.5)]
public decimal VolumeMultiplier;
[Parameter(1.5)]
public decimal TrailingMultiplier;
// ===== BIST30 =====
List symbols = new List()
{
"AKBNK","ARCLK","ASELS","BIMAS","EKGYO",
"ENKAI","EREGL","FROTO","GARAN","ISCTR",
"KCHOL","KOZAL","KOZAA","PETKM",
"PGSUS","SAHOL","SASA","SISE","TAVHL",
"TCELL","THYAO","TOASO","TUPRS","TTKOM",
"ULKER","YKBNK"
};
// ===== GLOBAL =====
DateTime currentDay;
decimal startOfDayEquity;
Dictionary ema200 = new();
Dictionary alligator = new();
Dictionary atr = new();
Dictionary atrAvg = new();
Dictionary volAvg = new();
Dictionary fractalUp = new();
Dictionary fractalDown = new();
public override void OnInit()
{
foreach (var s in symbols)
{
AddSymbol(s, Period);
ema200[s] = MOVIndicator(s, Period, OHLCType.Close, 200, MovMethod.Exponential);
alligator[s] = ALLIGATORIndicator(s, Period, OHLCType.HL2, 13, 8, 8, 5, 5, 3);
atr[s] = ATRIndicator(s, Period, OHLCType.Close, 14);
atrAvg[s] = MOVIndicator(atr[s], 20, MovMethod.Simple);
volAvg[s] = MOVIndicator(s, Period, OHLCType.Volume, 20, MovMethod.Simple);
fractalUp[s] = HighestHighIndicator(s, Period, OHLCType.High, 5);
fractalDown[s] = LowestLowIndicator(s, Period, OHLCType.Low, 5);
}
currentDay = DateTime.Now.Date;
startOfDayEquity = GetOverall();
}
public override void OnDataUpdate(BarDataEventArgs barData)
{
string symbol = barData.SymbolDef.Symbol;
if (!symbols.Contains(symbol))
return;
var data = GetBarData(symbol);
if (data.Close.Count < 100)
return;
int i = barData.BarDataIndex;
decimal close = data.Close[i];
decimal volume = data.Volume[i];
// ===== SAAT =====
int hour = DateTime.Now.Hour;
if (hour < 10 || hour > 17)
return;
// ===== GÜN RESET =====
if (DateTime.Now.Date != currentDay)
{
currentDay = DateTime.Now.Date;
startOfDayEquity = GetOverall();
}
// ===== POZİSYON =====
var position = GetPosition(symbol);
bool inPosition = position != null && position.Quantity > 0;
// ===== AÇIK POZİSYON SAYISI =====
int openCount = symbols.Count(s =>
{
var p = GetPosition(s);
return p != null && p.Quantity > 0;
});
// ===== GÜNLÜK ZARAR =====
decimal equity = GetOverall();
decimal dailyPnL = equity - startOfDayEquity;
if (dailyPnL <= -(equity * MaxDailyLoss))
{
Debug("⛔ Günlük zarar limiti aşıldı");
return;
}
// ===== İNDİKATÖRLER =====
var ema = ema200[symbol];
var alli = alligator[symbol];
var atrVal = atr[symbol];
var atrAvgVal = atrAvg[symbol];
var volAvgVal = volAvg[symbol];
var fUp = fractalUp[symbol];
var fDown = fractalDown[symbol];
if (fUp.CurrentIndex < 5 || fDown.CurrentIndex < 5)
return;
// ===== TREND =====
bool trend = close > ema.CurrentValue;
bool alliTrend =
alli.Lips.CurrentValue > alli.Teeth.CurrentValue &&
alli.Teeth.CurrentValue > alli.Jaws.CurrentValue;
bool alliStrong =
alli.Lips.CurrentValue > alli.Lips.Value[alli.Lips.CurrentIndex - 3];
// ===== FRACTAL =====
decimal fUpPrev = fUp.Value[fUp.CurrentIndex - 2];
decimal fDownPrev = fDown.Value[fDown.CurrentIndex - 2];
bool breakout = close > fUpPrev * BreakoutMultiplier;
// ===== FİLTRE =====
bool volumeOk = volume > volAvgVal.CurrentValue * VolumeMultiplier;
bool volatilityOk = atrVal.CurrentValue > atrAvgVal.CurrentValue;
bool priceOk = close > alli.Lips.CurrentValue;
bool buySignal = trend && alliTrend && alliStrong &&
breakout && volumeOk && volatilityOk && priceOk;
decimal stop = fDownPrev;
decimal trailing = close - atrVal.CurrentValue * TrailingMultiplier;
bool sellSignal = close < stop || close < trailing;
// ===== RİSK =====
decimal riskAmount = equity * RiskPercent;
decimal stopDistance = close - stop;
decimal qty = stopDistance > 0 ? riskAmount / stopDistance : 0;
if (qty < 1) qty = 1;
// ===== AL =====
if (buySignal && !inPosition && openCount < MaxPosition)
{
SendMarketOrder(symbol, qty, OrderSide.Buy);
StopLoss(symbol, SyntheticOrderPriceType.PricePoint, stop);
TrailingStopLoss(symbol, SyntheticOrderPriceType.PricePoint, trailing);
Debug($" AL {symbol} | Lot:{qty:F0}");
}
// ===== SAT =====
if (sellSignal && inPosition)
{
SendMarketOrder(symbol, position.Quantity, OrderSide.Sell);
Debug($" SAT {symbol}");
}
}
public override void OnOrderUpdate(IOrder order)
{
if (order.OrdStatus.Obj == OrdStatus.Filled)
{
Debug($"✅ {order.Symbol} {order.Side.Obj} {order.FilledQty:F0}");
}
}
}
}