Skip to content

Commit 2a531fe

Browse files
committed
Bar events examples added
1 parent 70a2acc commit 2a531fe

File tree

9 files changed

+199
-0
lines changed

9 files changed

+199
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30011.22
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BarClosed Example", "BarClosed Example\BarClosed Example.csproj", "{9a27c2b0-c67d-485b-a31d-b4f4dfabad1f}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{9a27c2b0-c67d-485b-a31d-b4f4dfabad1f}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{9a27c2b0-c67d-485b-a31d-b4f4dfabad1f}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{9a27c2b0-c67d-485b-a31d-b4f4dfabad1f}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{9a27c2b0-c67d-485b-a31d-b4f4dfabad1f}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using cAlgo.API;
6+
using cAlgo.API.Collections;
7+
using cAlgo.API.Indicators;
8+
using cAlgo.API.Internals;
9+
10+
namespace cAlgo.Robots
11+
{
12+
[Robot(AccessRights = AccessRights.None)]
13+
public class BarClosedExample : Robot
14+
{
15+
protected override void OnBarClosed()
16+
{
17+
var lowCloseDifference = ((Bars.LastBar.Close - Bars.LastBar.Low) / Bars.LastBar.Close) * 100;
18+
if (lowCloseDifference > 0.5)
19+
{
20+
foreach (var position in Positions)
21+
{
22+
position.Close();
23+
}
24+
ExecuteMarketOrder(TradeType.Buy, SymbolName, 10000, null, null, 50);
25+
}
26+
}
27+
}
28+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>net6.0</TargetFramework>
4+
</PropertyGroup>
5+
6+
<ItemGroup>
7+
<PackageReference Include="cTrader.Automate" Version="1.*" />
8+
</ItemGroup>
9+
</Project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30011.22
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BarOpened Example", "BarOpened Example\BarOpened Example.csproj", "{24d357c7-29ad-4a54-a7b4-34e6131ce23b}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{24d357c7-29ad-4a54-a7b4-34e6131ce23b}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{24d357c7-29ad-4a54-a7b4-34e6131ce23b}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{24d357c7-29ad-4a54-a7b4-34e6131ce23b}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{24d357c7-29ad-4a54-a7b4-34e6131ce23b}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using cAlgo.API;
6+
using cAlgo.API.Collections;
7+
using cAlgo.API.Indicators;
8+
using cAlgo.API.Internals;
9+
10+
namespace cAlgo.Robots
11+
{
12+
[Robot(AccessRights = AccessRights.None)]
13+
public class BarOpenedExample : Robot
14+
{
15+
protected override void OnBar()
16+
{
17+
var previousBar = Bars[Bars.Count - 2];
18+
var priceDifference = ((Bars.LastBar.Open - previousBar.Open) / previousBar.Open) * 100;
19+
20+
if (priceDifference > 1)
21+
{
22+
ExecuteMarketOrder(TradeType.Buy, SymbolName, 10000);
23+
}
24+
else if (priceDifference < -1)
25+
{
26+
ExecuteMarketOrder(TradeType.Sell, SymbolName, 10000);
27+
}
28+
else
29+
{
30+
foreach (var position in Positions)
31+
{
32+
position.Close();
33+
}
34+
}
35+
}
36+
}
37+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>net6.0</TargetFramework>
4+
</PropertyGroup>
5+
6+
<ItemGroup>
7+
<PackageReference Include="cTrader.Automate" Version="1.*" />
8+
</ItemGroup>
9+
</Project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30011.22
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomHandlers Example", "CustomHandlers Example\CustomHandlers Example.csproj", "{1fe8d3ac-8775-4f01-bbe6-51cf8a4a86b4}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{1fe8d3ac-8775-4f01-bbe6-51cf8a4a86b4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{1fe8d3ac-8775-4f01-bbe6-51cf8a4a86b4}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{1fe8d3ac-8775-4f01-bbe6-51cf8a4a86b4}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{1fe8d3ac-8775-4f01-bbe6-51cf8a4a86b4}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using cAlgo.API;
6+
using cAlgo.API.Collections;
7+
using cAlgo.API.Indicators;
8+
using cAlgo.API.Internals;
9+
10+
namespace cAlgo.Robots
11+
{
12+
[Robot(AccessRights = AccessRights.None)]
13+
public class CustomHandlersExample : Robot
14+
{
15+
16+
protected override void OnStart()
17+
{
18+
Bars.BarOpened += BullishReversal;
19+
Bars.BarOpened += BearishReversal;
20+
}
21+
22+
23+
private void BullishReversal(BarOpenedEventArgs args)
24+
{
25+
if (Bars.LastBar.Open > Bars.Last(1).Close && Bars.LastBar.Open > Bars.Last(2).Close)
26+
{
27+
ExecuteMarketOrder(TradeType.Buy, SymbolName, 10000, null, 10, 50);
28+
}
29+
}
30+
31+
private void BearishReversal(BarOpenedEventArgs args)
32+
{
33+
if (Bars.LastBar.Open < Bars.Last(1).Close && Bars.LastBar.Open < Bars.Last(2).Close)
34+
{
35+
ExecuteMarketOrder(TradeType.Sell, SymbolName, 10000, null, 10, 50);
36+
}
37+
}
38+
39+
}
40+
}
41+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>net6.0</TargetFramework>
4+
</PropertyGroup>
5+
6+
<ItemGroup>
7+
<PackageReference Include="cTrader.Automate" Version="1.*" />
8+
</ItemGroup>
9+
</Project>

0 commit comments

Comments
 (0)