Skip to content

Commit

Permalink
Merge pull request spotware#21 from spotware/es/CNT-638
Browse files Browse the repository at this point in the history
Add a plugin example from the video.
  • Loading branch information
evgenisedin authored Jun 13, 2024
2 parents 7f794b8 + 0995433 commit e11a175
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Plugins/.samples.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
{
"name": "PositionCurrentPrice Sample"
},
{
"name": "Previous Bar Info"
},
{
"name": "SmoothMouseMove Sample"
},
Expand Down
22 changes: 22 additions & 0 deletions Plugins/Previous Bar Info/Previous Bar Info.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}") = "Previous Bar Info", "Previous Bar Info\Previous Bar Info.csproj", "{745f073c-3ae0-4138-a7ef-5f56c8c43c40}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{745f073c-3ae0-4138-a7ef-5f56c8c43c40}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{745f073c-3ae0-4138-a7ef-5f56c8c43c40}.Debug|Any CPU.Build.0 = Debug|Any CPU
{745f073c-3ae0-4138-a7ef-5f56c8c43c40}.Release|Any CPU.ActiveCfg = Release|Any CPU
{745f073c-3ae0-4138-a7ef-5f56c8c43c40}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
106 changes: 106 additions & 0 deletions Plugins/Previous Bar Info/Previous Bar Info/Previous Bar Info.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// -------------------------------------------------------------------------------------------------
//
// 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 example plugin adds a new section to Trade Watch, featuring a two-by-two grid that displays information about the last known bar prices.
//
// For a detailed tutorial on creating this plugin, watch the video at: https://youtu.be/0HB-rdwpMAY
//
// -------------------------------------------------------------------------------------------------

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

namespace cAlgo.Plugins
{
[Plugin(AccessRights = AccessRights.None)]
public class PreviousBarInfo : Plugin
{

Bars _bars;
Grid _grid;
TextBlock _lowBlock;
TextBlock _openBlock;
TextBlock _highBlock;
TextBlock _closeBlock;

protected override void OnStart()
{
var tradeWatchTab = TradeWatch.AddTab("Previous Bar Info");
tradeWatchTab.IsSelected = true;

var webView = new WebView();
tradeWatchTab.Child = webView;

webView.NavigateAsync("https://ctrader.com/");

_grid = new Grid(2, 2)
{
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
ShowGridLines = true,
Height = 150,
Width = 150,
};

_bars = MarketData.GetBars(TimeFrame.Minute, "USDJPY");

_lowBlock = new TextBlock
{
Text = "Low:" + _bars.LowPrices.LastValue,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
};

_highBlock = new TextBlock
{
Text = "High:" + _bars.HighPrices.LastValue,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
};

_closeBlock = new TextBlock
{
Text = "Close:" +_bars.ClosePrices.LastValue,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
};

_openBlock = new TextBlock
{
Text = "Open:" + _bars.OpenPrices.LastValue,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
};

_grid.AddChild(_lowBlock, 0, 0);
_grid.AddChild(_highBlock, 0, 1);
_grid.AddChild(_openBlock, 1, 0);
_grid.AddChild(_closeBlock, 1, 1);

tradeWatchTab.Child = _grid;

_bars.Tick += _bars_Tick;


}

private void _bars_Tick(BarsTickEventArgs obj)
{
_lowBlock.Text = "Low: " +_bars.LowPrices.LastValue.ToString();
_highBlock.Text = "High: " +_bars.HighPrices.LastValue.ToString();
_openBlock.Text = "Open: " +_bars.OpenPrices.LastValue.ToString();
_closeBlock.Text = "Close: " +_bars.ClosePrices.LastValue.ToString();
}

protected override void OnStop()
{
// Handle Plugin stop here
}
}
}
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>

0 comments on commit e11a175

Please sign in to comment.