Initial commit

This commit is contained in:
Michael Schimmel
2026-01-28 09:10:52 +01:00
commit a1d2e96f8a
513 changed files with 19503 additions and 0 deletions
@@ -0,0 +1 @@
{"version":"2.0.0","tasks":[{"label":"build","command":"dotnet","type":"process","args":["build","${workspaceFolder}","/property:GenerateFullPaths=true","/consoleLoggerParameters:NoSummary"],"problemMatcher":"$msCompile"}]}
@@ -0,0 +1,22 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30011.22
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HmaMitigationSignals", "HmaMitigationSignals\HmaMitigationSignals.csproj", "{46b07fe6-e609-40d3-a15f-e381ff0f058e}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{46b07fe6-e609-40d3-a15f-e381ff0f058e}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{46b07fe6-e609-40d3-a15f-e381ff0f058e}.Debug|Any CPU.Build.0 = Debug|Any CPU
{46b07fe6-e609-40d3-a15f-e381ff0f058e}.Release|Any CPU.ActiveCfg = Release|Any CPU
{46b07fe6-e609-40d3-a15f-e381ff0f058e}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
@@ -0,0 +1,204 @@
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using System.Collections.Generic;
using System.Linq;
using System;
namespace cAlgo.Indicators
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class HmaMitigationSignals : Indicator
{
[Parameter("HMA Period", DefaultValue = 20, MinValue = 2)]
public int HmaPeriod { get; set; }
// Use the chart's TimeZone for this input
[Parameter("Session Close Time (Chart TZ)", DefaultValue = "17:30")]
public TimeSpan SessionCloseTime { get; set; }
[Parameter("Enable Alerts", DefaultValue = true)]
public bool EnableAlerts { get; set; }
[Parameter("Alert Sound Path", DefaultValue = "")]
public string AlertSoundPath { get; set; }
[Output("HMA", LineColor = "Orange")]
public IndicatorDataSeries HmaOutput { get; set; }
private HullMovingAverage _hma;
private Stack<double> _peakStack;
private Stack<double> _troughStack;
private DateTime _currentSessionEndTimeUtc = DateTime.MinValue;
// State flags for entry setup
private bool _buySetupActive = false;
private bool _sellSetupActive = false;
protected override void Initialize()
{
_hma = Indicators.HullMovingAverage(Bars.ClosePrices, HmaPeriod);
_peakStack = new Stack<double>();
_troughStack = new Stack<double>();
}
public override void Calculate(int index)
{
HmaOutput[index] = _hma.Result[index];
DateTime barOpenTime = Bars.OpenTimes[index]; // This is UTC
// --- Session Initialization (run once) ---
if (_currentSessionEndTimeUtc == DateTime.MinValue)
{
// Convert the current UTC bar time to the chart's local time zone
DateTime barOpenTimeChartTz = TimeZoneInfo.ConvertTimeFromUtc(barOpenTime, this.TimeZone);
// Create the session close time for "today" *in the chart's timezone*
DateTime sessionCloseChartTz = barOpenTimeChartTz.Date.Add(SessionCloseTime);
// Convert this chart-timezone-based closing time back to UTC
DateTime sessionCloseTodayUtc = TimeZoneInfo.ConvertTimeToUtc( sessionCloseChartTz, this.TimeZone);
if (barOpenTime >= sessionCloseTodayUtc)
{
// Bar is after today's close. Session end is tomorrow (chart time).
// Add 1 day *in chart time* (handles DST)
DateTime nextSessionEndChartTz = sessionCloseChartTz.AddDays(1);
// Convert back to UTC
_currentSessionEndTimeUtc = TimeZoneInfo.ConvertTime(nextSessionEndChartTz, this.TimeZone, TimeZoneInfo.Utc);
}
else
{
// Bar is before today's close. Session end is today (chart time).
_currentSessionEndTimeUtc = sessionCloseTodayUtc;
}
}
// --- Session Check ---
// Check if the current bar has crossed the session boundary
if (barOpenTime >= _currentSessionEndTimeUtc)
{
// New session starts, clear stacks and drawings
_peakStack.Clear();
_troughStack.Clear();
//Chart.RemoveAllObjects(); // Clear old session text and icons
// Reset setup flags
_buySetupActive = false;
_sellSetupActive = false;
// Set the *next* session end time, looping in case of market gaps (weekends)
while (barOpenTime >= _currentSessionEndTimeUtc)
{
// Convert current UTC end time to chart time
DateTime currentSessionEndChartTz = TimeZoneInfo.ConvertTimeFromUtc(_currentSessionEndTimeUtc, this.TimeZone);
// Add 1 day *in chart time* (handles DST)
DateTime nextSessionEndChartTz = currentSessionEndChartTz.AddDays(1);
// Convert back to UTC for the next comparison
_currentSessionEndTimeUtc = TimeZoneInfo.ConvertTime(nextSessionEndChartTz, this.TimeZone, TimeZoneInfo.Utc);
}
}
// Stop signal logic from running on the forming bar (which causes repainting)
if (IsLastBar)
{
return;
}
// We need at least 3 bars to identify a peak/trough at index - 1
if (index < 2)
{
return;
}
// --- 1. Identify new peaks/troughs at index - 1 AND check for entry ---
// All HMA values are now based on closed bars (index, index-1, index-2).
double prevHma = _hma.Result[index - 1];
double prevHma2 = _hma.Result[index - 2];
double currentHma = _hma.Result[index];
// A peak at index-1
bool isPeak = (prevHma > prevHma2) && (prevHma > currentHma);
// A trough at index-1
bool isTrough = (prevHma < prevHma2) && (prevHma < currentHma);
if (isPeak)
{
// Check if a sell setup was active *before* pushing the new peak
if (_sellSetupActive)
{
// Draw sell icon at the peak (index - 1)
Chart.DrawIcon($"sell_{index - 1}", ChartIconType.DownArrow, index - 1, Bars.HighPrices[index - 1] + Symbol.PipSize * 10, Color.Red);
_sellSetupActive = false; // Reset setup
}
_peakStack.Push(prevHma);
// Draw count above the peak bar
string peakLabel = $"{_peakStack.Count}";
double yPos = Bars.HighPrices[index - 1] + Symbol.PipSize * 5;
Chart.DrawText($"peak_{index - 1}", peakLabel, index - 1, yPos, Color.Red);
}
if (isTrough)
{
// Check if a buy setup was active *before* pushing the new trough
if (_buySetupActive)
{
// Draw buy icon at the trough (index - 1)
Chart.DrawIcon($"buy_{index - 1}", ChartIconType.UpArrow, index - 1, Bars.LowPrices[index - 1] - Symbol.PipSize * 10, Color.Lime);
_buySetupActive = false; // Reset setup
}
_troughStack.Push(prevHma);
// Draw count below the trough bar
string troughLabel = $"{_troughStack.Count}";
double yPos = Bars.LowPrices[index - 1] - Symbol.PipSize * 5;
Chart.DrawText($"trough_{index - 1}", troughLabel, index - 1, yPos, Color.Lime);
}
// --- 2. Check for mitigation (Setup) based on the hma value ---
// Mitigation is checked against the closed bar 'currentHma' (at index).
// Check peak mitigation (testing highs)
bool peakMitigationTriggeredSetup = false;
while (_peakStack.Count > 0 && currentHma >= _peakStack.Peek())
{
_peakStack.Pop();
if (_peakStack.Count <= 1)
{
peakMitigationTriggeredSetup = true;
}
}
if (peakMitigationTriggeredSetup)
{
// Alert only on the first bar the setup becomes active
if (EnableAlerts && !_sellSetupActive && !string.IsNullOrEmpty(AlertSoundPath))
{
Notifications.PlaySound(AlertSoundPath);
}
_sellSetupActive = true; // Activate sell setup
}
// Check trough mitigation (testing lows)
bool troughMitigationTriggeredSetup = false;
while (_troughStack.Count > 0 && currentHma <= _troughStack.Peek())
{
_troughStack.Pop();
if (_troughStack.Count <= 1)
{
troughMitigationTriggeredSetup = true;
}
}
if (troughMitigationTriggeredSetup)
{
// Alert only on the first bar the setup becomes active
if (EnableAlerts && !_buySetupActive && !string.IsNullOrEmpty(AlertSoundPath))
{
Notifications.PlaySound(AlertSoundPath);
}
_buySetupActive = true; // Activate buy setup
}
}
}
}
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="cTrader.Automate" Version="*" />
</ItemGroup>
</Project>
@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
@@ -0,0 +1,22 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("HmaMitigationSignals")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("HmaMitigationSignals")]
[assembly: System.Reflection.AssemblyTitleAttribute("HmaMitigationSignals")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Generated by the MSBuild WriteCodeFragment class.
@@ -0,0 +1,10 @@
is_global = true
build_property.TargetFramework = net6.0
build_property.TargetPlatformMinVersion =
build_property.UsingMicrosoftNETSdkWeb =
build_property.ProjectTypeGuids =
build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = HmaMitigationSignals
build_property.ProjectDir = C:\Users\Brummel\Documents\cAlgo\Sources\Indicators\HmaMitigationSignals\HmaMitigationSignals\
@@ -0,0 +1,66 @@
{
"format": 1,
"restore": {
"C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Indicators\\HmaMitigationSignals\\HmaMitigationSignals\\HmaMitigationSignals.csproj": {}
},
"projects": {
"C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Indicators\\HmaMitigationSignals\\HmaMitigationSignals\\HmaMitigationSignals.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Indicators\\HmaMitigationSignals\\HmaMitigationSignals\\HmaMitigationSignals.csproj",
"projectName": "HmaMitigationSignals",
"projectPath": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Indicators\\HmaMitigationSignals\\HmaMitigationSignals\\HmaMitigationSignals.csproj",
"packagesPath": "C:\\Users\\Brummel\\.nuget\\packages\\",
"outputPath": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Indicators\\HmaMitigationSignals\\HmaMitigationSignals\\obj\\",
"projectStyle": "PackageReference",
"configFilePaths": [
"C:\\Users\\Brummel\\AppData\\Roaming\\NuGet\\NuGet.Config"
],
"originalTargetFrameworks": [
"net6.0"
],
"sources": {
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net6.0": {
"targetAlias": "net6.0",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
}
},
"frameworks": {
"net6.0": {
"targetAlias": "net6.0",
"dependencies": {
"cTrader.Automate": {
"target": "Package",
"version": "[*, )"
}
},
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\6.0.200\\RuntimeIdentifierGraph.json"
}
}
}
}
}
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\Brummel\.nuget\packages\</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.1.0</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="C:\Users\Brummel\.nuget\packages\" />
</ItemGroup>
<ImportGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<Import Project="$(NuGetPackageRoot)ctrader.automate\1.0.14\build\cTrader.Automate.props" Condition="Exists('$(NuGetPackageRoot)ctrader.automate\1.0.14\build\cTrader.Automate.props')" />
</ImportGroup>
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<PkgcTrader_Automate Condition=" '$(PkgcTrader_Automate)' == '' ">C:\Users\Brummel\.nuget\packages\ctrader.automate\1.0.14</PkgcTrader_Automate>
</PropertyGroup>
</Project>
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<Import Project="$(NuGetPackageRoot)ctrader.automate\1.0.14\build\cTrader.Automate.targets" Condition="Exists('$(NuGetPackageRoot)ctrader.automate\1.0.14\build\cTrader.Automate.targets')" />
</ImportGroup>
</Project>
@@ -0,0 +1,139 @@
{
"version": 3,
"targets": {
"net6.0": {
"cTrader.Automate/1.0.14": {
"type": "package",
"compile": {
"lib/net6.0/cAlgo.API.dll": {}
},
"runtime": {
"lib/net6.0/cAlgo.API.dll": {}
},
"build": {
"build/cTrader.Automate.props": {},
"build/cTrader.Automate.targets": {}
}
}
}
},
"libraries": {
"cTrader.Automate/1.0.14": {
"sha512": "eNwE7WL90MGBKb5MuLAtZLdQy0vxkI5EVhLWAQ9S83EAdYkGAzdccvGFLk2oqmtSGBtD+gEpyrJUW/ej4dI4jw==",
"type": "package",
"path": "ctrader.automate/1.0.14",
"hasTools": true,
"files": [
".nupkg.metadata",
".signature.p7s",
"build/cTrader.Automate.props",
"build/cTrader.Automate.targets",
"ctrader.automate.1.0.14.nupkg.sha512",
"ctrader.automate.nuspec",
"eula.md",
"icon.png",
"lib/net40/cAlgo.API.dll",
"lib/net40/cAlgo.API.xml",
"lib/net6.0/cAlgo.API.dll",
"lib/net6.0/cAlgo.API.xml",
"tools/net472/Core.AlgoFormat.Compose.Reflection.dll",
"tools/net472/Core.AlgoFormat.Writer.dll",
"tools/net472/Core.AlgoFormat.dll",
"tools/net472/Core.Domain.Primitives.dll",
"tools/net472/Newtonsoft.Json.dll",
"tools/net472/System.Buffers.dll",
"tools/net472/System.Collections.Immutable.dll",
"tools/net472/System.Memory.dll",
"tools/net472/System.Numerics.Vectors.dll",
"tools/net472/System.Reflection.Metadata.dll",
"tools/net472/System.Reflection.MetadataLoadContext.dll",
"tools/net472/System.Runtime.CompilerServices.Unsafe.dll",
"tools/net472/cTrader.Automate.Sdk.Tasks.dll",
"tools/net6.0/Core.AlgoFormat.Compose.Reflection.dll",
"tools/net6.0/Core.AlgoFormat.Writer.dll",
"tools/net6.0/Core.AlgoFormat.dll",
"tools/net6.0/Core.Connection.Protobuf.Common.dll",
"tools/net6.0/Core.Domain.Primitives.dll",
"tools/net6.0/Microsoft.Win32.SystemEvents.dll",
"tools/net6.0/Newtonsoft.Json.dll",
"tools/net6.0/System.Drawing.Common.dll",
"tools/net6.0/System.Reflection.MetadataLoadContext.dll",
"tools/net6.0/System.Security.Permissions.dll",
"tools/net6.0/System.Windows.Extensions.dll",
"tools/net6.0/cTrader.Automate.Sdk.Tasks.dll",
"tools/net6.0/protobuf-net.Core.dll",
"tools/net6.0/protobuf-net.dll",
"tools/net6.0/runtimes/unix/lib/net6.0/System.Drawing.Common.dll",
"tools/net6.0/runtimes/win/lib/net6.0/Microsoft.Win32.SystemEvents.dll",
"tools/net6.0/runtimes/win/lib/net6.0/System.Drawing.Common.dll",
"tools/net6.0/runtimes/win/lib/net6.0/System.Windows.Extensions.dll"
]
}
},
"projectFileDependencyGroups": {
"net6.0": [
"cTrader.Automate >= *"
]
},
"packageFolders": {
"C:\\Users\\Brummel\\.nuget\\packages\\": {}
},
"project": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Indicators\\HmaMitigationSignals\\HmaMitigationSignals\\HmaMitigationSignals.csproj",
"projectName": "HmaMitigationSignals",
"projectPath": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Indicators\\HmaMitigationSignals\\HmaMitigationSignals\\HmaMitigationSignals.csproj",
"packagesPath": "C:\\Users\\Brummel\\.nuget\\packages\\",
"outputPath": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Indicators\\HmaMitigationSignals\\HmaMitigationSignals\\obj\\",
"projectStyle": "PackageReference",
"configFilePaths": [
"C:\\Users\\Brummel\\AppData\\Roaming\\NuGet\\NuGet.Config"
],
"originalTargetFrameworks": [
"net6.0"
],
"sources": {
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net6.0": {
"targetAlias": "net6.0",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
}
},
"frameworks": {
"net6.0": {
"targetAlias": "net6.0",
"dependencies": {
"cTrader.Automate": {
"target": "Package",
"version": "[*, )"
}
},
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\6.0.200\\RuntimeIdentifierGraph.json"
}
}
}
}
@@ -0,0 +1,10 @@
{
"version": 2,
"dgSpecHash": "DxEeUy28ZBdzEtfthwL77wzQ4ke6Qq+9ihU8hGHHq9Zkz9SR9yfNrOVC7zcjvC2fluF4I2zsexRZHVqmVVc3IA==",
"success": true,
"projectFilePath": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Indicators\\HmaMitigationSignals\\HmaMitigationSignals\\HmaMitigationSignals.csproj",
"expectedPackageFiles": [
"C:\\Users\\Brummel\\.nuget\\packages\\ctrader.automate\\1.0.14\\ctrader.automate.1.0.14.nupkg.sha512"
],
"logs": []
}