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
+1
View File
@@ -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}") = "Multi-MA-Bot", "Multi-MA-Bot\Multi-MA-Bot.csproj", "{a62c61af-44d7-443c-9f8a-242c717d8d45}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{a62c61af-44d7-443c-9f8a-242c717d8d45}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{a62c61af-44d7-443c-9f8a-242c717d8d45}.Debug|Any CPU.Build.0 = Debug|Any CPU
{a62c61af-44d7-443c-9f8a-242c717d8d45}.Release|Any CPU.ActiveCfg = Release|Any CPU
{a62c61af-44d7-443c-9f8a-242c717d8d45}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
@@ -0,0 +1,208 @@
using cAlgo.API;
using cAlgo.API.Indicators;
using System;
using System.Linq;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class KeltnerSlopeTickBot : Robot
{
[Parameter("HMA Period", DefaultValue = 250, Group = "Indicators")]
public int HmaPeriod { get; set; }
[Parameter("SMA Period", DefaultValue = 200, Group = "Indicators")]
public int SmaPeriod { get; set; }
[Parameter("KC Centerline Period", DefaultValue = 20, Group = "Indicators")]
public int KeltnerSmaPeriod { get; set; }
[Parameter("KC ATR Period", DefaultValue = 20, Group = "Indicators")]
public int KeltnerAtrPeriod { get; set; }
[Parameter("KC ATR MA Type", DefaultValue = MovingAverageType.Hull, Group = "Indicators")]
public MovingAverageType KeltnerAtrMaType { get; set; }
[Parameter("KC Band Distance", DefaultValue = 2.0, Group = "Indicators")]
public double KeltnerBandDistance { get; set; }
[Parameter("Equity Risk %", DefaultValue = 1.0, Group = "Trading")]
public double EquityRiskPercent { get; set; }
[Parameter("Max Open Positions", DefaultValue = 10, Group = "Trading")]
public int MaxPositions { get; set; }
[Parameter("Drawing History (Bars)", DefaultValue = 500, Group = "Display")]
public int DrawingHistory { get; set; }
private HullMovingAverage _hma;
private SimpleMovingAverage _sma;
private KeltnerChannels _keltnerChannels;
// KORREKTUR: Variablen zum Speichern des vorherigen Tick-Preises.
private double _previousAsk;
private double _previousBid;
private const string BotLabelPrefix = "KeltnerBot";
private const string HmaLinePrefix = "Bot_HMA";
private const string SmaLinePrefix = "Bot_SMA";
private const string KcTopLinePrefix = "Bot_KC_Top";
private const string KcMainLinePrefix = "Bot_KC_Main";
private const string KcBottomLinePrefix = "Bot_KC_Bottom";
protected override void OnStart()
{
_hma = Indicators.HullMovingAverage(Bars.ClosePrices, HmaPeriod);
_sma = Indicators.SimpleMovingAverage(Bars.ClosePrices, SmaPeriod);
_keltnerChannels = Indicators.KeltnerChannels(KeltnerSmaPeriod, MovingAverageType.Simple, KeltnerAtrPeriod, KeltnerAtrMaType, KeltnerBandDistance);
Positions.Opened += OnPositionOpened;
// KORREKTUR: Initialisiert die Preis-Variablen, um eine falsche Auslösung beim ersten Tick zu vermeiden.
_previousAsk = Symbol.Ask;
_previousBid = Symbol.Bid;
}
protected override void OnStop()
{
Chart.RemoveAllObjects();
}
protected override void OnBar()
{
DrawIndicators();
RemoveOldSegments();
}
protected override void OnTick()
{
if (Positions.Count >= MaxPositions)
{
return;
}
var hmaSlope = _hma.Result.Last(1) - _hma.Result.Last(2);
var smaSlope = _sma.Result.Last(1) - _sma.Result.Last(2);
var keltnerMainSlope = _keltnerChannels.Main.Last(1) - _keltnerChannels.Main.Last(2);
var kcMain = _keltnerChannels.Main.Last(1);
// Long-Entry-Logik
bool isUpTrend = hmaSlope > 0 && smaSlope > 0;
// KORREKTUR: Verwendet den gespeicherten _previousAsk für einen echten Tick-basierten Kreuzungsvergleich.
bool isBuyCross = _previousAsk <= kcMain && Symbol.Ask > kcMain;
if (isUpTrend && isBuyCross)
{
var stopLossPrice = _keltnerChannels.Bottom.Last(1);
var takeProfitPrice = _keltnerChannels.Top.Last(1);
if (stopLossPrice >= Symbol.Ask)
{
UpdatePreviousPrices();
return;
}
var stopLossInPips = (Symbol.Ask - stopLossPrice) / Symbol.PipSize;
var takeProfitInPips = (takeProfitPrice - Symbol.Ask) / Symbol.PipSize;
double? volumeInUnits = Symbol.VolumeForProportionalRisk(ProportionalAmountType.Equity, EquityRiskPercent / MaxPositions / 100, stopLossPrice);
if (volumeInUnits.HasValue)
{
var normalizedVolume = Symbol.NormalizeVolumeInUnits(volumeInUnits.Value, RoundingMode.Down);
if (normalizedVolume > 0)
{
ExecuteMarketOrder(TradeType.Buy, SymbolName, normalizedVolume, $"{BotLabelPrefix}_Buy", stopLossInPips, takeProfitInPips);
}
}
}
// Short-Entry-Logik
bool isDownTrend = hmaSlope < 0 && smaSlope < 0;
// KORREKTUR: Verwendet den gespeicherten _previousBid für einen echten Tick-basierten Kreuzungsvergleich.
bool isSellCross = _previousBid >= kcMain && Symbol.Bid < kcMain;
if (isDownTrend && isSellCross)
{
var stopLossPrice = _keltnerChannels.Top.Last(1);
var takeProfitPrice = _keltnerChannels.Bottom.Last(1);
if (stopLossPrice <= Symbol.Bid)
{
UpdatePreviousPrices();
return;
}
var stopLossInPips = (stopLossPrice - Symbol.Bid) / Symbol.PipSize;
var takeProfitInPips = (Symbol.Bid - takeProfitPrice) / Symbol.PipSize;
double? volumeInUnits = Symbol.VolumeForProportionalRisk(ProportionalAmountType.Equity, EquityRiskPercent / MaxPositions / 100, stopLossPrice);
if (volumeInUnits.HasValue)
{
var normalizedVolume = Symbol.NormalizeVolumeInUnits(volumeInUnits.Value, RoundingMode.Down);
if (normalizedVolume > 0)
{
ExecuteMarketOrder(TradeType.Sell, SymbolName, normalizedVolume, $"{BotLabelPrefix}_Sell", stopLossInPips, takeProfitInPips);
}
}
}
// KORREKTUR: Speichert die aktuellen Preise für den nächsten Tick.
UpdatePreviousPrices();
}
private void UpdatePreviousPrices()
{
_previousAsk = Symbol.Ask;
_previousBid = Symbol.Bid;
}
private void OnPositionOpened(PositionOpenedEventArgs args)
{
var position = args.Position;
if (!position.Label.StartsWith(BotLabelPrefix))
{
return;
}
if (!position.StopLoss.HasValue || !position.TakeProfit.HasValue)
{
Print("KRITISCHER FEHLER: Position {0} ({1}) wurde ohne StopLoss oder TakeProfit eröffnet. Bot wird gestoppt.", position.Id, position.Label);
Stop();
}
}
private void DrawIndicators()
{
// Da Indikatorwerte sich nur auf Bar-Basis ändern, ist eine Aktualisierung pro Tick nicht nötig.
// Die Ausführung im OnBar spart daher Rechenleistung.
var previousBarTime = Bars.OpenTimes.Last(2);
var currentBarTime = Bars.OpenTimes.Last(1);
string uniqueSuffix = $"_{currentBarTime:o}";
Chart.DrawTrendLine(HmaLinePrefix + uniqueSuffix, previousBarTime, _hma.Result.Last(2), currentBarTime, _hma.Result.Last(1), Color.Purple);
Chart.DrawTrendLine(SmaLinePrefix + uniqueSuffix, previousBarTime, _sma.Result.Last(2), currentBarTime, _sma.Result.Last(1), Color.Orange);
Chart.DrawTrendLine(KcTopLinePrefix + uniqueSuffix, previousBarTime, _keltnerChannels.Top.Last(2), currentBarTime, _keltnerChannels.Top.Last(1), Color.Blue);
Chart.DrawTrendLine(KcMainLinePrefix + uniqueSuffix, previousBarTime, _keltnerChannels.Main.Last(2), currentBarTime, _keltnerChannels.Main.Last(1), Color.Blue, 2, LineStyle.Dots);
Chart.DrawTrendLine(KcBottomLinePrefix + uniqueSuffix, previousBarTime, _keltnerChannels.Bottom.Last(2), currentBarTime, _keltnerChannels.Bottom.Last(1), Color.Blue);
}
private void RemoveOldSegments()
{
if (Bars.Count <= DrawingHistory)
{
return;
}
var oldBarTime = Bars.OpenTimes.Last(DrawingHistory);
string oldUniqueSuffix = $"_{oldBarTime:o}";
Chart.RemoveObject(HmaLinePrefix + oldUniqueSuffix);
Chart.RemoveObject(SmaLinePrefix + oldUniqueSuffix);
Chart.RemoveObject(KcTopLinePrefix + oldUniqueSuffix);
Chart.RemoveObject(KcMainLinePrefix + oldUniqueSuffix);
Chart.RemoveObject(KcBottomLinePrefix + oldUniqueSuffix);
}
}
}
@@ -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("Multi-MA-Bot")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("Multi-MA-Bot")]
[assembly: System.Reflection.AssemblyTitleAttribute("Multi-MA-Bot")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Generated by the MSBuild WriteCodeFragment class.
@@ -0,0 +1 @@
f0e854385f2f3e45c8832fc57c8188402c93f659
@@ -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 = Multi-MA-Bot
build_property.ProjectDir = C:\Users\Brummel\Documents\cAlgo\Sources\Robots\Multi-MA-Bot\Multi-MA-Bot\
@@ -0,0 +1,66 @@
{
"format": 1,
"restore": {
"C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\Multi-MA-Bot\\Multi-MA-Bot\\Multi-MA-Bot.csproj": {}
},
"projects": {
"C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\Multi-MA-Bot\\Multi-MA-Bot\\Multi-MA-Bot.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\Multi-MA-Bot\\Multi-MA-Bot\\Multi-MA-Bot.csproj",
"projectName": "Multi-MA-Bot",
"projectPath": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\Multi-MA-Bot\\Multi-MA-Bot\\Multi-MA-Bot.csproj",
"packagesPath": "C:\\Users\\Brummel\\.nuget\\packages\\",
"outputPath": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\Multi-MA-Bot\\Multi-MA-Bot\\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.12\build\cTrader.Automate.props" Condition="Exists('$(NuGetPackageRoot)ctrader.automate\1.0.12\build\cTrader.Automate.props')" />
</ImportGroup>
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<PkgcTrader_Automate Condition=" '$(PkgcTrader_Automate)' == '' ">C:\Users\Brummel\.nuget\packages\ctrader.automate\1.0.12</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.12\build\cTrader.Automate.targets" Condition="Exists('$(NuGetPackageRoot)ctrader.automate\1.0.12\build\cTrader.Automate.targets')" />
</ImportGroup>
</Project>
@@ -0,0 +1,139 @@
{
"version": 3,
"targets": {
"net6.0": {
"cTrader.Automate/1.0.12": {
"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.12": {
"sha512": "h+HPnbqPTkoSeojoYwWWOo5Jm9ExkmrmsU/WbF/idcgO2auKAPILBghZRP6Qt5mAcE/40YCRMNHT45/kzzs5Sg==",
"type": "package",
"path": "ctrader.automate/1.0.12",
"hasTools": true,
"files": [
".nupkg.metadata",
".signature.p7s",
"build/cTrader.Automate.props",
"build/cTrader.Automate.targets",
"ctrader.automate.1.0.12.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\\Robots\\Multi-MA-Bot\\Multi-MA-Bot\\Multi-MA-Bot.csproj",
"projectName": "Multi-MA-Bot",
"projectPath": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\Multi-MA-Bot\\Multi-MA-Bot\\Multi-MA-Bot.csproj",
"packagesPath": "C:\\Users\\Brummel\\.nuget\\packages\\",
"outputPath": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\Multi-MA-Bot\\Multi-MA-Bot\\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": "s24EynUesZSOJz4qpScvhH/N2ttt5lPGd0hG4jf8I3vVmHtQs2Uc8fTWUsUUbz6o6oRXLPvvXBfrOfuejLIKog==",
"success": true,
"projectFilePath": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\Multi-MA-Bot\\Multi-MA-Bot\\Multi-MA-Bot.csproj",
"expectedPackageFiles": [
"C:\\Users\\Brummel\\.nuget\\packages\\ctrader.automate\\1.0.12\\ctrader.automate.1.0.12.nupkg.sha512"
],
"logs": []
}