Global fix (#9)
* Fix time for candle * Fix out ouf range * Fix pnl, fix custom money management * Clean a bit
This commit is contained in:
@@ -6,11 +6,12 @@ using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Domain.Strategies;
|
||||
|
||||
public class MACDCrossStrategy : Strategy
|
||||
public class MacdCrossStrategy : Strategy
|
||||
{
|
||||
public List<Signal> Signals { get; set; }
|
||||
|
||||
public MACDCrossStrategy(string name, Timeframe timeframe, int fastPeriods, int slowPeriods, int signalPeriods) : base(name, timeframe, StrategyType.MacdCross)
|
||||
public MacdCrossStrategy(string name, Timeframe timeframe, int fastPeriods, int slowPeriods, int signalPeriods) :
|
||||
base(name, timeframe, StrategyType.MacdCross)
|
||||
{
|
||||
Signals = new List<Signal>();
|
||||
FastPeriods = fastPeriods;
|
||||
@@ -20,7 +21,7 @@ public class MACDCrossStrategy : Strategy
|
||||
|
||||
public override List<Signal> Run()
|
||||
{
|
||||
if (Candles.Count <= 2*(SlowPeriods + SignalPeriods))
|
||||
if (Candles.Count <= 2 * (SlowPeriods + SignalPeriods))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -29,7 +30,7 @@ public class MACDCrossStrategy : Strategy
|
||||
{
|
||||
var macd = Candles.GetMacd(FastPeriods.Value, SlowPeriods.Value, SignalPeriods.Value).ToList();
|
||||
var macdCandle = MapMacdToCandle(macd, Candles.TakeLast(SignalPeriods.Value));
|
||||
|
||||
|
||||
if (macd.Count == 0)
|
||||
return null;
|
||||
|
||||
@@ -72,19 +73,20 @@ public class MACDCrossStrategy : Strategy
|
||||
Date = candle.Date,
|
||||
Ticker = candle.Ticker,
|
||||
Exchange = candle.Exchange,
|
||||
FastEma = currentMacd.FastEma.Value,
|
||||
SlowEma = currentMacd.SlowEma.Value,
|
||||
Macd = currentMacd.Macd.Value,
|
||||
Histogram = currentMacd.Histogram.Value
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return macdList;
|
||||
}
|
||||
|
||||
private void AddSignal(CandleMacd candleSignal, Timeframe timeframe, TradeDirection direction, Confidence confidence)
|
||||
private void AddSignal(CandleMacd candleSignal, Timeframe timeframe, TradeDirection direction,
|
||||
Confidence confidence)
|
||||
{
|
||||
var signal = new Signal(MiscExtensions.ParseEnum<Ticker>(candleSignal.Ticker), direction, confidence, candleSignal, candleSignal.Date, candleSignal.Exchange, timeframe, Type, SignalType);
|
||||
var signal = new Signal(MiscExtensions.ParseEnum<Ticker>(candleSignal.Ticker), direction, confidence,
|
||||
candleSignal, candleSignal.Date, candleSignal.Exchange, timeframe, Type, SignalType);
|
||||
if (!Signals.Any(s => s.Identifier == signal.Identifier))
|
||||
{
|
||||
Signals.AddItem(signal);
|
||||
@@ -96,7 +98,5 @@ public class MACDCrossStrategy : Strategy
|
||||
public double Macd { get; set; }
|
||||
public double Signal { get; set; }
|
||||
public double Histogram { get; set; }
|
||||
public double FastEma { get; set; }
|
||||
public double SlowEma { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user