Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Indicators/.samples.json
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,9 @@
{
"name": "ToggleButtonEventArgs Sample"
},
{
"name": "Trading Panel Sample"
},
{
"name": "TradingFromIndicators Sample"
},
Expand Down
22 changes: 22 additions & 0 deletions Indicators/Trading Panel Sample/Trading Panel Sample.sln
Original file line number Diff line number Diff line change
@@ -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}") = "Trading Panel Sample", "Trading Panel Sample\Trading Panel Sample.csproj", "{b7a7a3f2-374a-41e2-97d3-a27390202a75}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{b7a7a3f2-374a-41e2-97d3-a27390202a75}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{b7a7a3f2-374a-41e2-97d3-a27390202a75}.Debug|Any CPU.Build.0 = Debug|Any CPU
{b7a7a3f2-374a-41e2-97d3-a27390202a75}.Release|Any CPU.ActiveCfg = Release|Any CPU
{b7a7a3f2-374a-41e2-97d3-a27390202a75}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// -------------------------------------------------------------------------------------------------
//
// This code is a cTrader Algo API example.
//
// The code is provided as a sample only and does not guarantee any particular outcome or profit of any kind. Use it at your own risk.
//
// This sample indicator displays a simple trading panel.
//
// For a detailed tutorial on creating this indicator, see this video: https://www.youtube.com/watch?v=IJu7zxl5DA0
//
// -------------------------------------------------------------------------------------------------

using System;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
[Indicator(AccessRights = AccessRights.None, IsOverlay = true)]
public class TradingPanel : Indicator
{
protected override void Initialize()
{
var tradeButtonBuy = new Button
{
Text = "Buy",
ForegroundColor = Color.White,
BackgroundColor = Color.Green,
Height = 25,
Width = 75,
Margin = 2
};

tradeButtonBuy.Click += args => ExecuteMarketOrderAsync(TradeType.Buy, SymbolName, 1000);

var tradeButtonSell = new Button
{
Text = "Sell",
ForegroundColor = Color.White,
BackgroundColor = Color.Red,
Height = 25,
Width = 75,
Margin = 2
};
tradeButtonSell.Click += args => ExecuteMarketOrderAsync(TradeType.Sell, SymbolName, 1000);

var grid = new Grid(1, 2);
grid.AddChild(tradeButtonBuy, 0,0);
grid.AddChild(tradeButtonSell, 0, 1);
Chart.AddControl(grid);
}

public override void Calculate(int index)
{
// Calculate value at specified index
// Result[index] =
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="cTrader.Automate" Version="*" />
</ItemGroup>
</Project>
9 changes: 9 additions & 0 deletions Robots/.samples.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
{
"name": "Bollinger Bands Sample"
},
{
"name": "cBots Adds Indicator Sample"
},
{
"name": "cBots Starts cBot Sample"
},
{
"name": "Center Of Gravity Sample"
},
Expand Down Expand Up @@ -299,6 +305,9 @@
{
"name": "Volume ROC Sample"
},
{
"name": "Web Sockets Sample"
},
{
"name": "WebSocket Sample"
},
Expand Down
22 changes: 22 additions & 0 deletions Robots/Web Sockets Sample/Web Sockets Sample.sln
Original file line number Diff line number Diff line change
@@ -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}") = "Web Sockets Sample", "Web Sockets Sample\Web Sockets Sample.csproj", "{cd5f4d41-2fe3-40da-b9b2-389ea0689fc4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{cd5f4d41-2fe3-40da-b9b2-389ea0689fc4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{cd5f4d41-2fe3-40da-b9b2-389ea0689fc4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{cd5f4d41-2fe3-40da-b9b2-389ea0689fc4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{cd5f4d41-2fe3-40da-b9b2-389ea0689fc4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
53 changes: 53 additions & 0 deletions Robots/Web Sockets Sample/Web Sockets Sample/Web Sockets Sample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// -------------------------------------------------------------------------------------------------
//
// This code is a cTrader Algo API example.
//
// The code is provided as a sample only and does not guarantee any particular outcome or profit of any kind. Use it at your own risk.
//
// This sample cBot subscribes to a symbol price feed and streams the prices.
//
// For a detailed tutorial on creating this cBot, see this video: https://www.youtube.com/watch?v=y5ARwEEXSLI
//
// -------------------------------------------------------------------------------------------------

using System;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo.Robots
{
[Robot(AccessRights = AccessRights.None, AddIndicators = true)]
public class WebSocketsExample : Robot
{
private WebSocketClient _webSocketClient = new WebSocketClient();
private readonly Uri _targetUri = new Uri("wss://marketdata.tradermade.com/feedadv");

protected override void OnStart()
{
_webSocketClient.Connect(_targetUri);

_webSocketClient.TextReceived += _webSocketClient_TextReceived;

var data = "{\"userKey\":\"PasteStreamingKeyHere\", \"symbol\":\"EURUSD\"}";

_webSocketClient.Send(data);
}

private void _webSocketClient_TextReceived(WebSocketClientTextReceivedEventArgs obj)
{
Print(obj.Text.Replace("{", "").Replace("}", "").ToString());
}

protected override void OnTick()
{
// Handle price updates here
}

protected override void OnStop()
{
_webSocketClient.Close(WebSocketClientCloseStatus.NormalClosure);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="cTrader.Automate" Version="*" />
</ItemGroup>
</Project>
22 changes: 22 additions & 0 deletions Robots/cBot Adds Indicator Sample/cBot Adds Indicator Sample.sln
Original file line number Diff line number Diff line change
@@ -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}") = "cBot Adds Indicator Sample", "cBot Adds Indicator Sample\cBot Adds Indicator Sample.csproj", "{1751be77-fe78-4e12-b558-7fb418ed6b44}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1751be77-fe78-4e12-b558-7fb418ed6b44}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1751be77-fe78-4e12-b558-7fb418ed6b44}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1751be77-fe78-4e12-b558-7fb418ed6b44}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1751be77-fe78-4e12-b558-7fb418ed6b44}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// -------------------------------------------------------------------------------------------------
//
// This code is a cTrader Algo API example.
//
// The code is provided as a sample only and does not guarantee any particular outcome or profit of any kind. Use it at your own risk.
//
// This sample cBot adds two moving averages for trading to a chart.
//
// For a detailed tutorial on creating this cBot, see this video: https://www.youtube.com/watch?v=DUzdEt30OSE
//
// -------------------------------------------------------------------------------------------------


using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None, AddIndicators = true)]
public class SampleTrendcBot : Robot
{
[Parameter("Quantity (Lots)", Group = "Volume", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]
public double Quantity { get; set; }

[Parameter("MA Type", Group = "Moving Average")]
public MovingAverageType MAType { get; set; }

[Parameter("Source", Group = "Moving Average")]
public DataSeries SourceSeries { get; set; }

[Parameter("Slow Periods", Group = "Moving Average", DefaultValue = 10)]
public int SlowPeriods { get; set; }

[Parameter("Fast Periods", Group = "Moving Average", DefaultValue = 5)]
public int FastPeriods { get; set; }

private MovingAverage slowMa;
private MovingAverage fastMa;
private const string label = "Sample Trend cBot";

ChartIndicator _indicator1;
ChartIndicator _indicator2;

protected override void OnStart()
{
fastMa = Indicators.MovingAverage(SourceSeries, FastPeriods, MAType);
slowMa = Indicators.MovingAverage(SourceSeries, SlowPeriods, MAType);

_indicator1 = Chart.Indicators.Add("Simple Moving Average", SourceSeries, FastPeriods, MAType);
_indicator2 = Chart.Indicators.Add("Simple Moving Average", SourceSeries, SlowPeriods, MAType);

_indicator1.Lines[0].Color = Color.Red;
_indicator1.Lines[0].Thickness = 3;
}

protected override void OnBarClosed()
{
Chart.Indicators.Remove(_indicator1);
Chart.Indicators.Remove(_indicator2);
}

protected override void OnTick()
{
var longPosition = Positions.Find(label, SymbolName, TradeType.Buy);
var shortPosition = Positions.Find(label, SymbolName, TradeType.Sell);

var currentSlowMa = slowMa.Result.Last(0);
var currentFastMa = fastMa.Result.Last(0);
var previousSlowMa = slowMa.Result.Last(1);
var previousFastMa = fastMa.Result.Last(1);

if (previousSlowMa > previousFastMa && currentSlowMa <= currentFastMa && longPosition == null)
{
if (shortPosition != null)
ClosePosition(shortPosition);

ExecuteMarketOrder(TradeType.Buy, SymbolName, VolumeInUnits, label);
}
else if (previousSlowMa < previousFastMa && currentSlowMa >= currentFastMa && shortPosition == null)
{
if (longPosition != null)
ClosePosition(longPosition);

ExecuteMarketOrder(TradeType.Sell, SymbolName, VolumeInUnits, label);
}
}

private double VolumeInUnits
{
get { return Symbol.QuantityToVolumeInUnits(Quantity); }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="cTrader.Automate" Version="*" />
</ItemGroup>
</Project>
22 changes: 22 additions & 0 deletions Robots/cBot Starts cBot Sample/cBot Starts cBot Sample.sln
Original file line number Diff line number Diff line change
@@ -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}") = "cBot Starts cBot Sample", "cBot Starts cBot Sample\cBot Starts cBot Sample.csproj", "{1751be77-fe78-4e12-b558-7fb418ed6b44}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1751be77-fe78-4e12-b558-7fb418ed6b44}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1751be77-fe78-4e12-b558-7fb418ed6b44}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1751be77-fe78-4e12-b558-7fb418ed6b44}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1751be77-fe78-4e12-b558-7fb418ed6b44}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Loading