Sono stati aggiunti tutti i file principali di Bootstrap 5.3.3, inclusi CSS, JavaScript (bundle, ESM, UMD, minificati), versioni RTL, utility, reboot, griglia e relative mappe delle sorgenti. Questi file abilitano un sistema di design moderno, responsive e accessibile, con supporto per layout LTR e RTL, debugging avanzato tramite source map e tutte le funzionalità di Bootstrap per lo sviluppo dell’interfaccia utente. Nessuna modifica ai file esistenti.
69 lines
2.4 KiB
C#
69 lines
2.4 KiB
C#
using TradingBot.Models;
|
|
|
|
namespace TradingBot.Services;
|
|
|
|
public class SimpleMovingAverageStrategy : ITradingStrategy
|
|
{
|
|
private readonly int _shortPeriod = 5;
|
|
private readonly int _longPeriod = 10;
|
|
|
|
public string Name => "Simple Moving Average (SMA)";
|
|
|
|
public Task<TradingSignal> AnalyzeAsync(string symbol, List<MarketPrice> historicalPrices)
|
|
{
|
|
if (historicalPrices.Count < _longPeriod)
|
|
{
|
|
return Task.FromResult(new TradingSignal
|
|
{
|
|
Symbol = symbol,
|
|
Type = SignalType.Hold,
|
|
Price = historicalPrices.LastOrDefault()?.Price ?? 0,
|
|
Reason = "Dati insufficienti per l'analisi",
|
|
Timestamp = DateTime.UtcNow
|
|
});
|
|
}
|
|
|
|
var recentPrices = historicalPrices.OrderByDescending(p => p.Timestamp).Take(_longPeriod).ToList();
|
|
|
|
var shortSMA = recentPrices.Take(_shortPeriod).Average(p => p.Price);
|
|
var longSMA = recentPrices.Average(p => p.Price);
|
|
var currentPrice = recentPrices.First().Price;
|
|
|
|
// Strategia: Compra quando la SMA breve incrocia sopra la SMA lunga
|
|
// Vendi quando la SMA breve incrocia sotto la SMA lunga
|
|
if (shortSMA > longSMA * 1.02m) // 2% sopra
|
|
{
|
|
return Task.FromResult(new TradingSignal
|
|
{
|
|
Symbol = symbol,
|
|
Type = SignalType.Buy,
|
|
Price = currentPrice,
|
|
Reason = $"SMA breve ({shortSMA:F2}) > SMA lunga ({longSMA:F2}) - Trend rialzista",
|
|
Timestamp = DateTime.UtcNow
|
|
});
|
|
}
|
|
else if (shortSMA < longSMA * 0.98m) // 2% sotto
|
|
{
|
|
return Task.FromResult(new TradingSignal
|
|
{
|
|
Symbol = symbol,
|
|
Type = SignalType.Sell,
|
|
Price = currentPrice,
|
|
Reason = $"SMA breve ({shortSMA:F2}) < SMA lunga ({longSMA:F2}) - Trend ribassista",
|
|
Timestamp = DateTime.UtcNow
|
|
});
|
|
}
|
|
else
|
|
{
|
|
return Task.FromResult(new TradingSignal
|
|
{
|
|
Symbol = symbol,
|
|
Type = SignalType.Hold,
|
|
Price = currentPrice,
|
|
Reason = $"SMA breve ({shortSMA:F2}) ? SMA lunga ({longSMA:F2}) - Nessun segnale chiaro",
|
|
Timestamp = DateTime.UtcNow
|
|
});
|
|
}
|
|
}
|
|
}
|