protected override void Signal(HistoricalPriceVolumeEntry entry) { AroonIndicator aroon = (AroonIndicator)Indicators["Aroon"]; DateTime yesterday = entry.Date.AddDays(-1); TechnicalIndicatorItem currentUp = aroon.AroonUp.Data[entry.Date]; TechnicalIndicatorItem currentDown = aroon.AroonDown.Data[entry.Date]; TechnicalIndicatorItem previousUp = null; TechnicalIndicatorItem previousDown = null; if (aroon.AroonUp.Data.ContainsKey(yesterday)) { previousUp = aroon.AroonUp.Data[yesterday]; previousDown = aroon.AroonDown.Data[yesterday]; } if ((previousDown?.Value >= 50 || previousUp?.Value < 100) && currentDown.Value < 50 && currentUp.Value == 100 && !_bought) { int shares = decimal.ToInt32(Math.Floor(BuyingPower / entry.Close)); _bought = Trade(entry.Date, TradeType.Buy, entry.Close, shares); } else if ((previousUp?.Value >= 50 || previousDown?.Value < 100) && currentUp.Value < 50 && currentDown.Value == 100 && _bought) { _bought = Trade(entry.Date, TradeType.Sell, entry.Close, SharesOwned); } }
protected override void Signal(HistoricalPriceVolumeEntry entry) { AroonIndicator aroon = (AroonIndicator)Indicators["Aroon"]; DateTime yesterday = entry.Date.AddDays(-1); TechnicalIndicatorItem currentUp = aroon.AroonUp.Data[entry.Date]; TechnicalIndicatorItem currentDown = aroon.AroonDown.Data[entry.Date]; TechnicalIndicatorItem previousUp = null; TechnicalIndicatorItem previousDown = null; if (aroon.AroonUp.Data.ContainsKey(yesterday)) { previousUp = aroon.AroonUp.Data[yesterday]; previousDown = aroon.AroonDown.Data[yesterday]; } if (currentUp.Value > currentDown.Value && !_bought) { int shares = decimal.ToInt32(Math.Floor(BuyingPower / entry.Close)); Trade(entry.Date, TradeType.Buy, entry.Close, shares); _bought = true; } else if (currentDown.Value > currentUp.Value && _bought) { // int max = GetMaxBuy(); // int owned = Math.Abs(SharesOwned); // Trade(entry.Date, TradeType.Cover, entry.Close, max > owned ? owned : max); Trade(entry.Date, TradeType.Sell, entry.Close, Math.Abs(SharesOwned)); _bought = false; } }
public void Add(TechnicalIndicatorItem item) { Data.Add(item.Date, item); Items.Add(item); }