Take into account TrendThreshold when calculating trend averages
This commit is contained in:
parent
88beb769da
commit
a8e018097d
|
@ -1519,11 +1519,15 @@ namespace Core.Main
|
||||||
|
|
||||||
int marketPairProcess = 1;
|
int marketPairProcess = 1;
|
||||||
Dictionary<string, List<string>> matchedMarketTriggers = new Dictionary<string, List<string>>();
|
Dictionary<string, List<string>> matchedMarketTriggers = new Dictionary<string, List<string>>();
|
||||||
|
|
||||||
|
// Loop through markets
|
||||||
foreach (string marketPair in this.MarketList)
|
foreach (string marketPair in this.MarketList)
|
||||||
{
|
{
|
||||||
this.Log.DoLogDebug("'" + marketPair + "' - Checking triggers (" + marketPairProcess.ToString() + "/" + this.MarketList.Count.ToString() + ")...");
|
this.Log.DoLogDebug("'" + marketPair + "' - Checking triggers (" + marketPairProcess.ToString() + "/" + this.MarketList.Count.ToString() + ")...");
|
||||||
|
|
||||||
bool stopTriggers = false;
|
bool stopTriggers = false;
|
||||||
|
|
||||||
|
// Loop through single market settings
|
||||||
foreach (SingleMarketSetting marketSetting in this.PTMagicConfiguration.AnalyzerSettings.SingleMarketSettings)
|
foreach (SingleMarketSetting marketSetting in this.PTMagicConfiguration.AnalyzerSettings.SingleMarketSettings)
|
||||||
{
|
{
|
||||||
List<string> matchedSingleMarketTriggers = new List<string>();
|
List<string> matchedSingleMarketTriggers = new List<string>();
|
||||||
|
@ -1560,7 +1564,7 @@ namespace Core.Main
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Checking Off Triggers
|
// Trigger checking
|
||||||
SingleMarketSettingSummary smss = this.SingleMarketSettingSummaries.Find(s => s.Market.Equals(marketPair, StringComparison.InvariantCultureIgnoreCase) && s.SingleMarketSetting.SettingName.Equals(marketSetting.SettingName, StringComparison.InvariantCultureIgnoreCase));
|
SingleMarketSettingSummary smss = this.SingleMarketSettingSummaries.Find(s => s.Market.Equals(marketPair, StringComparison.InvariantCultureIgnoreCase) && s.SingleMarketSetting.SettingName.Equals(marketSetting.SettingName, StringComparison.InvariantCultureIgnoreCase));
|
||||||
if (smss != null)
|
if (smss != null)
|
||||||
{
|
{
|
||||||
|
@ -1576,7 +1580,7 @@ namespace Core.Main
|
||||||
{
|
{
|
||||||
if (offTrigger.HoursSinceTriggered > 0)
|
if (offTrigger.HoursSinceTriggered > 0)
|
||||||
{
|
{
|
||||||
#region Check for Activation time period trigger
|
// Check for Activation time period trigger
|
||||||
int smsActiveHours = (int)Math.Floor(DateTime.UtcNow.Subtract(smss.ActivationDateTimeUTC).TotalHours);
|
int smsActiveHours = (int)Math.Floor(DateTime.UtcNow.Subtract(smss.ActivationDateTimeUTC).TotalHours);
|
||||||
if (smsActiveHours >= offTrigger.HoursSinceTriggered)
|
if (smsActiveHours >= offTrigger.HoursSinceTriggered)
|
||||||
{
|
{
|
||||||
|
@ -1588,17 +1592,15 @@ namespace Core.Main
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
// Trigger not met!
|
// Trigger not met!
|
||||||
this.Log.DoLogDebug("'" + marketPair + "' - SMS only active for " + smsActiveHours.ToString() + " hours. Trigger not matched!");
|
this.Log.DoLogDebug("'" + marketPair + "' - SMS only active for " + smsActiveHours.ToString() + " hours. Trigger not matched!");
|
||||||
|
|
||||||
offTriggerResults.Add(false);
|
offTriggerResults.Add(false);
|
||||||
}
|
}
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
else if (offTrigger.Min24hVolume > 0 || offTrigger.Max24hVolume < Constants.Max24hVolume)
|
else if (offTrigger.Min24hVolume > 0 || offTrigger.Max24hVolume < Constants.Max24hVolume)
|
||||||
{
|
{
|
||||||
#region Check for 24h volume trigger
|
// Check for 24h volume trigger
|
||||||
List<MarketTrendChange> marketTrendChanges = this.SingleMarketTrendChanges[this.SingleMarketTrendChanges.Keys.Last()];
|
List<MarketTrendChange> marketTrendChanges = this.SingleMarketTrendChanges[this.SingleMarketTrendChanges.Keys.Last()];
|
||||||
if (marketTrendChanges.Count > 0)
|
if (marketTrendChanges.Count > 0)
|
||||||
{
|
{
|
||||||
|
@ -1607,7 +1609,6 @@ namespace Core.Main
|
||||||
{
|
{
|
||||||
if (mtc.Volume24h >= offTrigger.Min24hVolume && mtc.Volume24h <= offTrigger.Max24hVolume)
|
if (mtc.Volume24h >= offTrigger.Min24hVolume && mtc.Volume24h <= offTrigger.Max24hVolume)
|
||||||
{
|
{
|
||||||
|
|
||||||
// Trigger met!
|
// Trigger met!
|
||||||
this.Log.DoLogDebug("'" + marketPair + "' - 24h volume off trigger matched! 24h volume = " + mtc.Volume24h.ToString(new System.Globalization.CultureInfo("en-US")) + " " + this.LastRuntimeSummary.MainMarket);
|
this.Log.DoLogDebug("'" + marketPair + "' - 24h volume off trigger matched! 24h volume = " + mtc.Volume24h.ToString(new System.Globalization.CultureInfo("en-US")) + " " + this.LastRuntimeSummary.MainMarket);
|
||||||
|
|
||||||
|
@ -1615,7 +1616,6 @@ namespace Core.Main
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
// Trigger not met!
|
// Trigger not met!
|
||||||
this.Log.DoLogDebug("'" + marketPair + "' - 24h volume off trigger not matched! 24h volume = " + mtc.Volume24h.ToString(new System.Globalization.CultureInfo("en-US")) + " " + this.LastRuntimeSummary.MainMarket);
|
this.Log.DoLogDebug("'" + marketPair + "' - 24h volume off trigger not matched! 24h volume = " + mtc.Volume24h.ToString(new System.Globalization.CultureInfo("en-US")) + " " + this.LastRuntimeSummary.MainMarket);
|
||||||
|
|
||||||
|
@ -1623,16 +1623,14 @@ namespace Core.Main
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#region Check for market trend triggers
|
// Check for market trend triggers
|
||||||
if (this.SingleMarketTrendChanges.ContainsKey(offTrigger.MarketTrendName))
|
if (this.SingleMarketTrendChanges.ContainsKey(offTrigger.MarketTrendName))
|
||||||
{
|
{
|
||||||
|
|
||||||
List<MarketTrendChange> marketTrendChanges = this.SingleMarketTrendChanges[offTrigger.MarketTrendName];
|
List<MarketTrendChange> marketTrendChanges = this.SingleMarketTrendChanges[offTrigger.MarketTrendName];
|
||||||
|
List<MarketTrend> marketTrends = this.PTMagicConfiguration.AnalyzerSettings.MarketAnalyzer.MarketTrends;
|
||||||
if (marketTrendChanges.Count > 0)
|
if (marketTrendChanges.Count > 0)
|
||||||
{
|
{
|
||||||
double averageMarketTrendChange = marketTrendChanges.Average(m => m.TrendChange);
|
double averageMarketTrendChange = marketTrendChanges.Average(m => m.TrendChange);
|
||||||
|
@ -1645,7 +1643,6 @@ namespace Core.Main
|
||||||
|
|
||||||
if (offTrigger.MarketTrendRelation.Equals(Constants.MarketTrendRelationRelative))
|
if (offTrigger.MarketTrendRelation.Equals(Constants.MarketTrendRelationRelative))
|
||||||
{
|
{
|
||||||
|
|
||||||
// Build pair trend change relative to the global market trend
|
// Build pair trend change relative to the global market trend
|
||||||
trendChange = trendChange - averageMarketTrendChange;
|
trendChange = trendChange - averageMarketTrendChange;
|
||||||
}
|
}
|
||||||
|
@ -1684,7 +1681,6 @@ namespace Core.Main
|
||||||
offTriggerResults.Add(false);
|
offTriggerResults.Add(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1720,8 +1716,8 @@ namespace Core.Main
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
|
||||||
|
|
||||||
|
// Do we have triggers
|
||||||
if (marketSetting.Triggers.Count > 0 && !stopTriggers)
|
if (marketSetting.Triggers.Count > 0 && !stopTriggers)
|
||||||
{
|
{
|
||||||
#region Checking Triggers
|
#region Checking Triggers
|
||||||
|
@ -1730,6 +1726,8 @@ namespace Core.Main
|
||||||
List<bool> triggerResults = new List<bool>();
|
List<bool> triggerResults = new List<bool>();
|
||||||
Dictionary<int, double> relevantTriggers = new Dictionary<int, double>();
|
Dictionary<int, double> relevantTriggers = new Dictionary<int, double>();
|
||||||
int triggerIndex = 0;
|
int triggerIndex = 0;
|
||||||
|
|
||||||
|
// Loop through SMS triggers
|
||||||
foreach (Trigger trigger in marketSetting.Triggers)
|
foreach (Trigger trigger in marketSetting.Triggers)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -1819,7 +1817,37 @@ namespace Core.Main
|
||||||
List<MarketTrendChange> marketTrendChanges = this.SingleMarketTrendChanges[trigger.MarketTrendName];
|
List<MarketTrendChange> marketTrendChanges = this.SingleMarketTrendChanges[trigger.MarketTrendName];
|
||||||
if (marketTrendChanges.Count > 0)
|
if (marketTrendChanges.Count > 0)
|
||||||
{
|
{
|
||||||
double averageMarketTrendChange = marketTrendChanges.Average(m => m.TrendChange);
|
double averageMarketTrendChange = 0;
|
||||||
|
var trendThreshold = (from mt in this.PTMagicConfiguration.AnalyzerSettings.MarketAnalyzer.MarketTrends
|
||||||
|
where mt.Name == trigger.MarketTrendName
|
||||||
|
select new { mt.TrendThreshold }).Single();
|
||||||
|
|
||||||
|
// Calculate average market change, skip any that are outside the threshold if enabled
|
||||||
|
if (trendThreshold.TrendThreshold != 0)
|
||||||
|
{
|
||||||
|
// Exclude trends outside the threshhold.
|
||||||
|
var excludedMarkets = from m in marketTrendChanges
|
||||||
|
where m.TrendChange > trendThreshold.TrendThreshold
|
||||||
|
orderby m.Market
|
||||||
|
select m;
|
||||||
|
|
||||||
|
foreach (var marketTrend in excludedMarkets)
|
||||||
|
{
|
||||||
|
this.Log.DoLogInfo("SMS Trigger for '" + marketSetting.SettingName + "' is ignoring " + marketTrend.Market + " for exceeding TrendThreshold " + trendThreshold.TrendThreshold + " on " + trigger.MarketTrendName);
|
||||||
|
}
|
||||||
|
|
||||||
|
var includedMarkets = from m in marketTrendChanges
|
||||||
|
where m.TrendChange <= trendThreshold.TrendThreshold
|
||||||
|
orderby m.Market
|
||||||
|
select m;
|
||||||
|
|
||||||
|
averageMarketTrendChange = includedMarkets.Average(m => m.TrendChange);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Calculate for whole market
|
||||||
|
averageMarketTrendChange = marketTrendChanges.Average(m => m.TrendChange);
|
||||||
|
}
|
||||||
|
|
||||||
MarketTrendChange mtc = marketTrendChanges.Find(m => m.Market.Equals(marketPair, StringComparison.InvariantCultureIgnoreCase));
|
MarketTrendChange mtc = marketTrendChanges.Find(m => m.Market.Equals(marketPair, StringComparison.InvariantCultureIgnoreCase));
|
||||||
if (mtc != null)
|
if (mtc != null)
|
||||||
|
@ -1895,7 +1923,7 @@ namespace Core.Main
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
triggerIndex++;
|
triggerIndex++;
|
||||||
}
|
} // End loop SMS triggers
|
||||||
|
|
||||||
// Check if all triggers have to get triggered or just one
|
// Check if all triggers have to get triggered or just one
|
||||||
bool settingTriggered = false;
|
bool settingTriggered = false;
|
||||||
|
@ -2041,7 +2069,7 @@ namespace Core.Main
|
||||||
this.Log.DoLogDebug("'" + marketPair + "' - '" + marketSetting.SettingName + "' not triggered!");
|
this.Log.DoLogDebug("'" + marketPair + "' - '" + marketSetting.SettingName + "' not triggered!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} // End loop single market settings
|
||||||
|
|
||||||
if ((marketPairProcess % 10) == 0)
|
if ((marketPairProcess % 10) == 0)
|
||||||
{
|
{
|
||||||
|
@ -2049,8 +2077,9 @@ namespace Core.Main
|
||||||
}
|
}
|
||||||
|
|
||||||
marketPairProcess++;
|
marketPairProcess++;
|
||||||
}
|
} // End loop through markets
|
||||||
|
|
||||||
|
// Did we trigger any SMS?
|
||||||
if (this.TriggeredSingleMarketSettings.Count > 0)
|
if (this.TriggeredSingleMarketSettings.Count > 0)
|
||||||
{
|
{
|
||||||
this.Log.DoLogInfo("Building single market settings for '" + this.TriggeredSingleMarketSettings.Count.ToString() + "' markets...");
|
this.Log.DoLogInfo("Building single market settings for '" + this.TriggeredSingleMarketSettings.Count.ToString() + "' markets...");
|
||||||
|
|
Loading…
Reference in New Issue