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
Binary file not shown.
+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}") = "HMACrossBot", "HMACrossBot\HMACrossBot.csproj", "{7acd261c-177a-4980-a562-d7b8d3f6feb4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7acd261c-177a-4980-a562-d7b8d3f6feb4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7acd261c-177a-4980-a562-d7b8d3f6feb4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7acd261c-177a-4980-a562-d7b8d3f6feb4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7acd261c-177a-4980-a562-d7b8d3f6feb4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
@@ -0,0 +1,148 @@
using System;
using System.Linq; // Required for .Where() and .Count()
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo.Robots
{
// Strategy based on two HMAs (fast and slow)
[Robot(AccessRights = AccessRights.None, TimeZone = TimeZones.UTC)]
public class HMACrossBot : Robot
{
[Parameter("Fast HMA Period", DefaultValue = 20, MinValue = 2)]
public int FastHmaPeriod { get; set; }
[Parameter("Slow HMA Period", DefaultValue = 25, MinValue = 2)]
public int SlowHmaPeriod { get; set; }
[Parameter("Max Positions (per side)", DefaultValue = 3, MinValue = 1)]
public int MaxPositions { get; set; }
[Parameter("Volume (Units)", DefaultValue = 0.1, MinValue = 0.1)]
public double VolumeInUnits { get; set; }
private HullMovingAverage _fastHma;
private HullMovingAverage _slowHma;
// A unique label to identify positions opened by this cBot instance
private string _botLabel;
// Initialize indicators and check parameters
protected override void OnStart()
{
if (FastHmaPeriod >= SlowHmaPeriod)
{
Print("Error: Fast HMA Period must be less than Slow HMA Period for this logic.");
Stop();
return;
}
_fastHma = Indicators.HullMovingAverage(Bars.ClosePrices, FastHmaPeriod);
_slowHma = Indicators.HullMovingAverage(Bars.ClosePrices, SlowHmaPeriod);
// Generate a unique label for this cBot instance
_botLabel = $"HMACrossBot_{SymbolName}_{TimeFrame}_{InstanceId}";
}
// Main logic executed at the close of each bar
protected override void OnBar()
{
// Ensure we have enough data to calculate HMA direction
if (_slowHma.Result.Count < 3)
{
return;
}
// --- 1. Get HMA values ---
// Use index 1 (the most recently closed bar) as OnBar fires at the close.
double fastHmaCurrent = _fastHma.Result.Last(1);
double slowHmaCurrent = _slowHma.Result.Last(1);
double slowHmaPrevious = _slowHma.Result.Last(2);
// --- 2. Check Exit Conditions (Close First) ---
// Close all LONG positions if fast HMA crosses below or equals slow HMA
if (fastHmaCurrent <= slowHmaCurrent)
{
ClosePositions(TradeType.Buy);
}
// Close all SHORT positions if fast HMA crosses above or equals slow HMA
// (Corrected: Use TradeType.Sell, not .Short)
if (fastHmaCurrent >= slowHmaCurrent)
{
ClosePositions(TradeType.Sell);
}
// --- 3. Check Entry Conditions (Open After) ---
// Get current positions count (check only positions managed by this bot)
int longPositionsCount = Positions.Count(p => p.Label == _botLabel && p.SymbolName == SymbolName && p.TradeType == TradeType.Buy);
// (Corrected: Use TradeType.Sell, not .Short)
int shortPositionsCount = Positions.Count(p => p.Label == _botLabel && p.SymbolName == SymbolName && p.TradeType == TradeType.Sell);
// LONG Entry: fast > slow AND slow is rising
if ((fastHmaCurrent > slowHmaCurrent) && (slowHmaCurrent > slowHmaPrevious))
{
if (longPositionsCount < MaxPositions)
{
ExecuteTrade(TradeType.Buy);
}
}
// SHORT Entry: fast < slow AND slow is falling
if ((fastHmaCurrent < slowHmaCurrent) && (slowHmaCurrent < slowHmaPrevious))
{
if (shortPositionsCount < MaxPositions)
{
// (Corrected: Use TradeType.Sell, not .Short)
ExecuteTrade(TradeType.Sell);
}
}
}
// Helper to execute a trade with normalized volume
private void ExecuteTrade(TradeType tradeType)
{
// Normalize volume to the symbol's requirements
double volumeToTrade = Symbol.NormalizeVolumeInUnits(VolumeInUnits, RoundingMode.ToNearest);
// Ensure minimum volume is met
if (volumeToTrade < Symbol.VolumeInUnitsMin)
{
volumeToTrade = Symbol.VolumeInUnitsMin;
}
ExecuteMarketOrder(tradeType, SymbolName, volumeToTrade, _botLabel);
}
// Helper to close all positions of a specific type
private void ClosePositions(TradeType tradeType)
{
// Find all positions for the specified trade type and label
// (Corrected: Removed 'IsClosing' check, as it's not on Position interface)
var positionsToClose = Positions
.Where(p => p.Label == _botLabel &&
p.SymbolName == SymbolName &&
p.TradeType == tradeType)
.ToList();
foreach (var position in positionsToClose)
{
// Asynchronously close each position
ClosePositionAsync(position);
}
}
protected override void OnStop()
{
// cBot is stopping
}
protected override void OnTick()
{
// All logic is handled OnBar in this strategy
}
}
}
@@ -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("HMACrossBot")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("HMACrossBot")]
[assembly: System.Reflection.AssemblyTitleAttribute("HMACrossBot")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Generated by the MSBuild WriteCodeFragment class.
@@ -0,0 +1 @@
f7a58568308eab12ad2da8f697114353004279fa
@@ -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 = HMACrossBot
build_property.ProjectDir = C:\Users\Brummel\Documents\cAlgo\Sources\Robots\HMACrossBot\HMACrossBot\
@@ -0,0 +1,66 @@
{
"format": 1,
"restore": {
"C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\HMACrossBot\\HMACrossBot\\HMACrossBot.csproj": {}
},
"projects": {
"C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\HMACrossBot\\HMACrossBot\\HMACrossBot.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\HMACrossBot\\HMACrossBot\\HMACrossBot.csproj",
"projectName": "HMACrossBot",
"projectPath": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\HMACrossBot\\HMACrossBot\\HMACrossBot.csproj",
"packagesPath": "C:\\Users\\Brummel\\.nuget\\packages\\",
"outputPath": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\HMACrossBot\\HMACrossBot\\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\\Robots\\HMACrossBot\\HMACrossBot\\HMACrossBot.csproj",
"projectName": "HMACrossBot",
"projectPath": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\HMACrossBot\\HMACrossBot\\HMACrossBot.csproj",
"packagesPath": "C:\\Users\\Brummel\\.nuget\\packages\\",
"outputPath": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\HMACrossBot\\HMACrossBot\\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": "K2rUaOKUIqRJ+x6ANzVtKPk1+58QBQ2T6CNqLozyqXgru9j1i7/TzPvsHUDY/xQrYcV+KOxXpy8WirqosKokuQ==",
"success": true,
"projectFilePath": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\HMACrossBot\\HMACrossBot\\HMACrossBot.csproj",
"expectedPackageFiles": [
"C:\\Users\\Brummel\\.nuget\\packages\\ctrader.automate\\1.0.14\\ctrader.automate.1.0.14.nupkg.sha512"
],
"logs": []
}
Binary file not shown.
@@ -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}") = "Hma20CandleStartegy_V1", "Hma20CandleStartegy_V1\Hma20CandleStartegy_V1.csproj", "{f2e9a40a-78e5-4641-8770-59be963064e1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{f2e9a40a-78e5-4641-8770-59be963064e1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{f2e9a40a-78e5-4641-8770-59be963064e1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{f2e9a40a-78e5-4641-8770-59be963064e1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{f2e9a40a-78e5-4641-8770-59be963064e1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
@@ -0,0 +1,130 @@
using cAlgo.API;
using cAlgo.API.Indicators;
using System;
namespace cAlgo.Robots
{
// A simple trading strategy based on HMA slope and candle patterns.
[Robot(AccessRights = AccessRights.None)]
public class HmaBiasStrategy : Robot
{
[Parameter("HMA Period", DefaultValue = 20, Group = "Parameters")]
public int HmaPeriod { get; set; }
[Parameter("ATR Period", DefaultValue = 14, Group = "Parameters")]
public int AtrPeriod { get; set; }
[Parameter("ATR Multiplier for SL", DefaultValue = 4.0, Group = "Parameters")]
public double AtrMultiplier { get; set; }
[Parameter("Volume (Units)", DefaultValue = 10000, MinValue = 1000, Group = "Parameters")]
public double VolumeInUnits { get; set; }
[Parameter("Wick Ratio (Lower > Upper * Ratio)", DefaultValue = 2.0, Group = "Parameters")]
public double WickRatio { get; set; }
[Parameter("Trade Label", DefaultValue = "HmaBiasStrategy", Group = "Parameters")]
public string Label { get; set; }
// Hull Moving Average for trend direction and momentum.
private HullMovingAverage _hma;
// Average True Range for Stop Loss calculation.
private AverageTrueRange _atr;
// Holds the currently open position.
private Position _position;
// Tracks the bar index when a position was opened.
private int _entryBarIndex;
// Initialize indicators and state variables.
protected override void OnStart()
{
_hma = Indicators.HullMovingAverage(Bars.ClosePrices, HmaPeriod);
_atr = Indicators.AverageTrueRange(AtrPeriod, MovingAverageType.Simple);
_position = null;
_entryBarIndex = -1;
}
// Main logic, executed on every bar close.
protected override void OnBar()
{
// First, check if we need to close the existing position.
if ((_position != null) && (Bars.Count - 1 > _entryBarIndex))
{
ClosePosition(_position);
_position = null;
}
// If no position is open, check for a new entry signal.
if (_position == null)
{
// Ensure we have enough data for the lookback.
if (Bars.Count < HmaPeriod + 5)
{
return;
}
// --- Bias Calculation on PREVIOUS bar ---
var hmaPrev = _hma.Result.Last(2);
var hmaPrev2 = _hma.Result.Last(3);
var hmaPrev3 = _hma.Result.Last(4);
var slopeOnPrevBar = hmaPrev - hmaPrev2;
var slopeOnPrevBar2 = hmaPrev2 - hmaPrev3;
// Check if the bias was bullish on the bar that just closed before this one.
bool previousBarHadBullishBias = (slopeOnPrevBar > 0) && (slopeOnPrevBar > slopeOnPrevBar2);
if (previousBarHadBullishBias)
{
// --- Signal Check on CURRENT bar ---
var currentBar = Bars.LastBar;
var previousBar = Bars.Last(1); // This is the bar that had the bias
bool signalTriggered = false;
// Signal 1: Current bar's close is above the previous bar's high.
if (currentBar.Close > previousBar.High)
{
signalTriggered = true;
}
// Signal 2: Current bar is a bullish candle with a long lower wick.
bool isBullishCandle = currentBar.Close > currentBar.Open;
if ((!signalTriggered) && (isBullishCandle))
{
double lowerWick = currentBar.Open - currentBar.Low;
double upperWick = currentBar.High - currentBar.Close;
if (lowerWick > (upperWick * WickRatio))
{
signalTriggered = true;
}
}
// --- Execute Trade ---
if (signalTriggered)
{
var volumeInUnits = Symbol.NormalizeVolumeInUnits(VolumeInUnits, RoundingMode.ToNearest);
var stopLossPips = _atr.Result.LastValue * AtrMultiplier / Symbol.PipSize;
var result = ExecuteMarketOrder(TradeType.Buy, Symbol.Name, volumeInUnits, Label, stopLossPips, null);
if (result.IsSuccessful)
{
_position = result.Position;
_entryBarIndex = Bars.Count - 1;
}
}
}
}
}
// Ensure any open position is closed when the cBot stops.
protected override void OnStop()
{
if (_position != null)
{
ClosePosition(_position);
_position = null;
}
}
}
}
@@ -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("Hma20CandleStartegy_V1")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("Hma20CandleStartegy_V1")]
[assembly: System.Reflection.AssemblyTitleAttribute("Hma20CandleStartegy_V1")]
[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 = Hma20CandleStartegy_V1
build_property.ProjectDir = C:\Users\Brummel\Documents\cAlgo\Sources\Robots\Hma20CandleStartegy_V1\Hma20CandleStartegy_V1\
@@ -0,0 +1,66 @@
{
"format": 1,
"restore": {
"C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\Hma20CandleStartegy_V1\\Hma20CandleStartegy_V1\\Hma20CandleStartegy_V1.csproj": {}
},
"projects": {
"C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\Hma20CandleStartegy_V1\\Hma20CandleStartegy_V1\\Hma20CandleStartegy_V1.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\Hma20CandleStartegy_V1\\Hma20CandleStartegy_V1\\Hma20CandleStartegy_V1.csproj",
"projectName": "Hma20CandleStartegy_V1",
"projectPath": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\Hma20CandleStartegy_V1\\Hma20CandleStartegy_V1\\Hma20CandleStartegy_V1.csproj",
"packagesPath": "C:\\Users\\Brummel\\.nuget\\packages\\",
"outputPath": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\Hma20CandleStartegy_V1\\Hma20CandleStartegy_V1\\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.13\build\cTrader.Automate.props" Condition="Exists('$(NuGetPackageRoot)ctrader.automate\1.0.13\build\cTrader.Automate.props')" />
</ImportGroup>
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<PkgcTrader_Automate Condition=" '$(PkgcTrader_Automate)' == '' ">C:\Users\Brummel\.nuget\packages\ctrader.automate\1.0.13</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.13\build\cTrader.Automate.targets" Condition="Exists('$(NuGetPackageRoot)ctrader.automate\1.0.13\build\cTrader.Automate.targets')" />
</ImportGroup>
</Project>
@@ -0,0 +1,139 @@
{
"version": 3,
"targets": {
"net6.0": {
"cTrader.Automate/1.0.13": {
"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.13": {
"sha512": "teFQQhvFb8/1XQsvvGXNlUIkwZ6Ab+FZHqJ8kXiR2AW8IJA0EIue2dRHNglmlRdqSwnMhocSS9EkPZBTXxsHLQ==",
"type": "package",
"path": "ctrader.automate/1.0.13",
"hasTools": true,
"files": [
".nupkg.metadata",
".signature.p7s",
"build/cTrader.Automate.props",
"build/cTrader.Automate.targets",
"ctrader.automate.1.0.13.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\\Hma20CandleStartegy_V1\\Hma20CandleStartegy_V1\\Hma20CandleStartegy_V1.csproj",
"projectName": "Hma20CandleStartegy_V1",
"projectPath": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\Hma20CandleStartegy_V1\\Hma20CandleStartegy_V1\\Hma20CandleStartegy_V1.csproj",
"packagesPath": "C:\\Users\\Brummel\\.nuget\\packages\\",
"outputPath": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\Hma20CandleStartegy_V1\\Hma20CandleStartegy_V1\\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": "KAVywmsuuoI+N5Yoz0EqytZDCBvv/kG4rq4cxtRVij8d4jb5sQvxFq6zhsdVSKst9ebEbkC7kERvAUjuJ6BsPw==",
"success": true,
"projectFilePath": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\Hma20CandleStartegy_V1\\Hma20CandleStartegy_V1\\Hma20CandleStartegy_V1.csproj",
"expectedPackageFiles": [
"C:\\Users\\Brummel\\.nuget\\packages\\ctrader.automate\\1.0.13\\ctrader.automate.1.0.13.nupkg.sha512"
],
"logs": []
}
Binary file not shown.
+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}") = "HmaClusterBot", "HmaClusterBot\HmaClusterBot.csproj", "{5ca67298-283e-4125-b2b7-5ca1cceeb315}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5ca67298-283e-4125-b2b7-5ca1cceeb315}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5ca67298-283e-4125-b2b7-5ca1cceeb315}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5ca67298-283e-4125-b2b7-5ca1cceeb315}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5ca67298-283e-4125-b2b7-5ca1cceeb315}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
@@ -0,0 +1,936 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class HmaClusterBot : Robot
{
#region Parameters
[Parameter("Symbols (CSV)", DefaultValue = "", Group = "Multi Symbol")]
public string SymbolsCsv { get; set; }
[Parameter("Risk % of Balance", DefaultValue = 1.0, MinValue = 0.1, MaxValue = 10.0, Group = "Risk")]
public double RiskPercent { get; set; }
[Parameter("Entry Significance %", DefaultValue = 20.0, MinValue = 1.0, Group = "Thresholds")]
public double EntrySigThreshold { get; set; }
[Parameter("Stop Loss Significance %", DefaultValue = 10.0, MinValue = 1.0, Group = "Thresholds")]
public double SlSigThreshold { get; set; }
[Parameter("SMA Bias Period", DefaultValue = 200, Group = "Bias")]
public int SmaBiasPeriod { get; set; }
[Parameter("HMA Bias Period", DefaultValue = 250, Group = "Bias")]
public int HmaBiasPeriod { get; set; }
[Parameter("Use Bias Deviation Filter", DefaultValue = true, Group = "Bias Filter")]
public bool UseBiasDeviationFilter { get; set; }
[Parameter("Bias Deviation Avg Period", DefaultValue = 500, Group = "Bias Filter")]
public int BiasDeviationAvgPeriod { get; set; }
[Parameter("Use Dynamic Position Management", DefaultValue = true, Group = "Management")]
public bool UseDynamicPositionManagement { get; set; }
[Parameter("Close Profit on Bias Flip", DefaultValue = false, Group = "Management")]
public bool CloseProfitOnBiasFlip { get; set; }
[Parameter("HMA Cluster Period", DefaultValue = 25, Group = "Clusters")]
public int HmaClusterPeriod { get; set; }
[Parameter("Cluster Max Points", DefaultValue = 2000, Group = "Clusters")]
public int MaxPoints { get; set; }
[Parameter("Cluster Decay (Bars)", DefaultValue = 1000, Group = "Clusters")]
public int DecayPeriod { get; set; }
// --- Telegram Parameters ---
[Parameter("Send Telegram Only", DefaultValue = false, Group = "Telegram")]
public bool SendTelegramOnly { get; set; }
[Parameter("Telegram Bot Token", DefaultValue = "", Group = "Telegram")]
public string TelegramBotToken { get; set; }
[Parameter("Telegram Chat ID", DefaultValue = "", Group = "Telegram")]
public string TelegramChatId { get; set; }
#endregion
private readonly List<ClusterStrategy> _strategies = new List<ClusterStrategy>();
private static readonly HttpClient _httpClient = new HttpClient();
protected override void OnStart()
{
try
{
if (string.IsNullOrWhiteSpace(SymbolsCsv))
{
Print("CSV is empty. Running in Single-Symbol Mode on Chart Symbol.");
var config = new StrategyConfig
{
SymbolName = SymbolName,
EntrySigThreshold = EntrySigThreshold,
SlSigThreshold = SlSigThreshold,
SmaBiasPeriod = SmaBiasPeriod,
HmaBiasPeriod = HmaBiasPeriod,
HmaClusterPeriod = HmaClusterPeriod,
UseBiasDeviationFilter = UseBiasDeviationFilter,
BiasDeviationAvgPeriod = BiasDeviationAvgPeriod,
UseDynamicPositionManagement = UseDynamicPositionManagement,
CloseProfitOnBiasFlip = CloseProfitOnBiasFlip,
SendTelegramOnly = SendTelegramOnly,
RiskPercent = RiskPercent,
MaxPoints = MaxPoints,
DecayPeriod = DecayPeriod
};
var strategy = new ClusterStrategy(this, Symbol, Bars, config, _httpClient, TelegramBotToken, TelegramChatId, BroadcastError);
_strategies.Add(strategy);
strategy.Start();
}
else
{
Print("CSV detected. Running in Multi-Symbol Mode.");
ParseCsvAndCreateStrategies();
}
}
catch (Exception ex)
{
BroadcastError($"CRITICAL STARTUP ERROR: {ex.Message}");
Stop();
}
}
protected override void OnStop()
{
foreach (var strategy in _strategies)
{
strategy.Stop();
}
}
protected override void OnError(Error error)
{
BroadcastError($"TRADING ERROR [{error.Code}]: {error.ToString}");
}
public void BroadcastError(string message)
{
Print(message);
if (!string.IsNullOrWhiteSpace(TelegramBotToken) && !string.IsNullOrWhiteSpace(TelegramChatId))
{
string formattedMsg = $"⚠️ <b>ERROR @ {DateTime.UtcNow:HH:mm:ss} UTC</b>\n\n{message}";
_ = SendTelegramRawAsync(TelegramBotToken, TelegramChatId, formattedMsg);
}
}
private async Task SendTelegramRawAsync(string token, string chatId, string message)
{
try
{
string url = $"https://api.telegram.org/bot{token}/sendMessage?chat_id={chatId}&text={Uri.EscapeDataString(message)}&parse_mode=HTML";
await _httpClient.GetAsync(url);
}
catch (Exception ex)
{
Print("FAILED TO SEND TELEGRAM ERROR: " + ex.Message);
}
}
private void ParseCsvAndCreateStrategies()
{
var normalizedCsv = SymbolsCsv.Replace("\n", ",").Replace("\r", ",");
var tokens = normalizedCsv.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
.Select(t => t.Trim())
.Where(t => !string.IsNullOrEmpty(t))
.ToArray();
int paramsPerSymbol = 10;
if (tokens.Length % paramsPerSymbol != 0)
{
string err = $"CSV Token count ({tokens.Length}) is not a multiple of {paramsPerSymbol}. Check format.";
BroadcastError(err);
}
for (int i = 0; i < tokens.Length; i += paramsPerSymbol)
{
if (i + paramsPerSymbol > tokens.Length) break;
string symName = tokens[i];
try
{
Symbol symbol = Symbols.GetSymbol(symName);
if (symbol == null)
{
BroadcastError($"Symbol '{symName}' not found in cTrader.");
continue;
}
Bars bars = MarketData.GetBars(TimeFrame, symName);
var config = new StrategyConfig
{
SymbolName = symName,
EntrySigThreshold = double.Parse(tokens[i + 1], CultureInfo.InvariantCulture),
SlSigThreshold = double.Parse(tokens[i + 2], CultureInfo.InvariantCulture),
SmaBiasPeriod = int.Parse(tokens[i + 3], CultureInfo.InvariantCulture),
HmaBiasPeriod = int.Parse(tokens[i + 4], CultureInfo.InvariantCulture),
HmaClusterPeriod = int.Parse(tokens[i + 5], CultureInfo.InvariantCulture),
UseBiasDeviationFilter = bool.Parse(tokens[i + 6]),
BiasDeviationAvgPeriod = int.Parse(tokens[i + 7], CultureInfo.InvariantCulture),
UseDynamicPositionManagement = bool.Parse(tokens[i + 8]),
SendTelegramOnly = bool.Parse(tokens[i + 9]),
// Defaults from global params
CloseProfitOnBiasFlip = CloseProfitOnBiasFlip,
RiskPercent = RiskPercent,
MaxPoints = MaxPoints,
DecayPeriod = DecayPeriod
};
var strategy = new ClusterStrategy(this, symbol, bars, config, _httpClient, TelegramBotToken, TelegramChatId, BroadcastError);
_strategies.Add(strategy);
strategy.Start();
Print("Initialized Strategy for {0}", symName);
}
catch (Exception ex)
{
BroadcastError($"Config Error for '{symName}': {ex.Message}");
}
}
}
}
public class StrategyConfig
{
public string SymbolName { get; set; }
public double EntrySigThreshold { get; set; }
public double SlSigThreshold { get; set; }
public int SmaBiasPeriod { get; set; }
public int HmaBiasPeriod { get; set; }
public int HmaClusterPeriod { get; set; }
public bool UseBiasDeviationFilter { get; set; }
public int BiasDeviationAvgPeriod { get; set; }
public bool UseDynamicPositionManagement { get; set; }
public bool CloseProfitOnBiasFlip { get; set; }
public bool SendTelegramOnly { get; set; }
public double RiskPercent { get; set; }
public int MaxPoints { get; set; }
public int DecayPeriod { get; set; }
}
public class ClusterStrategy
{
#region Types & Fields
private enum PointType { Peak, Trough }
private enum Bias { Long, Short, Neutral }
private struct ExtremumPoint
{
public double Price;
public int Index;
public PointType Type;
}
public struct ClusterLevel
{
public double Price;
public double Significance;
}
private readonly Robot _robot;
private readonly Symbol _symbol;
private readonly Bars _bars;
private readonly StrategyConfig _config;
private readonly HttpClient _httpClient;
private readonly string _botToken;
private readonly string _chatId;
private readonly Action<string> _errorCallback;
private SimpleMovingAverage _smaBias;
private HullMovingAverage _hmaBias;
private HullMovingAverage _hmaCluster;
private readonly Queue<double> _deviationQueue = new Queue<double>();
private double _runningDeviationSum;
private bool _deviationConditionMetInCurrentCycle;
private bool _isTradingAllowedBasedOnPrevCycle;
private readonly List<ExtremumPoint> _extremaPoints = new();
private readonly List<double> _amplitudes = new();
private double _trendExtremum;
private int _trendExtremumIndex;
private double _lastExtremumPrice;
private bool? _isUpTrend;
private double _currentDynamicRange;
private const string Label = "HmaClusterBot";
#endregion
public ClusterStrategy(
Robot robot,
Symbol symbol,
Bars bars,
StrategyConfig config,
HttpClient httpClient,
string token,
string chatId,
Action<string> errorCallback)
{
_robot = robot;
_symbol = symbol;
_bars = bars;
_config = config;
_httpClient = httpClient;
_botToken = token;
_chatId = chatId;
_errorCallback = errorCallback;
}
public void Start()
{
int requiredBars = Math.Max(_config.SmaBiasPeriod, _config.HmaBiasPeriod);
requiredBars = Math.Max(requiredBars, _config.BiasDeviationAvgPeriod) + 10;
while (_bars.Count < requiredBars)
{
int loaded = _bars.LoadMoreHistory();
if (loaded == 0)
{
_errorCallback?.Invoke($"Not enough history for {_config.SymbolName}. Loaded: {_bars.Count}, Req: {requiredBars}");
return;
}
}
_smaBias = _robot.Indicators.SimpleMovingAverage(_bars.ClosePrices, _config.SmaBiasPeriod);
_hmaBias = _robot.Indicators.HullMovingAverage(_bars.ClosePrices, _config.HmaBiasPeriod);
_hmaCluster = _robot.Indicators.HullMovingAverage(_bars.ClosePrices, _config.HmaClusterPeriod);
_currentDynamicRange = 5.0 * _symbol.PipSize;
_deviationConditionMetInCurrentCycle = false;
_isTradingAllowedBasedOnPrevCycle = false;
int startIndex = Math.Max(_config.SmaBiasPeriod, _config.HmaBiasPeriod);
startIndex = Math.Max(startIndex, _config.BiasDeviationAvgPeriod);
for (int i = startIndex; i < _bars.Count; i++)
{
UpdateFilterState(i);
UpdateClusterData(i);
}
_bars.BarOpened += OnBarOpened;
}
public void Stop()
{
_bars.BarOpened -= OnBarOpened;
}
private void OnBarOpened(BarOpenedEventArgs obj)
{
try
{
int index = _bars.Count - 2;
if (index < _config.BiasDeviationAvgPeriod) return;
UpdateFilterState(index);
UpdateClusterData(index);
var clusters = CalculateClusters(index);
// 1. Dynamic SL/TP Management
if (!_config.SendTelegramOnly && _config.UseDynamicPositionManagement && clusters.Count >= 2)
{
ManagePositions(clusters);
}
var currentBias = GetCurrentBias(index);
// 2. Check for Profit Close on Bias Flip
if (!_config.SendTelegramOnly && _config.CloseProfitOnBiasFlip)
{
CloseReversedPositions(currentBias);
}
// 3. New Entry Logic with FIXED Orphan-Cleanup and Validations
ManageOrders(currentBias, index, clusters);
}
catch (Exception ex)
{
_errorCallback?.Invoke($"Runtime Error ({_config.SymbolName}): {ex.Message}\n{ex.StackTrace}");
}
}
private void CloseReversedPositions(Bias currentBias)
{
if (currentBias == Bias.Neutral) return;
foreach (var pos in _robot.Positions)
{
if (pos.SymbolName != _config.SymbolName || pos.Label != Label) continue;
if (pos.NetProfit <= 0) continue;
bool close = false;
if (currentBias == Bias.Short && pos.TradeType == TradeType.Buy)
close = true;
else if (currentBias == Bias.Long && pos.TradeType == TradeType.Sell)
close = true;
if (close)
{
var result = _robot.ClosePosition(pos);
if (result.IsSuccessful)
{
string msg = $"🔒 <b>CLOSE PROFIT</b> (Bias Flip) @ <b>{_config.SymbolName}</b>\n" +
$"Profit: {pos.NetProfit:F2}";
_ = SendTelegramMessageAsync(msg);
}
}
}
}
private void UpdateFilterState(int index)
{
double currHma = _hmaBias.Result[index];
double currSma = _smaBias.Result[index];
double prevHma = _hmaBias.Result[index - 1];
double prevSma = _smaBias.Result[index - 1];
double currentBiasDeviation = Math.Abs(currHma - currSma);
_deviationQueue.Enqueue(currentBiasDeviation);
_runningDeviationSum += currentBiasDeviation;
if (_deviationQueue.Count > _config.BiasDeviationAvgPeriod)
{
double removed = _deviationQueue.Dequeue();
_runningDeviationSum -= removed;
}
double averageDeviation = (_deviationQueue.Count > 0)
? _runningDeviationSum / _deviationQueue.Count
: 0.0;
bool currHmaAbove = currHma > currSma;
bool prevHmaAbove = prevHma > prevSma;
if (currHmaAbove != prevHmaAbove)
{
_isTradingAllowedBasedOnPrevCycle = _deviationConditionMetInCurrentCycle;
_deviationConditionMetInCurrentCycle = false;
}
if (currentBiasDeviation > averageDeviation)
{
_deviationConditionMetInCurrentCycle = true;
}
}
private Bias GetCurrentBias(int index)
{
double hma = _hmaBias.Result[index];
double sma = _smaBias.Result[index];
double prevSma = _smaBias.Result[index - 1];
if ((hma > sma) && (sma > prevSma)) return Bias.Long;
if ((hma < sma) && (sma < prevSma)) return Bias.Short;
return Bias.Neutral;
}
private void ManagePositions(List<ClusterLevel> clusters)
{
double pNow = _symbol.Bid;
foreach (var pos in _robot.Positions)
{
if (pos.Label != Label || pos.SymbolName != _config.SymbolName) continue;
ClusterLevel? newSl = null;
ClusterLevel? newTp = null;
if (pos.TradeType == TradeType.Buy)
{
double highestSlPrice = double.MinValue;
double highestTpPrice = double.MinValue;
foreach (var c in clusters)
{
if (c.Price < pNow && c.Significance < _config.SlSigThreshold && c.Price > highestSlPrice)
{
newSl = c;
highestSlPrice = c.Price;
}
if (c.Price > pNow && c.Significance >= _config.EntrySigThreshold && c.Price > highestTpPrice)
{
newTp = c;
highestTpPrice = c.Price;
}
}
double proposedSl = (newSl.HasValue) ? newSl.Value.Price : (pos.StopLoss ?? 0);
double proposedTp = (newTp.HasValue) ? newTp.Value.Price : (pos.TakeProfit ?? 0);
bool modifySl = pos.StopLoss.HasValue && (proposedSl > pos.StopLoss.Value + _symbol.TickSize);
if (!pos.StopLoss.HasValue && newSl.HasValue) modifySl = true;
bool modifyTp = newTp.HasValue && Math.Abs(proposedTp - (pos.TakeProfit ?? 0)) > _symbol.TickSize;
if (modifySl || modifyTp)
{
double finalSl = modifySl ? proposedSl : pos.StopLoss ?? 0;
double finalTp = modifyTp ? proposedTp : pos.TakeProfit ?? 0;
if (finalSl < _symbol.Bid && (finalTp == 0 || finalTp > _symbol.Bid))
{
_robot.ModifyPosition(pos, finalSl, finalTp, ProtectionType.Absolute);
}
}
}
else // Sell
{
double lowestSlPrice = double.MaxValue;
double lowestTpPrice = double.MaxValue;
foreach (var c in clusters)
{
if (c.Price > pNow && c.Significance < _config.SlSigThreshold && c.Price < lowestSlPrice)
{
newSl = c;
lowestSlPrice = c.Price;
}
if (c.Price < pNow && c.Significance >= _config.EntrySigThreshold && c.Price < lowestTpPrice)
{
newTp = c;
lowestTpPrice = c.Price;
}
}
double proposedSl = (newSl.HasValue) ? newSl.Value.Price : (pos.StopLoss ?? 0);
double proposedTp = (newTp.HasValue) ? newTp.Value.Price : (pos.TakeProfit ?? 0);
bool modifySl = pos.StopLoss.HasValue && (proposedSl < pos.StopLoss.Value - _symbol.TickSize);
if (!pos.StopLoss.HasValue && newSl.HasValue) modifySl = true;
bool modifyTp = newTp.HasValue && Math.Abs(proposedTp - (pos.TakeProfit ?? 0)) > _symbol.TickSize;
if (modifySl || modifyTp)
{
double finalSl = modifySl ? proposedSl : pos.StopLoss ?? 0;
double finalTp = modifyTp ? proposedTp : pos.TakeProfit ?? 0;
if (finalSl > _symbol.Ask && (finalTp == 0 || finalTp < _symbol.Ask))
{
_robot.ModifyPosition(pos, finalSl, finalTp, ProtectionType.Absolute);
}
}
}
}
}
private void ManageOrders(Bias bias, int index, List<ClusterLevel> clusters)
{
// Standard Cleanup: Orders in wrong direction (Bias Change)
CleanupWrongBiasOrders(bias);
if (_config.UseBiasDeviationFilter && !_isTradingAllowedBasedOnPrevCycle)
return;
if (bias == Bias.Neutral) return;
if (!_config.SendTelegramOnly)
{
bool hasLong = _robot.Positions.Any(p => p.SymbolName == _config.SymbolName && p.Label == Label && p.TradeType == TradeType.Buy);
bool hasShort = _robot.Positions.Any(p => p.SymbolName == _config.SymbolName && p.Label == Label && p.TradeType == TradeType.Sell);
// --- FIX 1: Open Positions Cleanup ---
// If we are already invested, we ensure no pending orders for the same direction are lingering around.
if (bias == Bias.Long && hasLong)
{
CancelPendingOrders(TradeType.Buy);
return;
}
if (bias == Bias.Short && hasShort)
{
CancelPendingOrders(TradeType.Sell);
return;
}
}
if (clusters.Count < 2) return;
double pNow = _bars.ClosePrices[index];
if (bias == Bias.Short)
ProcessShortSetup(clusters, pNow);
else if (bias == Bias.Long)
ProcessLongSetup(clusters, pNow);
}
private void CancelPendingOrders(TradeType type)
{
foreach (var order in _robot.PendingOrders)
{
if (order.SymbolName == _config.SymbolName && order.Label == Label && order.TradeType == type)
{
_robot.CancelPendingOrder(order);
}
}
}
private void CleanupWrongBiasOrders(Bias currentBias)
{
if (_config.SendTelegramOnly) return;
foreach (var order in _robot.PendingOrders)
{
if (order.Label != Label || order.SymbolName != _config.SymbolName) continue;
if (currentBias == Bias.Long && order.TradeType == TradeType.Sell)
_robot.CancelPendingOrder(order);
else if (currentBias == Bias.Short && order.TradeType == TradeType.Buy)
_robot.CancelPendingOrder(order);
else if (currentBias == Bias.Neutral)
_robot.CancelPendingOrder(order);
}
}
private void ProcessShortSetup(List<ClusterLevel> clusters, double pNow)
{
ClusterLevel? entry = null;
ClusterLevel? sl = null;
ClusterLevel? tp = null;
double highestEntryPrice = double.MinValue;
double lowestSlPrice = double.MaxValue;
double lowestTpPrice = double.MaxValue;
foreach (var c in clusters)
{
if (c.Price > pNow)
{
if ((c.Significance >= _config.EntrySigThreshold) && (c.Price > highestEntryPrice))
{
entry = c;
highestEntryPrice = c.Price;
}
if ((c.Significance < _config.SlSigThreshold) && (c.Price < lowestSlPrice))
{
sl = c;
lowestSlPrice = c.Price;
}
}
}
if (entry == null || sl == null) return;
foreach (var c in clusters)
{
if ((c.Price < entry.Value.Price) && (c.Significance >= _config.EntrySigThreshold))
{
if (c.Price < lowestTpPrice)
{
tp = c;
lowestTpPrice = c.Price;
}
}
}
if (tp != null && (sl.Value.Price > entry.Value.Price))
{
double risk = sl.Value.Price - entry.Value.Price;
double reward = entry.Value.Price - tp.Value.Price;
if (risk <= reward)
UpdateOrPlaceLimitOrder(TradeType.Sell, entry.Value.Price, sl.Value.Price, tp.Value.Price);
}
}
private void ProcessLongSetup(List<ClusterLevel> clusters, double pNow)
{
ClusterLevel? entry = null;
ClusterLevel? sl = null;
ClusterLevel? tp = null;
double lowestEntryPrice = double.MaxValue;
double highestSlPrice = double.MinValue;
double highestTpPrice = double.MinValue;
foreach (var c in clusters)
{
if (c.Price < pNow)
{
if ((c.Significance >= _config.EntrySigThreshold) && (c.Price < lowestEntryPrice))
{
entry = c;
lowestEntryPrice = c.Price;
}
if ((c.Significance < _config.SlSigThreshold) && (c.Price > highestSlPrice))
{
sl = c;
highestSlPrice = c.Price;
}
}
}
if (entry == null || sl == null) return;
foreach (var c in clusters)
{
if ((c.Price > entry.Value.Price) && (c.Significance >= _config.EntrySigThreshold))
{
if (c.Price > highestTpPrice)
{
tp = c;
highestTpPrice = c.Price;
}
}
}
if (tp != null && (sl.Value.Price < entry.Value.Price))
{
double risk = entry.Value.Price - sl.Value.Price;
double reward = tp.Value.Price - entry.Value.Price;
if (risk <= reward)
UpdateOrPlaceLimitOrder(TradeType.Buy, entry.Value.Price, sl.Value.Price, tp.Value.Price);
}
}
private void UpdateOrPlaceLimitOrder(TradeType type, double entry, double sl, double tp)
{
var existingOrder = _robot.PendingOrders.FirstOrDefault(o => o.SymbolName == _config.SymbolName && o.Label == Label && o.TradeType == type);
// --- FIX 4: Market Proximity Check ---
// If the limit price is invalid (e.g. Buy Limit above Ask), we must abort/cancel.
bool priceInvalid = false;
double buffer = _symbol.PipSize;
if (type == TradeType.Buy && entry >= (_symbol.Ask - buffer)) priceInvalid = true;
if (type == TradeType.Sell && entry <= (_symbol.Bid + buffer)) priceInvalid = true;
if (priceInvalid)
{
if (existingOrder != null) _robot.CancelPendingOrder(existingOrder);
return;
}
// --- FIX 3: SL Distance Check ---
double slDistPips = Math.Abs(entry - sl) / _symbol.PipSize;
if (slDistPips <= 0)
{
if (existingOrder != null) _robot.CancelPendingOrder(existingOrder);
return;
}
// --- FIX 2: Volume Check ---
double riskAmount = _robot.Account.Balance * (_config.RiskPercent / 100.0);
double volume = _symbol.VolumeForFixedRisk(riskAmount, slDistPips);
volume = _symbol.NormalizeVolumeInUnits(volume, RoundingMode.Down);
if (volume < _symbol.VolumeInUnitsMin)
{
if (existingOrder != null) _robot.CancelPendingOrder(existingOrder);
return;
}
double lots = _symbol.VolumeInUnitsToQuantity(volume);
if (_config.SendTelegramOnly)
{
string directionStr = type == TradeType.Buy ? "BUY" : "SELL";
string directionIcon = type == TradeType.Buy ? "📈" : "📉";
string msg = $"{directionIcon} <b>{directionStr}</b> Signal @ <b>{_config.SymbolName}</b>\n\n" +
$"<b>Entry:</b> {entry}\n" +
$"<b>SL:</b> {sl}\n" +
$"<b>TP:</b> {tp}\n" +
$"<b>Vol:</b> {lots:F2} Lots";
_ = SendTelegramMessageAsync(msg);
return;
}
if (existingOrder != null)
{
bool volumeChanged = Math.Abs(existingOrder.VolumeInUnits - volume) > _symbol.VolumeInUnitsStep;
bool entryChanged = Math.Abs(existingOrder.TargetPrice - entry) > _symbol.TickSize;
bool slChanged = Math.Abs((existingOrder.StopLoss ?? 0) - sl) > _symbol.TickSize;
bool tpChanged = Math.Abs((existingOrder.TakeProfit ?? 0) - tp) > _symbol.TickSize;
if (volumeChanged || entryChanged || slChanged || tpChanged)
{
var result = _robot.ModifyPendingOrder(existingOrder, entry, sl, tp, ProtectionType.Absolute, null, volume);
if (!result.IsSuccessful)
{
// Fallback: If modify fails (e.g. spread jump), cancel it to avoid stale orders
_robot.CancelPendingOrder(existingOrder);
}
}
}
else
{
_robot.Print("[SIGNAL] {0} {1} | Entry: {2} | SL: {3} | TP: {4} | Vol: {5:F2} Lots",
(type == TradeType.Buy ? "BUY" : "SELL"), _config.SymbolName, entry, sl, tp, lots);
_robot.PlaceLimitOrder(type, _config.SymbolName, volume, entry, Label, sl, tp, ProtectionType.Absolute);
}
}
private async Task SendTelegramMessageAsync(string message)
{
if (_robot.IsBacktesting) return;
if (string.IsNullOrWhiteSpace(_botToken) || string.IsNullOrWhiteSpace(_chatId)) return;
try
{
string url = $"https://api.telegram.org/bot{_botToken}/sendMessage?chat_id={_chatId}&text={Uri.EscapeDataString(message)}&parse_mode=HTML";
HttpResponseMessage response = await _httpClient.GetAsync(url);
if (!response.IsSuccessStatusCode)
{
_errorCallback?.Invoke($"Telegram Error: {response.StatusCode}");
}
}
catch (Exception ex)
{
_errorCallback?.Invoke($"Telegram Exception: {ex.Message}");
}
}
private void UpdateClusterData(int index)
{
double currentHma = _hmaCluster.Result[index];
double prevHma = _hmaCluster.Result[index - 1];
bool currentDirectionUp = (currentHma > prevHma);
if (_isUpTrend == null)
{
_isUpTrend = currentDirectionUp;
SetExtremum(index);
_lastExtremumPrice = _trendExtremum;
return;
}
if (currentDirectionUp != _isUpTrend)
{
double amp = Math.Abs(_trendExtremum - _lastExtremumPrice);
if (amp > 0)
{
_amplitudes.Add(amp);
if (_amplitudes.Count > 50) _amplitudes.RemoveAt(0);
double sum = 0;
for (int i = 0; i < _amplitudes.Count; i++) sum += _amplitudes[i];
_currentDynamicRange = (sum / _amplitudes.Count) * 0.5;
}
_extremaPoints.Add(new ExtremumPoint { Price = _trendExtremum, Index = _trendExtremumIndex, Type = _isUpTrend.Value ? PointType.Peak : PointType.Trough });
if (_extremaPoints.Count > _config.MaxPoints) _extremaPoints.RemoveAt(0);
_lastExtremumPrice = _trendExtremum;
_isUpTrend = currentDirectionUp;
SetExtremum(index);
}
else
{
UpdateExtremum(index);
}
}
private void SetExtremum(int index)
{
_trendExtremum = _isUpTrend.Value ? _bars.HighPrices[index] : _bars.LowPrices[index];
_trendExtremumIndex = index;
}
private void UpdateExtremum(int index)
{
if (_isUpTrend.Value && (_bars.HighPrices[index] > _trendExtremum))
{
_trendExtremum = _bars.HighPrices[index];
_trendExtremumIndex = index;
}
else if (!_isUpTrend.Value && (_bars.LowPrices[index] < _trendExtremum))
{
_trendExtremum = _bars.LowPrices[index];
_trendExtremumIndex = index;
}
}
private List<ClusterLevel> CalculateClusters(int currentIndex)
{
int count = _extremaPoints.Count;
if (count == 0) return new List<ClusterLevel>();
double currentPrice = _bars.ClosePrices[currentIndex];
double[] weights = new double[count];
double totalWeightSum = 0;
for (int i = 0; i < count; i++)
{
weights[i] = GetWeight(_extremaPoints[i], currentIndex, currentPrice);
totalWeightSum += weights[i];
}
if (totalWeightSum == 0) return new List<ClusterLevel>();
var zones = new List<ClusterLevel>();
for (int i = count - 1; i >= 0; i--)
{
var p = _extremaPoints[i];
bool exists = false;
for (int j = 0; j < zones.Count; j++)
{
if (Math.Abs(zones[j].Price - p.Price) < _currentDynamicRange)
{
exists = true;
break;
}
}
if (exists) continue;
double score = 0;
for (int k = 0; k < count; k++)
{
if (Math.Abs(_extremaPoints[k].Price - p.Price) <= _currentDynamicRange)
{
score += weights[k];
}
}
zones.Add(new ClusterLevel { Price = p.Price, Significance = (score / totalWeightSum) * 100.0 });
}
return zones;
}
private double GetWeight(ExtremumPoint point, int currentIndex, double currentPrice)
{
double weight = Math.Max(0.0, 1.0 - ((double)(currentIndex - point.Index) / _config.DecayPeriod));
if ((point.Type == PointType.Peak) && (point.Price < currentPrice)) weight *= 2.0;
else if ((point.Type == PointType.Trough) && (point.Price > currentPrice)) weight *= 2.0;
return weight;
}
}
}
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<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("HmaClusterBot")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("HmaClusterBot")]
[assembly: System.Reflection.AssemblyTitleAttribute("HmaClusterBot")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Generated by the MSBuild WriteCodeFragment class.
@@ -0,0 +1 @@
296f6e29070e0927c857564d4a04976a31621cde
@@ -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 = HmaClusterBot
build_property.ProjectDir = C:\Users\Brummel\Documents\cAlgo\Sources\Robots\HmaClusterBot\HmaClusterBot\
@@ -0,0 +1,66 @@
{
"format": 1,
"restore": {
"C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\HmaClusterBot\\HmaClusterBot\\HmaClusterBot.csproj": {}
},
"projects": {
"C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\HmaClusterBot\\HmaClusterBot\\HmaClusterBot.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\HmaClusterBot\\HmaClusterBot\\HmaClusterBot.csproj",
"projectName": "HmaClusterBot",
"projectPath": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\HmaClusterBot\\HmaClusterBot\\HmaClusterBot.csproj",
"packagesPath": "C:\\Users\\Brummel\\.nuget\\packages\\",
"outputPath": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\HmaClusterBot\\HmaClusterBot\\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\\Robots\\HmaClusterBot\\HmaClusterBot\\HmaClusterBot.csproj",
"projectName": "HmaClusterBot",
"projectPath": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\HmaClusterBot\\HmaClusterBot\\HmaClusterBot.csproj",
"packagesPath": "C:\\Users\\Brummel\\.nuget\\packages\\",
"outputPath": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\HmaClusterBot\\HmaClusterBot\\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": "NEYKNJ+0pRHXWSIUJ8meJtMDF84xyxPwtc1chms3WBz34cQ0viYha1RgvvteKYETOCh8y4l1tk9Xm9OxaOeitA==",
"success": true,
"projectFilePath": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\HmaClusterBot\\HmaClusterBot\\HmaClusterBot.csproj",
"expectedPackageFiles": [
"C:\\Users\\Brummel\\.nuget\\packages\\ctrader.automate\\1.0.14\\ctrader.automate.1.0.14.nupkg.sha512"
],
"logs": []
}
Binary file not shown.
Binary file not shown.
+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"}]}
+22
View File
@@ -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}") = "HmaKcBot", "HmaKcBot\HmaKcBot.csproj", "{335ef48b-c961-4e40-97d0-9890a4d69d46}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{335ef48b-c961-4e40-97d0-9890a4d69d46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{335ef48b-c961-4e40-97d0-9890a4d69d46}.Debug|Any CPU.Build.0 = Debug|Any CPU
{335ef48b-c961-4e40-97d0-9890a4d69d46}.Release|Any CPU.ActiveCfg = Release|Any CPU
{335ef48b-c961-4e40-97d0-9890a4d69d46}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
@@ -0,0 +1,114 @@
using cAlgo.API;
using cAlgo.API.Indicators;
using System;
namespace cAlgo.Robots
{
[Robot(AccessRights = AccessRights.None)]
public class HmaKcBot : Robot
{
[Parameter("HMA Period", DefaultValue = 250)]
public int HmaPeriod { get; set; }
[Parameter("KC MA Period", DefaultValue = 20)]
public int KcMaPeriod { get; set; }
[Parameter("KC ATR Period", DefaultValue = 20)]
public int KcAtrPeriod { get; set; }
[Parameter("KC Multiplier", DefaultValue = 2.0)]
public double KcMultiplier { get; set; }
[Parameter("Risk Percentage", DefaultValue = 1.0, MinValue = 0.1, MaxValue = 10.0)]
public double RiskPercentage { get; set; }
[Parameter("Stop Loss (pips)", DefaultValue = 20, MinValue = 1)]
public double StopLossPips { get; set; }
private HullMovingAverage _hma;
private KeltnerChannels _kc;
private const string Label = "HmaKcBot";
protected override void OnStart()
{
_hma = Indicators.HullMovingAverage(Bars.ClosePrices, HmaPeriod);
_kc = Indicators.KeltnerChannels(KcMaPeriod, MovingAverageType.Simple, KcAtrPeriod, MovingAverageType.Hull, KcMultiplier);
}
protected override void OnBar()
{
var hmaCurrent = _hma.Result.Last(1);
var hmaPrevious = _hma.Result.Last(2);
var hmaOld = _hma.Result.Last(3);
// Sell Condition
if (hmaPrevious > hmaCurrent && hmaPrevious > hmaOld)
{
ClosePositions(TradeType.Buy);
var position = Positions.Find(Label, SymbolName, TradeType.Sell);
if (position == null)
{
var volumeInUnits = Symbol.VolumeForProportionalRisk(ProportionalAmountType.Equity, RiskPercentage, StopLossPips);
var normalizedVolume = Symbol.NormalizeVolumeInUnits(volumeInUnits, RoundingMode.ToNearest);
if (normalizedVolume > 0)
{
ExecuteMarketOrder(TradeType.Sell, SymbolName, normalizedVolume, Label, StopLossPips, null);
}
}
}
// Buy Condition
if (hmaPrevious < hmaCurrent && hmaPrevious < hmaOld)
{
ClosePositions(TradeType.Sell);
var position = Positions.Find(Label, SymbolName, TradeType.Buy);
if (position == null)
{
var volumeInUnits = Symbol.VolumeForProportionalRisk(ProportionalAmountType.Equity, RiskPercentage, StopLossPips);
var normalizedVolume = Symbol.NormalizeVolumeInUnits(volumeInUnits, RoundingMode.ToNearest);
if (normalizedVolume > 0)
{
ExecuteMarketOrder(TradeType.Buy, SymbolName, normalizedVolume, Label, StopLossPips, null);
}
}
}
TrailStopLoss();
}
private void TrailStopLoss()
{
foreach (var position in Positions.FindAll(Label, SymbolName))
{
if (position.TradeType == TradeType.Buy)
{
var newStopLoss = Math.Round(_kc.Bottom.Last(1), Symbol.Digits);
if (position.StopLoss == null || newStopLoss > position.StopLoss)
{
// Updated ModifyPosition to include ProtectionType.Absolute.
ModifyPosition(position, newStopLoss, position.TakeProfit, ProtectionType.Absolute);
}
}
else if (position.TradeType == TradeType.Sell)
{
var newStopLoss = Math.Round(_kc.Top.Last(1), Symbol.Digits);
if (position.StopLoss == null || newStopLoss < position.StopLoss)
{
// Updated ModifyPosition to include ProtectionType.Absolute.
ModifyPosition(position, newStopLoss, position.TakeProfit, ProtectionType.Absolute);
}
}
}
}
private void ClosePositions(TradeType tradeType)
{
foreach (var position in Positions.FindAll(Label, SymbolName, tradeType))
{
ClosePosition(position);
}
}
}
}
@@ -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("HmaKcBot")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("HmaKcBot")]
[assembly: System.Reflection.AssemblyTitleAttribute("HmaKcBot")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Generated by the MSBuild WriteCodeFragment class.
@@ -0,0 +1 @@
c085c96e76c2bfbc661649df310079c6fc9608f0
@@ -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 = HmaKcBot
build_property.ProjectDir = C:\Users\Brummel\Documents\cAlgo\Sources\Robots\HmaKcBot\HmaKcBot\
@@ -0,0 +1,66 @@
{
"format": 1,
"restore": {
"C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\HmaKcBot\\HmaKcBot\\HmaKcBot.csproj": {}
},
"projects": {
"C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\HmaKcBot\\HmaKcBot\\HmaKcBot.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\HmaKcBot\\HmaKcBot\\HmaKcBot.csproj",
"projectName": "HmaKcBot",
"projectPath": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\HmaKcBot\\HmaKcBot\\HmaKcBot.csproj",
"packagesPath": "C:\\Users\\Brummel\\.nuget\\packages\\",
"outputPath": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\HmaKcBot\\HmaKcBot\\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\\HmaKcBot\\HmaKcBot\\HmaKcBot.csproj",
"projectName": "HmaKcBot",
"projectPath": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\HmaKcBot\\HmaKcBot\\HmaKcBot.csproj",
"packagesPath": "C:\\Users\\Brummel\\.nuget\\packages\\",
"outputPath": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\HmaKcBot\\HmaKcBot\\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": "XgjSBy1e5g3yI21pAC15ZU+Ik0YPC1U9+c5CtniqfcpL0zXKjYStMBHb3A6jnU4FFMSg8LtqczM9QrWa3Q/x0w==",
"success": true,
"projectFilePath": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\HmaKcBot\\HmaKcBot\\HmaKcBot.csproj",
"expectedPackageFiles": [
"C:\\Users\\Brummel\\.nuget\\packages\\ctrader.automate\\1.0.12\\ctrader.automate.1.0.12.nupkg.sha512"
],
"logs": []
}
Binary file not shown.
+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}") = "HmaSmaCrossoverBot", "HmaSmaCrossoverBot\HmaSmaCrossoverBot.csproj", "{b3f19675-15c1-4ecd-87db-b4e345e3d6f5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{b3f19675-15c1-4ecd-87db-b4e345e3d6f5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{b3f19675-15c1-4ecd-87db-b4e345e3d6f5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{b3f19675-15c1-4ecd-87db-b4e345e3d6f5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{b3f19675-15c1-4ecd-87db-b4e345e3d6f5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
@@ -0,0 +1,198 @@
using cAlgo.API;
using cAlgo.API.Indicators;
using System;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class HmaSmaCrossoverBot : Robot
{
[Parameter("HMA A Period (Fast)", DefaultValue = 20, Group = "Periods")]
public int HmaAPeriod { get; set; }
[Parameter("HMA B Period (Slow)", DefaultValue = 250, Group = "Periods")]
public int HmaBPeriod { get; set; }
[Parameter("SMA C Period (Base)", DefaultValue = 200, Group = "Periods")]
public int SmaCPeriod { get; set; }
[Parameter("Lot Size", DefaultValue = 0.1, Group = "Volume")]
public double LotSize { get; set; }
[Parameter("Max Positions", DefaultValue = 4, Group = "Volume")]
public int MaxPositions { get; set; }
[Parameter("Stop Loss (Pips)", DefaultValue = 50, Group = "Protection")]
public double StopLossPips { get; set; }
// Label for position management
private const string BotLabel = "HmaSmaCrossoverBot";
private HullMovingAverage _hmaA;
private HullMovingAverage _hmaB;
private SimpleMovingAverage _smaC;
private double _volumeInUnits;
private TimeZoneInfo _germanZone; // Added for time filter
protected override void OnStart()
{
_hmaA = Indicators.HullMovingAverage(Bars.ClosePrices, HmaAPeriod);
_hmaB = Indicators.HullMovingAverage(Bars.ClosePrices, HmaBPeriod);
_smaC = Indicators.SimpleMovingAverage(Bars.ClosePrices, SmaCPeriod);
// Convert LotSize to normalized VolumeInUnits
double preciseVolume = Symbol.QuantityToVolumeInUnits(LotSize);
_volumeInUnits = Symbol.NormalizeVolumeInUnits(preciseVolume, RoundingMode.ToNearest);
if (_volumeInUnits < Symbol.VolumeInUnitsMin)
{
_volumeInUnits = Symbol.VolumeInUnitsMin;
Print($"Warning: Requested volume {preciseVolume} is below minimum. Using minimum: {_volumeInUnits} units.");
}
// Initialize German TimeZone
try
{
// "W. Europe Standard Time" is the ID for Berlin, Amsterdam, Rome (CET/CEST)
_germanZone = TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time");
}
catch (TimeZoneNotFoundException)
{
Print("Error: TimeZone 'W. Europe Standard Time' not found. Using Server TimeZone as fallback for time filter (might be incorrect).");
_germanZone = TimeZone; // Fallback to server zone (which is UTC here)
}
catch (Exception ex)
{
Print($"Error initializing TimeZone: {ex.Message}. Using Server TimeZone as fallback.");
_germanZone = TimeZone;
}
}
protected override void OnBar()
{
// Ensure indicators have enough data + 3 bars for peak/trough logic
int requiredBars = Math.Max(HmaAPeriod, Math.Max(HmaBPeriod, SmaCPeriod)) + 3;
if (Bars.Count < requiredBars)
{
return;
}
// Check exit conditions first
HandleExits();
// Check entry conditions
HandleEntries();
}
// Checks and executes exit logic based on rules
private void HandleExits()
{
// Get current and previous values (based on closed bars)
// Last(0) = current closed bar, Last(1) = previous bar
double hmaB_curr = _hmaB.Result.Last(0);
double smaC_curr = _smaC.Result.Last(0);
double hmaB_prev = _hmaB.Result.Last(1);
double low_curr = Bars.LowPrices.Last(0);
double low_prev = Bars.LowPrices.Last(1);
double high_curr = Bars.HighPrices.Last(0);
double high_prev = Bars.HighPrices.Last(1);
// --- Long Exit Conditions ---
// 1. B < C (at current close)
// 2. Low crosses below B (Currentbar.Low < Current.B AND PreviousBar.Low >= Previous.B)
bool longExitSignal = (hmaB_curr < smaC_curr) ||
((low_curr < hmaB_curr) && (low_prev >= hmaB_prev));
// --- Short Exit Conditions ---
// 1. B > C (at current close)
// 2. High crosses above B (Currentbar.High > Current.B AND PreviousBar.High <= Previous.B)
bool shortExitSignal = (hmaB_curr > smaC_curr) ||
((high_curr > hmaB_curr) && (high_prev <= hmaB_prev));
// Find all positions managed by this bot for the current symbol
var botPositions = GetPositions(null);
foreach (var position in botPositions)
{
if (position.TradeType == TradeType.Buy && longExitSignal)
{
ClosePosition(position);
}
else if (position.TradeType == TradeType.Sell && shortExitSignal)
{
ClosePosition(position);
}
}
}
// Checks and executes entry logic based on indicator signals
private void HandleEntries()
{
// --- Time Filter ---
// Use TimeInUtc for a reliable UTC baseline (as Robot TimeZone is UTC)
DateTime germanTime = TimeZoneInfo.ConvertTimeFromUtc(TimeInUtc, _germanZone);
// Only allow new trades between 7:00 (inclusive) and 17:00 (exclusive) German time
if (germanTime.Hour < 7 || germanTime.Hour >= 17)
{
return; // Outside trading hours
}
// --- End Time Filter ---
// Get values for signal bar (i-1) and confirmation bar (i)
// Last(0) = i (confirmation bar, just closed)
// Last(1) = i-1 (signal bar)
// Last(2) = i-2 (previous bar)
double hmaA_confirm = _hmaA.Result.Last(0);
double hmaA_signal = _hmaA.Result.Last(1);
double hmaA_prev = _hmaA.Result.Last(2);
// Get filter values at the signal bar (i-1)
double hmaB_signal = _hmaB.Result.Last(1);
double smaC_signal = _smaC.Result.Last(1);
// Peak/Trough detection at i-1 (Last(1)), confirmed by i (Last(0))
bool isPeak = (hmaA_prev < hmaA_signal) && (hmaA_signal > hmaA_confirm);
bool isTrough = (hmaA_prev > hmaA_signal) && (hmaA_signal < hmaA_confirm);
// --- Sell Signal Condition (at i-1) ---
// 1. B < C
// 2. A > C
// 3. A forms a peak
if ((hmaB_signal < smaC_signal) && (hmaA_signal > smaC_signal) && isPeak)
{
if (GetPositions(TradeType.Sell).Length < MaxPositions)
{
ExecuteMarketOrder(TradeType.Sell, SymbolName, _volumeInUnits, BotLabel, StopLossPips, null);
}
}
// --- Buy Signal Condition (at i-1) ---
// 1. B > C
// 2. A < C
// 3. A forms a trough
if ((hmaB_signal > smaC_signal) && (hmaA_signal < smaC_signal) && isTrough)
{
if (GetPositions(TradeType.Buy).Length < MaxPositions)
{
ExecuteMarketOrder(TradeType.Buy, SymbolName, _volumeInUnits, BotLabel, StopLossPips, null);
}
}
}
// Helper to get positions only for the current symbol and managed by this bot
private Position[] GetPositions(TradeType? tradeType)
{
if (tradeType == null)
{
// Get all Buy or Sell positions for this bot/symbol
return Positions.FindAll(BotLabel, SymbolName);
}
// Get specific TradeType positions for this bot/symbol
return Positions.FindAll(BotLabel, SymbolName, tradeType.Value);
}
}
}
@@ -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("HmaSmaCrossoverBot")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("HmaSmaCrossoverBot")]
[assembly: System.Reflection.AssemblyTitleAttribute("HmaSmaCrossoverBot")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Generated by the MSBuild WriteCodeFragment class.
@@ -0,0 +1 @@
4f125f90c408d20a05e42f8a6dc598f9c14b8e6f
@@ -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 = HmaSmaCrossoverBot
build_property.ProjectDir = C:\Users\Brummel\Documents\cAlgo\Sources\Robots\HmaSmaCrossoverBot\HmaSmaCrossoverBot\
@@ -0,0 +1,66 @@
{
"format": 1,
"restore": {
"C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\HmaSmaCrossoverBot\\HmaSmaCrossoverBot\\HmaSmaCrossoverBot.csproj": {}
},
"projects": {
"C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\HmaSmaCrossoverBot\\HmaSmaCrossoverBot\\HmaSmaCrossoverBot.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\HmaSmaCrossoverBot\\HmaSmaCrossoverBot\\HmaSmaCrossoverBot.csproj",
"projectName": "HmaSmaCrossoverBot",
"projectPath": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\HmaSmaCrossoverBot\\HmaSmaCrossoverBot\\HmaSmaCrossoverBot.csproj",
"packagesPath": "C:\\Users\\Brummel\\.nuget\\packages\\",
"outputPath": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\HmaSmaCrossoverBot\\HmaSmaCrossoverBot\\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\\Robots\\HmaSmaCrossoverBot\\HmaSmaCrossoverBot\\HmaSmaCrossoverBot.csproj",
"projectName": "HmaSmaCrossoverBot",
"projectPath": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\HmaSmaCrossoverBot\\HmaSmaCrossoverBot\\HmaSmaCrossoverBot.csproj",
"packagesPath": "C:\\Users\\Brummel\\.nuget\\packages\\",
"outputPath": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\HmaSmaCrossoverBot\\HmaSmaCrossoverBot\\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": "o2zbiJnQ5+mDJlvuxYW8+Qmxo/HzYxOwFc7BUoYdtbMdhQvLGFQJ9gkt6PTVAeX05JrpmDeuNnfj0iTviIs+iQ==",
"success": true,
"projectFilePath": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\HmaSmaCrossoverBot\\HmaSmaCrossoverBot\\HmaSmaCrossoverBot.csproj",
"expectedPackageFiles": [
"C:\\Users\\Brummel\\.nuget\\packages\\ctrader.automate\\1.0.14\\ctrader.automate.1.0.14.nupkg.sha512"
],
"logs": []
}
Binary file not shown.
+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}") = "HmaStructureBot", "HmaStructureBot\HmaStructureBot.csproj", "{9f6f411d-ba95-4e92-853b-10e6a1a8c98c}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9f6f411d-ba95-4e92-853b-10e6a1a8c98c}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9f6f411d-ba95-4e92-853b-10e6a1a8c98c}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9f6f411d-ba95-4e92-853b-10e6a1a8c98c}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9f6f411d-ba95-4e92-853b-10e6a1a8c98c}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
@@ -0,0 +1,227 @@
using System;
using System.Collections.Generic;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class HmaStructureBot : Robot
{
// --- Parameters ---
[Parameter("HMA Period", DefaultValue = 25)]
public int HmaPeriod { get; set; }
[Parameter("Risk % per Trade", DefaultValue = 1.0, MinValue = 0.01)]
public double RiskPercent { get; set; }
[Parameter("Order Label", DefaultValue = "HMA_Struct")]
public string OrderLabel { get; set; }
// Expiration removed
// --- Indicators ---
private HullMovingAverage _hma;
// --- State Management ---
private DateTime _lastSetupTime;
// --- Data Structures ---
private enum ExtremumType { High, Low }
private struct Extremum
{
public ExtremumType Type;
public double Value;
public int Index; // Index relative to logic
public DateTime Time; // Unique identifier for the extremum
}
protected override void OnStart()
{
_hma = Indicators.HullMovingAverage(Bars.ClosePrices, HmaPeriod);
}
protected override void OnBarClosed()
{
// 1. Manage existing pending orders
ManageExistingOrders();
// 2. Find Extrema
var extrema = GetExtrema(200, 5);
if (extrema.Count < 5)
return;
// 3. Check for duplicate execution on the same setup
// The setup is defined by the latest extremum (extrema[0])
if (extrema[0].Time == _lastSetupTime)
return;
bool orderPlaced = false;
// --- Short Logic ---
// Last extremum must be a Trough (T0)
if (extrema[0].Type == ExtremumType.Low)
{
var t0 = extrema[0].Value;
var h0 = extrema[1].Value;
var t1 = extrema[2].Value;
var h1 = extrema[3].Value;
var t2 = extrema[4].Value;
// Condition: T1 < T2 and H0 < T2
if (t1 < t2 && h0 < t2)
{
double entryPrice = 0.5 * (t2 + h0);
double stopLossPrice = h1;
double takeProfitPrice = Math.Max(t0, t1);
PlaceStructureOrder(TradeType.Sell, entryPrice, stopLossPrice, takeProfitPrice);
orderPlaced = true;
}
}
// --- Long Logic ---
// Last extremum must be a Peak (H0)
else if (extrema[0].Type == ExtremumType.High)
{
var h0 = extrema[0].Value;
var t0 = extrema[1].Value;
var h1 = extrema[2].Value;
var t1 = extrema[3].Value;
var h2 = extrema[4].Value;
// Condition: H1 > H2 and T0 > H2
if (h1 > h2 && t0 > h2)
{
double entryPrice = 0.5 * (h2 + t0);
double stopLossPrice = t1;
double takeProfitPrice = Math.Min(h0, h1);
PlaceStructureOrder(TradeType.Buy, entryPrice, stopLossPrice, takeProfitPrice);
orderPlaced = true;
}
}
// 4. Mark Setup as handled if we placed an order
if (orderPlaced)
{
_lastSetupTime = extrema[0].Time;
}
}
private void PlaceStructureOrder(TradeType type, double entryPrice, double slPrice, double tpPrice)
{
// Calculate Risk
double riskAmount = Account.Balance * (RiskPercent / 100.0);
// Note: VolumeForFixedRisk still requires SL in Pips calculation
double slDistancePips = Math.Abs(entryPrice - slPrice) / Symbol.PipSize;
if (slDistancePips <= 0) return;
double volume = Symbol.VolumeForFixedRisk(riskAmount, slDistancePips);
volume = Symbol.NormalizeVolumeInUnits(volume, RoundingMode.Down);
// Place Limit Order using Absolute Prices
// Expiry is null (GTC - Good Till Cancelled)
PlaceLimitOrder(type, SymbolName, volume, entryPrice, OrderLabel, slPrice, tpPrice, ProtectionType.Absolute, null);
}
private void ManageExistingOrders()
{
foreach (var order in PendingOrders.ToArray())
{
if (order.Label != OrderLabel || order.SymbolName != SymbolName)
continue;
var barLow = Bars.LowPrices.Last(0);
var barHigh = Bars.HighPrices.Last(0);
bool isCancelled = false;
// --- Check SL Hit ---
if (order.StopLoss.HasValue)
{
if (order.TradeType == TradeType.Buy)
{
if (barLow <= order.StopLoss.Value)
{
order.Cancel();
isCancelled = true;
}
}
else // Sell
{
if (barHigh >= order.StopLoss.Value)
{
order.Cancel();
isCancelled = true;
}
}
}
if (isCancelled) continue;
// --- Check TP Extension ---
if (order.TakeProfit.HasValue)
{
if (order.TradeType == TradeType.Sell)
{
// If price went lower than TP, move TP to Low
if (barLow < order.TakeProfit.Value)
{
ModifyPendingOrder(order, order.TargetPrice, order.StopLoss, barLow, order.ProtectionType);
}
}
else // Buy
{
// If price went higher than TP, move TP to High
if (barHigh > order.TakeProfit.Value)
{
ModifyPendingOrder(order, order.TargetPrice, order.StopLoss, barHigh, order.ProtectionType);
}
}
}
}
}
private List<Extremum> GetExtrema(int searchDepth, int minCount)
{
var list = new List<Extremum>();
var hma = _hma.Result;
// i starts at 1 to compare with confirmed i+1 and i-1 (where i-1 is closer to closed bar Last(0))
for (int i = 1; i < searchDepth && i < hma.Count - 1; i++)
{
double current = hma.Last(i);
double prev = hma.Last(i + 1); // Older
double next = hma.Last(i - 1); // Newer
if (current > prev && current > next)
{
list.Add(new Extremum {
Type = ExtremumType.High,
Value = current,
Index = i,
Time = Bars.OpenTimes.Last(i)
});
}
else if (current < prev && current < next)
{
list.Add(new Extremum {
Type = ExtremumType.Low,
Value = current,
Index = i,
Time = Bars.OpenTimes.Last(i)
});
}
if (list.Count >= minCount)
break;
}
return list;
}
}
}
@@ -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("HmaStructureBot")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("HmaStructureBot")]
[assembly: System.Reflection.AssemblyTitleAttribute("HmaStructureBot")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Generated by the MSBuild WriteCodeFragment class.
@@ -0,0 +1 @@
7c0c361c93e8c6d8fca2b9bb1c31f57269d6fb5c
@@ -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 = HmaStructureBot
build_property.ProjectDir = C:\Users\Brummel\Documents\cAlgo\Sources\Robots\HmaStructureBot\HmaStructureBot\
@@ -0,0 +1,66 @@
{
"format": 1,
"restore": {
"C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\HmaStructureBot\\HmaStructureBot\\HmaStructureBot.csproj": {}
},
"projects": {
"C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\HmaStructureBot\\HmaStructureBot\\HmaStructureBot.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\HmaStructureBot\\HmaStructureBot\\HmaStructureBot.csproj",
"projectName": "HmaStructureBot",
"projectPath": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\HmaStructureBot\\HmaStructureBot\\HmaStructureBot.csproj",
"packagesPath": "C:\\Users\\Brummel\\.nuget\\packages\\",
"outputPath": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\HmaStructureBot\\HmaStructureBot\\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\\Robots\\HmaStructureBot\\HmaStructureBot\\HmaStructureBot.csproj",
"projectName": "HmaStructureBot",
"projectPath": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\HmaStructureBot\\HmaStructureBot\\HmaStructureBot.csproj",
"packagesPath": "C:\\Users\\Brummel\\.nuget\\packages\\",
"outputPath": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\HmaStructureBot\\HmaStructureBot\\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": "+LfUhmmRyp/da3uLv4sl9ySOIaNqbWkyyWrG6dFoxe2QtHmfBoTXxKOgzeDDVjvn++es3OTLB7yxGQK8b5/qMg==",
"success": true,
"projectFilePath": "C:\\Users\\Brummel\\Documents\\cAlgo\\Sources\\Robots\\HmaStructureBot\\HmaStructureBot\\HmaStructureBot.csproj",
"expectedPackageFiles": [
"C:\\Users\\Brummel\\.nuget\\packages\\ctrader.automate\\1.0.14\\ctrader.automate.1.0.14.nupkg.sha512"
],
"logs": []
}
Binary file not shown.
+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}") = "HmaTrendTrader", "HmaTrendTrader\HmaTrendTrader.csproj", "{3730b511-c6f3-4c3c-9b25-cec622450d0e}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3730b511-c6f3-4c3c-9b25-cec622450d0e}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3730b511-c6f3-4c3c-9b25-cec622450d0e}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3730b511-c6f3-4c3c-9b25-cec622450d0e}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3730b511-c6f3-4c3c-9b25-cec622450d0e}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

Some files were not shown because too many files have changed in this diff Show More