Skip to content

Commit

Permalink
strategy parameter Button create
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWan committed May 18, 2020
1 parent 6d1c4b6 commit 8c82d90
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 11 deletions.
79 changes: 78 additions & 1 deletion project/OsEngine/Entity/StrategyParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -774,9 +774,81 @@ public bool LoadFromString(string save)

return false;
}
}

/// <summary>
/// A strategy parameter to button click
/// Параметр для обработки нажатия на кнопку
/// </summary>
public class StrategyParameterButton : IIStrategyParameter
{
public StrategyParameterButton(string buttonLabel)
{
_name = buttonLabel;
_type = StrategyParameterType.Button;
}

/// <summary>
/// blank. it is impossible to create a variable of StrategyParameter type with an empty constructor
/// заглушка. нельзя создать переменную типа StrategyParameter с пустым конструктором
/// </summary>
private StrategyParameterButton()
{

}

/// <summary>
/// to take a line to save
/// взять строку для сохранения
/// </summary>
public string GetStringToSave()
{
string save = _name + "#";

return save;
}

/// <summary>
/// download settings from the save file
/// загрузить настройки из файла сохранения
/// </summary>
/// <param name="save"></param>
public void LoadParamFromString(string[] save)
{
}

/// <summary>
/// Parameter name. Used to identify a parameter in the settings windows
/// Название параметра. Используется для идентификации параметра в окнах настроек
/// </summary>
public string Name
{
get { return _name; }
}
private string _name;

/// <summary>
/// parameter type
/// тип параметра
/// </summary>
public StrategyParameterType Type
{
get { return _type; }
}
private StrategyParameterType _type;

public event Action ValueChange;

public void Click()
{
UserClickOnButtonEvent?.Invoke();
}

public event Action UserClickOnButtonEvent;
}



/// <summary>
/// parameter type
/// тип параметра
Expand Down Expand Up @@ -810,7 +882,12 @@ public enum StrategyParameterType
/// <summary>
/// время
/// </summary>
TimeOfDay
TimeOfDay,

/// <summary>
/// нажатие на кнопку
/// </summary>
Button
}

}
2 changes: 1 addition & 1 deletion project/OsEngine/Entity/StrategyParemetrsUi.xaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Window x:Class="OsEngine.Entity.ParemetrsUi"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Parameters" Height="262" Width="615" Topmost="True" Style="{StaticResource WindowStyleNoResize}" WindowStartupLocation="CenterScreen" Icon="/Images/OsLogo.ico">
Title="Parameters" Height="370" Width="615" Topmost="True" Style="{StaticResource WindowStyleNoResize}" WindowStartupLocation="CenterScreen" Icon="/Images/OsLogo.ico">
<Grid>
<Rectangle Margin="5"/>
<WindowsFormsHost Name="HostParametrs" Margin="10,10,10,41"/>
Expand Down
43 changes: 41 additions & 2 deletions project/OsEngine/Entity/StrategyParemetrsUi.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ namespace OsEngine.Entity
/// </summary>
public partial class ParemetrsUi
{

private List<IIStrategyParameter> _parameters;

public ParemetrsUi(List<IIStrategyParameter> parameters)
Expand All @@ -35,8 +34,9 @@ public ParemetrsUi(List<IIStrategyParameter> parameters)

private void CreateTable()
{
_grid = DataGridFactory.GetDataGridView(DataGridViewSelectionMode.FullRowSelect,
_grid = DataGridFactory.GetDataGridView(DataGridViewSelectionMode.CellSelect,
DataGridViewAutoSizeRowsMode.None);
_grid.ScrollBars = ScrollBars.Vertical;

DataGridViewTextBoxCell cell0 = new DataGridViewTextBoxCell();
cell0.Style = _grid.DefaultCellStyle;
Expand All @@ -59,6 +59,7 @@ private void CreateTable()
_grid.Rows.Add(null, null);

_grid.CellValueChanged += _grid_CellValueChanged;
_grid.CellClick += _grid_Click;

HostParametrs.Child = _grid;
}
Expand Down Expand Up @@ -123,10 +124,48 @@ private void PaintTable()
cell.Value = param.Value.ToString();
row.Cells.Add(cell);
}
else if (_parameters[i].Type == StrategyParameterType.Button)
{
DataGridViewButtonCell cell = new DataGridViewButtonCell();
row.Cells[0].Value = "";
cell.Value = _parameters[i].Name;
// StrategyParameterButton param = (StrategyParameterButton)_parameters[i];

row.Cells.Add(cell);
}

_grid.Rows.Add(row);
}
}

private void _grid_Click(object sender, EventArgs e)
{
int index = 0;

try
{
int cellIndex = _grid.SelectedCells[0].ColumnIndex;

if (cellIndex != 1)
{
return;
}

index = _grid.SelectedCells[0].RowIndex;
if (_parameters[index].Type != StrategyParameterType.Button)
{
return;
}
}
catch
{
return;
}

StrategyParameterButton param = (StrategyParameterButton)_parameters[index];
param.Click();
}

private void _grid_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
int index = e.RowIndex;
Expand Down
10 changes: 9 additions & 1 deletion project/OsEngine/OsTrader/OsTraderMaster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ namespace OsEngine.OsTrader
/// </summary>
public class OsTraderMaster
{
#region Static Part

public static OsTraderMaster Master;

#endregion

/// <summary>
/// create a robot manager
/// создать менеджера роботов
Expand Down Expand Up @@ -113,6 +119,8 @@ public OsTraderMaster(WindowsFormsHost hostChart, WindowsFormsHost hostGlass, Wi
_tabBotNames.SelectionChanged += _tabBotControl_SelectionChanged;
ReloadRiskJournals();
_globalController.StartPaint();

OsTraderMaster.Master = this;
}

private WindowsFormsHost _hostLogPrime;
Expand Down Expand Up @@ -140,7 +148,7 @@ public OsTraderMaster(WindowsFormsHost hostChart, WindowsFormsHost hostGlass, Wi
/// bots array
/// массив роботов
/// </summary>
private List<BotPanel> _panelsArray;
public List<BotPanel> _panelsArray;

/// <summary>
/// the bot to which the interface is currently connected
Expand Down
16 changes: 16 additions & 0 deletions project/OsEngine/OsTrader/Panels/BotPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,22 @@ public StrategyParameterBool CreateParameter(string name, bool value)
return (StrategyParameterBool)LoadParameterValues(newParameter);
}

/// <summary>
/// create button type parameter /
/// создать параметр типа Button
/// </summary>
public StrategyParameterButton CreateParameterButton(string buttonLabel)
{
StrategyParameterButton newParameter = new StrategyParameterButton(buttonLabel);

if (_parameters.Find(p => p.Name == buttonLabel) != null)
{
throw new Exception(OsLocalization.Trader.Label52);
}

return (StrategyParameterButton)LoadParameterValues(newParameter);
}

/// <summary>
/// load parameter settings /
/// загрузить настройки параметра
Expand Down
6 changes: 0 additions & 6 deletions project/OsEngine/Robots/High Frequency/Fisher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ private void Fisher_DeleteEvent()

private bool _isDisposed;

/// <summary>
/// uniq strategy name
/// взять уникальное имя
/// </summary>
public override string GetNameStrategyType()
{
return "Fisher";
Expand All @@ -60,8 +56,6 @@ public override void ShowIndividualSettingsDialog()

private BotTabSimple _tab;

//indicators индикаторы

private Aindicator _sma;

public StrategyParameterDecimal Volume;
Expand Down
Binary file modified project/OsEngine/bin/Debug/OsEngine.exe
Binary file not shown.

0 comments on commit 8c82d90

Please sign in to comment.