Skip to content

Commit 6df33b9

Browse files
author
Ahmad Noman Musleh
committed
Add new plugin samples.
1 parent a95efe6 commit 6df33b9

26 files changed

+1312
-128
lines changed

‎Plugins/.samples.json‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,52 @@
55
{
66
"name": "All placements"
77
},
8+
{
9+
"name": "ActiveFrameChanged Sample"
10+
},
11+
{
12+
"name": "AlgoRegistry Sample"
13+
},
14+
{
15+
"name": "BacktestingInPlugins Sample"
16+
},
17+
{
18+
"name": "ChartId Sample"
19+
},
20+
{
21+
"name": "ChartIndicators Sample"
22+
},
23+
{
24+
"name": "ChartRobots Sample"
25+
},
26+
{
27+
"name": "Commands Sample"
28+
},
29+
{
30+
"name": "CoordinatesConversion Sample"
31+
},
32+
{
33+
"name": "Custom Frame Sample"
34+
},
35+
{
36+
"name": "IndicatorTitles Sample"
37+
},
838
{
939
"name": "Interactive WebView"
1040
},
1141
{
1242
"name": "Order by Margin"
43+
},
44+
{
45+
"name": "PositionCurrentPrice Sample"
46+
},
47+
{
48+
"name": "SmoothMouseMove Sample"
49+
},
50+
{
51+
"name": "TradeWatch Tab Sample"
52+
},
53+
{
54+
"name": "WebSocket Sample"
1355
}
1456
]

‎Plugins/AlgoRegistry Sample/AlgoRegistry Sample.sln‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 16
44
VisualStudioVersion =16.0.30011.22
55
MinimumVisualStudioVersion =10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AlgoRegistry Sample", "AlgoRegistry Sample\AlgoRegistry Sample.csproj", "{253c1137-a441-477f-bbdd-8dffcad26446}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AlgoRegistry Sample", "AlgoRegistry Sample\AlgoRegistry Sample.csproj", "{43349484-218e-4bf3-a452-0e44bf636cfe}"
77
EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1010
Debug|Any CPU = Debug|Any CPU
1111
Release|Any CPU = Release|Any CPU
1212
EndGlobalSection
1313
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14-
{253c1137-a441-477f-bbdd-8dffcad26446}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15-
{253c1137-a441-477f-bbdd-8dffcad26446}.Debug|Any CPU.Build.0 = Debug|Any CPU
16-
{253c1137-a441-477f-bbdd-8dffcad26446}.Release|Any CPU.ActiveCfg = Release|Any CPU
17-
{253c1137-a441-477f-bbdd-8dffcad26446}.Release|Any CPU.Build.0 = Release|Any CPU
14+
{43349484-218e-4bf3-a452-0e44bf636cfe}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{43349484-218e-4bf3-a452-0e44bf636cfe}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{43349484-218e-4bf3-a452-0e44bf636cfe}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{43349484-218e-4bf3-a452-0e44bf636cfe}.Release|Any CPU.Build.0 = Release|Any CPU
1818
EndGlobalSection
1919
GlobalSection(SolutionProperties) = preSolution
2020
HideSolutionNode =FALSE

‎Plugins/AlgoRegistry Sample/AlgoRegistry Sample/AlgoRegistry Sample.cs‎

Lines changed: 12 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -5,99 +5,31 @@
55
// This code is intended to be used as a sample and does not guarantee any particular outcome or
66
// profit of any kind. Use it at your own risk.
77
//
8-
// This sample adds a new block into the ASP. The block displays statistics about the number of
9-
// different types of algorithms installed on the user's machine. Information in the block is
10-
// updated every second to make sure that it is always accurate.
8+
// This sample adds a trade watch tab, and uses AlgoRegistry API to show stats about installed algo types.
119
//
1210
// -------------------------------------------------------------------------------------------------
1311

14-
15-
usingSystem;
16-
usingSystem.Collections.Generic;
17-
usingSystem.Linq;
18-
usingSystem.Text;
1912
usingcAlgo.API;
20-
usingcAlgo.API.Collections;
21-
usingcAlgo.API.Indicators;
22-
usingcAlgo.API.Internals;
2313

2414
namespacecAlgo.Plugins
2515
{
2616
[Plugin(AccessRights=AccessRights.None)]
2717
publicclassAlgoRegistrySample:Plugin
2818
{
29-
// Declaring the TextBlock for displaying data about
30-
// custom indicators
31-
privateTextBlock_customIndicatorsBlock=newTextBlock
32-
{
33-
FontSize=12,
34-
FontWeight=FontWeight.Bold,
35-
TextAlignment=TextAlignment.Left,
36-
Padding=newThickness(5,5,5,5),
37-
};
38-
39-
// Declaring the TextBlock for displaying data about
40-
// built-in indicators
41-
privateTextBlock_indicatorsBlock=newTextBlock
42-
{
43-
FontSize=12,
44-
FontWeight=FontWeight.Bold,
45-
TextAlignment=TextAlignment.Left,
46-
Padding=newThickness(5,5,5,5),
47-
};
48-
49-
// Declaring the TextBlock for displaying data about
50-
// cBots
51-
privateTextBlock_robotsBlock=newTextBlock
52-
{
53-
FontSize=12,
54-
FontWeight=FontWeight.Bold,
55-
TextAlignment=TextAlignment.Left,
56-
Padding=newThickness(5,5,5,5),
57-
};
58-
59-
// Declaring the TextBlock for displaying data about
60-
// plugins
61-
privateTextBlock_pluginsBlock=newTextBlock
62-
{
63-
FontSize=12,
64-
FontWeight=FontWeight.Bold,
65-
TextAlignment=TextAlignment.Left,
66-
Padding=newThickness(5,5,5,5),
67-
};
68-
69-
// Declaring the Grid to store custom controls
70-
privateGrid_grid=newGrid(4,1);
71-
7219
protectedoverridevoidOnStart()
7320
{
74-
// Adding a new block into the ASP and adding
75-
// the Grid with all TextBlocks as a child
76-
varaspBlock=Asp.SymbolTab.AddBlock("Algo Registry");
77-
aspBlock.IsExpanded=true;
78-
aspBlock.Height=200;
79-
80-
_grid.AddChild(_robotsBlock,0,0);
81-
_grid.AddChild(_indicatorsBlock,1,0);
82-
_grid.AddChild(_customIndicatorsBlock,2,0);
83-
_grid.AddChild(_pluginsBlock,3,0);
21+
vartradeWatchTab=TradeWatch.AddTab("Algo Registry");
8422

85-
aspBlock.Child=_grid;
23+
varpanel=newStackPanel
24+
{
25+
Orientation=Orientation.Horizontal,
26+
HorizontalAlignment=HorizontalAlignment.Center,
27+
};
28+
29+
panel.AddChild(newAlgoStatsControl(AlgoRegistry){Margin=10,VerticalAlignment=VerticalAlignment.Top});
30+
panel.AddChild(newAlgoTypeInfoControl(AlgoRegistry){Margin=10,VerticalAlignment=VerticalAlignment.Top});
8631

87-
// Starting the Timer to refresh information
88-
// in all TextBlocks
89-
Timer.Start(TimeSpan.FromSeconds(1));
32+
tradeWatchTab.Child=panel;
9033
}
91-
92-
protectedoverridevoidOnTimer()
93-
{
94-
// Using the AlgoRegistry to attain information about the
95-
// different AlgoKinds installed on the user's machine
96-
_robotsBlock.Text=$"cBots: {AlgoRegistry.GetCount(AlgoKind.Robot)}";
97-
_customIndicatorsBlock.Text=$"Custom indicators: {AlgoRegistry.GetCount(AlgoKind.CustomIndicator)}";
98-
_indicatorsBlock.Text=$"Indicators: {AlgoRegistry.GetCount(AlgoKind.StandardIndicator)}";
99-
_pluginsBlock.Text=$"Plugins: {AlgoRegistry.GetCount(AlgoKind.Plugin)}";
100-
}
101-
102-
}
34+
}
10335
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
usingSystem.Linq;
2+
usingcAlgo.API;
3+
4+
namespacecAlgo.Plugins;
5+
6+
publicclassAlgoStatsControl:CustomControl
7+
{
8+
privateconststringFontFamily="Calibri";
9+
10+
privatereadonlyAlgoRegistry_algoRegistry;
11+
privatereadonlyTextBlock_algosCountTextBlock;
12+
privatereadonlyTextBlock_customIndicatorsCountTextBlock;
13+
privatereadonlyTextBlock_standardIndicatorsCountTextBlock;
14+
privatereadonlyTextBlock_botsCountTextBlock;
15+
privatereadonlyTextBlock_pluginsCountTextBlock;
16+
17+
publicAlgoStatsControl(AlgoRegistryalgoRegistry)
18+
{
19+
_algoRegistry=algoRegistry;
20+
21+
varpanel=newGrid(6,2);
22+
23+
vartitleTextBlock=GetTextBlock("Algo Stats");
24+
25+
titleTextBlock.HorizontalAlignment=HorizontalAlignment.Center;
26+
27+
panel.AddChild(titleTextBlock,0,0,1,2);
28+
29+
panel.AddChild(GetTextBlock("Algos #"),1,0);
30+
31+
_algosCountTextBlock=GetTextBlock();
32+
33+
panel.AddChild(_algosCountTextBlock,1,1);
34+
35+
panel.AddChild(GetTextBlock("Standard Indicators #"),2,0);
36+
37+
_standardIndicatorsCountTextBlock=GetTextBlock();
38+
39+
panel.AddChild(_standardIndicatorsCountTextBlock,2,1);
40+
41+
panel.AddChild(GetTextBlock("Custom Indicators #"),3,0);
42+
43+
_customIndicatorsCountTextBlock=GetTextBlock();
44+
45+
panel.AddChild(_customIndicatorsCountTextBlock,3,1);
46+
47+
panel.AddChild(GetTextBlock("cBots #"),4,0);
48+
49+
_botsCountTextBlock=GetTextBlock();
50+
51+
panel.AddChild(_botsCountTextBlock,4,1);
52+
53+
panel.AddChild(GetTextBlock("Plugins #"),5,0);
54+
55+
_pluginsCountTextBlock=GetTextBlock();
56+
57+
panel.AddChild(_pluginsCountTextBlock,5,1);
58+
59+
AddChild(panel);
60+
61+
Populate();
62+
63+
_algoRegistry.AlgoTypeInstalled+= _ =>Populate();
64+
_algoRegistry.AlgoTypeDeleted+= _ =>Populate();
65+
}
66+
67+
privatevoidPopulate()
68+
{
69+
_algosCountTextBlock.Text=_algoRegistry.Count.ToString();
70+
_botsCountTextBlock.Text=_algoRegistry.Count(type =>type.AlgoKind==AlgoKind.Robot).ToString();
71+
_customIndicatorsCountTextBlock.Text=_algoRegistry.Count(type =>type.AlgoKind==AlgoKind.CustomIndicator).ToString();
72+
_standardIndicatorsCountTextBlock.Text=_algoRegistry.Count(type =>type.AlgoKind==AlgoKind.StandardIndicator).ToString();
73+
_pluginsCountTextBlock.Text=_algoRegistry.Count(type =>type.AlgoKind==AlgoKind.Plugin).ToString();
74+
}
75+
76+
privateTextBlockGetTextBlock(stringtext=null)=>new()
77+
{
78+
Margin=3,
79+
FontSize=20,
80+
FontWeight=FontWeight.Bold,
81+
FontFamily=FontFamily,
82+
Text=text
83+
};
84+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
usingSystem.Linq;
2+
usingcAlgo.API;
3+
4+
namespacecAlgo.Plugins;
5+
6+
publicclassAlgoTypeInfoControl:CustomControl
7+
{
8+
privateconststringFontFamily="Calibri";
9+
10+
privatereadonlyAlgoRegistry_algoRegistry;
11+
privatereadonlyComboBox_algoTypesComboBox;
12+
privatereadonlyTextBlock_algoTypeKindTextBlock;
13+
privatereadonlyTextBlock_algoTypeParametersTextBlock;
14+
privatereadonlyTextBlock_algoTypeOutputsTextBlock;
15+
16+
publicAlgoTypeInfoControl(AlgoRegistryalgoRegistry)
17+
{
18+
_algoRegistry=algoRegistry;
19+
20+
varpanel=newGrid(5,2){BackgroundColor=Color.Gray};
21+
22+
vartitleTextBlock=GetTextBlock("Algo Type Info");
23+
24+
titleTextBlock.HorizontalAlignment=HorizontalAlignment.Center;
25+
26+
panel.AddChild(titleTextBlock,0,0,1,2);
27+
28+
panel.AddChild(GetTextBlock("Types"),1,0);
29+
30+
_algoTypesComboBox=newComboBox
31+
{
32+
Margin=3,
33+
FontSize=20,
34+
FontWeight=FontWeight.Bold,
35+
FontFamily=FontFamily,
36+
Padding=2
37+
};
38+
39+
panel.AddChild(_algoTypesComboBox,1,1);
40+
41+
panel.AddChild(GetTextBlock("Kind"),2,0);
42+
43+
_algoTypeKindTextBlock=GetTextBlock();
44+
45+
panel.AddChild(_algoTypeKindTextBlock,2,1);
46+
47+
panel.AddChild(GetTextBlock("Parameters"),3,0);
48+
49+
_algoTypeParametersTextBlock=GetTextBlock();
50+
51+
panel.AddChild(_algoTypeParametersTextBlock,3,1);
52+
53+
panel.AddChild(GetTextBlock("Outputs"),4,0);
54+
55+
_algoTypeOutputsTextBlock=GetTextBlock();
56+
57+
panel.AddChild(_algoTypeOutputsTextBlock,4,1);
58+
59+
AddChild(panel);
60+
61+
_algoTypesComboBox.SelectedItemChanged+= _ =>OnAlgoTypesComboBoxSelectedItemChanged();
62+
63+
PopulateTypes();
64+
65+
_algoRegistry.AlgoTypeInstalled+= _ =>PopulateTypes();
66+
_algoRegistry.AlgoTypeDeleted+= _ =>PopulateTypes();
67+
}
68+
69+
privatevoidOnAlgoTypesComboBoxSelectedItemChanged()
70+
{
71+
if(_algoRegistry.Get(_algoTypesComboBox.SelectedItem)is not {}algoType)
72+
{
73+
_algoTypeKindTextBlock.Text=null;
74+
_algoTypeParametersTextBlock.Text=null;
75+
_algoTypeOutputsTextBlock.Text=null;
76+
77+
return;
78+
}
79+
80+
_algoTypeKindTextBlock.Text=algoType.AlgoKind.ToString();
81+
_algoTypeParametersTextBlock.Text=algoTypeswitch
82+
{
83+
IndicatorTypeindicatorType=>string.Join(", ",indicatorType.Parameters.Select(p =>p.Name)),
84+
RobotTyperobotType=>string.Join(", ",robotType.Parameters.Select(p =>p.Name)),
85+
_ =>null
86+
};
87+
_algoTypeOutputsTextBlock.Text=algoTypeswitch
88+
{
89+
IndicatorTypeindicatorType=>string.Join(", ",indicatorType.Outputs.Select(p =>p.Name)),
90+
_ =>null
91+
};
92+
}
93+
94+
privatevoidPopulateTypes()
95+
{
96+
foreach(varalgoTypein_algoRegistry)
97+
{
98+
_algoTypesComboBox.AddItem(algoType.Name);
99+
}
100+
101+
_algoTypesComboBox.SelectedItem=_algoRegistry.FirstOrDefault()?.Name;
102+
103+
OnAlgoTypesComboBoxSelectedItemChanged();
104+
}
105+
106+
privateTextBlockGetTextBlock(stringtext=null)=>new()
107+
{
108+
Margin=3,
109+
FontSize=20,
110+
FontWeight=FontWeight.Bold,
111+
FontFamily=FontFamily,
112+
Text=text
113+
};
114+
}

0 commit comments

Comments
(0)