Ejemplo n.º 1
0
        private void BuyAsset(IIndexedOhlcvData indexedCandle, decimal premium, IDictionary <IEnumerable <IOhlcvData>, decimal> assetCashMap, IList <Transaction> transactions)
        {
            if (assetCashMap.TryGetValue(indexedCandle.BackingList, out decimal cash))
            {
                var nextIOhlcvData = indexedCandle.Next;
                int quantity       = Convert.ToInt32(Math.Floor((cash - premium) / nextIOhlcvData.Open));

                decimal cashOut = nextIOhlcvData.Open * quantity + premium;
                assetCashMap[indexedCandle.BackingList] -= cashOut;

                transactions.Add(new Transaction(indexedCandle.BackingList, nextIOhlcvData.Index, nextIOhlcvData.DateTime, TransactionType.Buy, quantity, cashOut));
                OnBought?.Invoke(indexedCandle.BackingList, nextIOhlcvData.Index, nextIOhlcvData.DateTime, nextIOhlcvData.Open, quantity, cashOut, assetCashMap[indexedCandle.BackingList]);
            }
        }
Ejemplo n.º 2
0
        private void SellAsset(IIndexedOhlcvData indexedCandle, decimal premium, IDictionary <IEnumerable <IOhlcvData>, decimal> assetCashMap, IList <Transaction> transactions)
        {
            if (assetCashMap.TryGetValue(indexedCandle.BackingList, out _))
            {
                var nextIOhlcvData  = indexedCandle.Next;
                var lastTransaction = transactions.LastOrDefault(t => t.IOhlcvDatas.Equals(indexedCandle.BackingList));
                if (lastTransaction.Type == TransactionType.Sell)
                {
                    return;
                }

                decimal cashIn  = nextIOhlcvData.Open * lastTransaction.Quantity - premium;
                decimal plRatio = (cashIn - lastTransaction.AbsoluteCashFlow) / lastTransaction.AbsoluteCashFlow;
                assetCashMap[indexedCandle.BackingList] += cashIn;

                transactions.Add(new Transaction(indexedCandle.BackingList, nextIOhlcvData.Index, nextIOhlcvData.DateTime, TransactionType.Sell, lastTransaction.Quantity, cashIn));
                OnSold?.Invoke(indexedCandle.BackingList, nextIOhlcvData.Index, nextIOhlcvData.DateTime, nextIOhlcvData.Open, lastTransaction.Quantity, cashIn, assetCashMap[indexedCandle.BackingList], plRatio);
            }
        }
Ejemplo n.º 3
0
 public static bool IsObvBearish(this IIndexedOhlcvData ic)
 => ic.Get <OnBalanceVolume>().Diff(ic.Index).Tick.IsNegative();
Ejemplo n.º 4
0
 public static bool IsEmaBearish(this IIndexedOhlcvData ic, int periodCount)
 => ic.Get <ExponentialMovingAverage>(periodCount).Diff(ic.Index).Tick.IsNegative();
Ejemplo n.º 5
0
 public static bool IsSmaBullish(this IIndexedOhlcvData ic, int periodCount)
 => ic.Get <SimpleMovingAverage>(periodCount).Diff(ic.Index).Tick.IsPositive();
Ejemplo n.º 6
0
 public static decimal?ClosePriceChange(this IIndexedOhlcvData ic)
 => ic.Get <ClosePriceChange>(1)[ic.Index].Tick;
Ejemplo n.º 7
0
 public static bool IsSlowStoOversold(this IIndexedOhlcvData ic, int periodCount, int smaPeriodCountD)
 => ic.Get <Stochastics.Slow>(periodCount, smaPeriodCountD)[ic.Index].Tick.IsTrue((k, d, j) => k <= 20);
Ejemplo n.º 8
0
 public static bool IsRsiOversold(this IIndexedOhlcvData ic, int periodCount)
 => ic.Get <RelativeStrengthIndex>(periodCount)[ic.Index].Tick.IsTrue(t => t <= 30);
Ejemplo n.º 9
0
 public static bool IsBearish(this IIndexedOhlcvData ic)
 => ic.Get <ClosePriceChange>()[ic.Index].Tick.IsNegative();
Ejemplo n.º 10
0
 public static bool IsMacdBearishCross(this IIndexedOhlcvData ic, int emaPeriodCount1, int emaPeriodCount2, int demPeriodCount)
 => ic.Get <MovingAverageConvergenceDivergenceHistogram>(emaPeriodCount1, emaPeriodCount2, demPeriodCount).ComputeNeighbour(ic.Index)
 .IsTrue((prev, current, _) => prev.Tick.IsPositive() && current.Tick.IsNegative());
Ejemplo n.º 11
0
 public static bool IsEmaBearishCross(this IIndexedOhlcvData ic, int periodCount1, int periodCount2)
 => ic.Get <ExponentialMovingAverageOscillator>(periodCount1, periodCount2).ComputeNeighbour(ic.Index)
 .IsTrue((prev, current, _) => prev.Tick.IsPositive() && current.Tick.IsNegative());
Ejemplo n.º 12
0
 public static bool IsSlowStoOscBearish(this IIndexedOhlcvData ic, int periodCount, int smaPeriodCountD)
 => ic.Get <StochasticsOscillator.Slow>(periodCount, smaPeriodCountD).Diff(ic.Index).Tick.IsNegative();
Ejemplo n.º 13
0
 public static bool IsFullStoOscBullish(this IIndexedOhlcvData ic, int periodCount, int smaPeriodCountK, int smaPeriodCountD)
 => ic.Get <StochasticsOscillator.Full>(periodCount, smaPeriodCountK, smaPeriodCountD).Diff(ic.Index).Tick.IsPositive();
Ejemplo n.º 14
0
 public static bool IsMacdOscBearish(this IIndexedOhlcvData ic, int emaPeriodCount1, int emaPeriodCount2, int demPeriodCount)
 => ic.Get <MovingAverageConvergenceDivergenceHistogram>(emaPeriodCount1, emaPeriodCount2, demPeriodCount).Diff(ic.Index).Tick.IsNegative();
Ejemplo n.º 15
0
 public static bool IsInBbRange(this IIndexedOhlcvData ic, int periodCount, int sdCount)
 => ic.Get <BollingerBands>(periodCount, sdCount)[ic.Index].Tick.IsTrue((low, mid, up) => ic.Close >= low && ic.Close <= up);
Ejemplo n.º 16
0
 public static bool IsBelowBbLow(this IIndexedOhlcvData ic, int periodCount, int sdCount)
 => ic.Get <BollingerBands>(periodCount, sdCount)[ic.Index].Tick.IsTrue((low, mid, up) => ic.Close < low);
Ejemplo n.º 17
0
 public static bool IsSlowStoBearishCross(this IIndexedOhlcvData ic, int periodCount, int smaPeriodCountD)
 => ic.Get <StochasticsOscillator.Slow>(periodCount, smaPeriodCountD).ComputeNeighbour(ic.Index)
 .IsTrue((prev, current, _) => prev.Tick.IsPositive() && current.Tick.IsNegative());
Ejemplo n.º 18
0
 public static bool IsFullStoOverbought(this IIndexedOhlcvData ic, int periodCount, int smaPeriodCountK, int smaPeriodCountD)
 => ic.Get <Stochastics.Full>(periodCount, smaPeriodCountK, smaPeriodCountD)[ic.Index].Tick.IsTrue((k, d, j) => k >= 80);
Ejemplo n.º 19
0
 public static bool IsBreakingHistoricalHighestHigh(this IIndexedOhlcvData ic)
 => ic.Get <HistoricalHighestHigh>().Diff(ic.Index).Tick.IsPositive();
Ejemplo n.º 20
0
 public static bool IsAboveSma(this IIndexedOhlcvData ic, int periodCount)
 => ic.Get <SimpleMovingAverage>(periodCount)[ic.Index].Tick.IsTrue(t => ic.Close > t);
Ejemplo n.º 21
0
 public static bool IsBreakingHistoricalLowestClose(this IIndexedOhlcvData ic)
 => ic.Get <HistoricalLowestClose>().Diff(ic.Index).Tick.IsNegative();
Ejemplo n.º 22
0
 public static bool IsBelowEma(this IIndexedOhlcvData ic, int periodCount)
 => ic.Get <ExponentialMovingAverage>(periodCount)[ic.Index].Tick.IsTrue(t => ic.Close < t);
Ejemplo n.º 23
0
 public static bool IsBreakingHighestHigh(this IIndexedOhlcvData ic, int periodCount)
 => ic.Get <HighestHigh>(periodCount).Diff(ic.Index).Tick.IsPositive();
Ejemplo n.º 24
0
 public static bool IsSmaOscBullish(this IIndexedOhlcvData ic, int periodCount1, int periodCount2)
 => ic.Get <SimpleMovingAverageOscillator>(periodCount1, periodCount2).Diff(ic.Index).Tick.IsPositive();
Ejemplo n.º 25
0
 public static bool IsBreakingLowestClose(this IIndexedOhlcvData ic, int periodCount)
 => ic.Get <LowestClose>(periodCount).Diff(ic.Index).Tick.IsNegative();
Ejemplo n.º 26
0
 public static bool IsEmaOscBearish(this IIndexedOhlcvData ic, int periodCount1, int periodCount2)
 => ic.Get <ExponentialMovingAverageOscillator>(periodCount1, periodCount2).Diff(ic.Index).Tick.IsNegative();
Ejemplo n.º 27
0
 public static bool IsAccumDistBearish(this IIndexedOhlcvData ic)
 => ic.Get <AccumulationDistributionLine>().Diff(ic.Index).Tick.IsNegative();