Skip to content

Commit 4d61b74

Browse files
Merge pull request #38 from spotware/am/XT-17608
XT-17608 Create cBots, Indicators and Plugins Samples in Python. Add …
2 parents 1618351 + f09288b commit 4d61b74

File tree

421 files changed

+19679
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

421 files changed

+19679
-0
lines changed

Indicators/.samples.json

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,5 +175,89 @@
175175
},
176176
{
177177
"name": "Custom Control Sample"
178+
},
179+
{
180+
"name": "Data Series Sample"
181+
},
182+
{
183+
"name": "Dock Panel Sample"
184+
},
185+
{
186+
"name": "Ellipse Shape Sample"
187+
},
188+
{
189+
"name": "Equidistant Channel Sample"
190+
},
191+
{
192+
"name": "Fibonacci Expansion Sample"
193+
},
194+
{
195+
"name": "Fibonacci Fan Sample"
196+
},
197+
{
198+
"name": "Fibonacci Level Sample"
199+
},
200+
{
201+
"name": "Fibonacci Retracement Sample"
202+
},
203+
{
204+
"name": "Fill Rule Sample"
205+
},
206+
{
207+
"name": "Font Sample"
208+
},
209+
{
210+
"name": "Functions Sample"
211+
},
212+
{
213+
"name": "Grid Sample"
214+
},
215+
{
216+
"name": "GridColumn Sample"
217+
},
218+
{
219+
"name": "GridLength Sample"
220+
},
221+
{
222+
"name": "GridRow Sample"
223+
},
224+
{
225+
"name": "GridUnitType Sample"
226+
},
227+
{
228+
"name": "HistoricalTrade Sample"
229+
},
230+
{
231+
"name": "HorizontalAlignment Sample"
232+
},
233+
{
234+
"name": "HorizontalLine Sample"
235+
},
236+
{
237+
"name": "IIndicatorsAccessor Sample"
238+
},
239+
{
240+
"name": "Image Sample"
241+
},
242+
{
243+
"name": "Indicator Area Sample"
244+
},
245+
{
246+
"name": "Indicator Data Series Sample"
247+
},
248+
{
249+
"name": "IndicatorAreaAddedEventArgs Sample"
250+
},
251+
{
252+
"name": "IndicatorAreaEventArgs Sample"
253+
},
254+
{
255+
"name": "IndicatorAreaRemovedEventArgs Sample"
256+
},
257+
{
258+
"name": "IndicatorTitles Sample"
259+
},
260+
{
261+
"name": "Key Sample"
178262
}
179263
]
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}") = "Data Series Sample", "Data Series Sample\Data Series Sample.csproj", "{7a913f1d-1919-4bfb-a9b9-78c903b26e69}"
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+
{7a913f1d-1919-4bfb-a9b9-78c903b26e69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{7a913f1d-1919-4bfb-a9b9-78c903b26e69}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{7a913f1d-1919-4bfb-a9b9-78c903b26e69}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{7a913f1d-1919-4bfb-a9b9-78c903b26e69}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using Python.Runtime;
3+
4+
namespace cAlgo.Indicators;
5+
6+
internal abstract class BaseBridge
7+
{
8+
private readonly SafeExecuteMethodProxy _onOnTimerProxy;
9+
private readonly SafeExecuteMethodProxy _onExceptionProxy;
10+
11+
protected BaseBridge(PyObject objectInstance)
12+
{
13+
_onOnTimerProxy = new SafeExecuteMethodProxy(objectInstance, "on_timer");
14+
_onExceptionProxy = new SafeExecuteMethodProxy(objectInstance, "on_exception");
15+
}
16+
17+
internal void OnTimer()
18+
{
19+
_onOnTimerProxy.Invoke();
20+
}
21+
22+
internal void OnException(Exception exception)
23+
{
24+
_onExceptionProxy.Invoke(exception);
25+
}
26+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>net6.0</TargetFramework>
4+
<AlgoLanguage>Python</AlgoLanguage>
5+
<IncludeSource>True</IncludeSource>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<Compile Remove="**\*.py" />
10+
</ItemGroup>
11+
12+
<ItemGroup>
13+
<EmbeddedResource Include="**\*.py">
14+
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
15+
</EmbeddedResource>
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<None Update="requirements.txt">
20+
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
21+
</None>
22+
</ItemGroup>
23+
24+
<ItemGroup>
25+
<PackageReference Include="cTrader.Automate" Version="*" />
26+
<PackageReference Include="pythonnet" Version="3.0.5" />
27+
</ItemGroup>
28+
</Project>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import clr
2+
clr.AddReference("cAlgo.API")
3+
4+
from cAlgo.API import *
5+
6+
class DataSeriesSample():
7+
def initialize(self):
8+
grid = Grid(3, 2)
9+
grid.BackgroundColor = Color.DarkGoldenrod
10+
grid.HorizontalAlignment = HorizontalAlignment.Left
11+
grid.VerticalAlignment = VerticalAlignment.Bottom
12+
grid.Opacity = 0.5
13+
14+
grid.AddChild(self.get_text_block("Last Value"), 0, 0)
15+
16+
self.lastValueTextBlock = self.get_text_block(str(api.Source.LastValue))
17+
18+
grid.AddChild(self.lastValueTextBlock, 0, 1)
19+
grid.AddChild(self.get_text_block("Last Closed Value"), 1, 0)
20+
21+
self.lastClosedValueTextBlock = self.get_text_block(str(api.Source.Last(1)))
22+
23+
grid.AddChild(self.lastClosedValueTextBlock, 1, 1)
24+
25+
grid.AddChild(self.get_text_block("Values Count"), 2, 0)
26+
27+
self.countTextBlock = self.get_text_block(str(api.Source.Count))
28+
29+
grid.AddChild(self.countTextBlock, 2, 1)
30+
31+
api.Chart.AddControl(grid)
32+
33+
def calculate(self, index):
34+
# You can also use "LastValue" property if you don't have index
35+
self.lastValueTextBlock.Text = str(api.Source[index])
36+
# You can also use "Last(1)" property if you don't have index
37+
self.lastClosedValueTextBlock.Text = str(api.Source[index - 1])
38+
self.countTextBlock.Text = str(api.Source.Count)
39+
40+
def get_text_block(self, text):
41+
textBlock = TextBlock()
42+
textBlock.Text = text
43+
textBlock.Margin = Thickness(5)
44+
return textBlock
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
using cAlgo.API;
3+
4+
namespace cAlgo.Indicators;
5+
6+
[Indicator(AccessRights = AccessRights.None, IsOverlay = true)]
7+
public partial class DataSeriesSample : Indicator
8+
{
9+
[Parameter()]
10+
public DataSeries Source { get; set; }
11+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using System;
2+
using System.IO;
3+
using System.Linq;
4+
using System.Text.Json;
5+
6+
namespace cAlgo.Indicators;
7+
8+
internal class EmbeddedResourceProvider
9+
{
10+
public const string PythonManifestFileName = "EmbeddedResources.manifest.json";
11+
12+
internal static string[] List()
13+
{
14+
var assembly = typeof(EmbeddedResourceProvider).Assembly;
15+
return assembly.GetManifestResourceNames();
16+
}
17+
18+
internal static string ReadText(string name)
19+
{
20+
var assembly = typeof(EmbeddedResourceProvider).Assembly;
21+
var resourceName = assembly.GetManifestResourceNames()
22+
.SingleOrDefault(n => n.EndsWith($".{name}", StringComparison.OrdinalIgnoreCase));
23+
24+
if (resourceName == null)
25+
return null;
26+
27+
using var stream = assembly.GetManifestResourceStream(resourceName);
28+
if (stream == null)
29+
return null;
30+
31+
using var stringReader = new StreamReader(stream);
32+
return stringReader.ReadToEnd();
33+
}
34+
35+
internal static Stream ReadStream(string name)
36+
{
37+
var assembly = typeof(EmbeddedResourceProvider).Assembly;
38+
return assembly.GetManifestResourceStream(name);
39+
}
40+
41+
public static bool TryGetPythonManifest(out PythonManifest pythonManifest)
42+
{
43+
pythonManifest = null;
44+
var pythonManifestJson = ReadText(PythonManifestFileName);
45+
46+
if (string.IsNullOrEmpty(pythonManifestJson))
47+
return false;
48+
49+
pythonManifest = JsonSerializer.Deserialize<PythonManifest>(pythonManifestJson);
50+
51+
return true;
52+
}
53+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"RootNamespace": "Data_Series_Sample","PythonFiles": ["Data Series Sample_main.py","http_requests.py"]}

0 commit comments

Comments
 (0)