protected override void OnStarted()
{
//vcon.Open();
CommissionRule commissionRule = new CommissionRule { Type = CommissionTypes.PerTradeVolume, Value = new Unit(3m) };
_commissionManager.Rules.Add(commissionRule);
Sostoyanie = "кэш";
takeprofit = decimal.Parse(MainWindow.Instance.takeprofit_form.Text);
proskalz = decimal.Parse(MainWindow.Instance.proskalz.Text);
vol_kontr = decimal.Parse(MainWindow.Instance.vol_lotov.Text);
vcon.Open();
// Создание элемента графика представляющего свечки
_candlesElem = new ChartCandleElement();
MainWindow.Instance._area.Elements.Add(_candlesElem);
//MainWindow.Instance._area_ind.Elements.Add(_longMaElem);
//MainWindow.Instance._area_ind.Elements.Add(_shortMaElem);
this
.WhenNewMyTrades()
.Do(ProcessNewTrades)
.Apply(this);
_series
.WhenCandlesFinished()
.Do(ProcessCandle)
.Apply(this);
base.OnStarted();
}
private void ProcessCandle(Candle candle)
{
// if (candle.State == CandleStates.Finished) MainWindow.Instance.GuiAsync(() => MainWindow.Instance.Chart.ProcessCandle(_candlesElem, candle));
Indicator.Process(candle.ClosePrice);
MainWindow.Instance.GuiAsync(() =>
{
MainWindow.Instance.trades_time.Text = Security.LastTrade.Time.ToString();
MainWindow.Instance.pos2_form.Text = Sostoyanie;
MainWindow.Instance.position_form.Text = Position.ToString();
});
if (!START)
{
if (Indicator.Container.Count > 2)
{
START = true;
Security
.WhenNewTrades()
.Do(ProcessNewTrade)
.Apply(this);
}
}
}
private void Comission_raschet()
{
comission = 0;
foreach (MyTrade trade in MyTrades)
{
comission = comission + _commissionManager.ProcessMyTrade(trade);
}
//MainWindow.Instance.GuiAsync(() =>
//{
// MainWindow.Instance.comission_form.Text = comission.ToString();
//});
}
private void ProcessNewTrade()
{
if (Security.LastTrade == null)
{ goto propusk2; }
if (Security.LastTrade.Time.Hour == 19 && Security.LastTrade.Time.Minute == 0 && Security.LastTrade.Time.Second < 10)
{ goto propusk2; }
switch (Sostoyanie)
{
case "кэш":
{
if (...)
{
Sostoyanie = "Long";
Buy_Order(vol_kontr);
}
else if (...)
{
Sostoyanie = "Short";
Sell_Order(vol_kontr);
}
}
break;
case "Long":
{
if (...)
{
Sostoyanie = "кэш";
Sell_Order(vol_kontr);
}
}
break;
case "Short":
{
if (...)
{
Sostoyanie = "кэш";
Buy_Order(vol_kontr);
}
}
break;
}
propusk2:
//MainWindow.Instance.GuiAsync(() =>
//{
// MainWindow.Instance.trades_time.Text = Security.LastTrade.Time.ToString();
// //MainWindow.Instance.now_time.Text = DateTime.Now.ToString();
// MainWindow.Instance.pos2_form.Text = pos;
// MainWindow.Instance.position_form.Text = Position.ToString();
// MainWindow.Instance.komiss_form.Text = comission.ToString();
//});
}
private void Buy_Order(decimal volume)
{
EntryPrice = Security.LastTrade.Price; ;
this.AddInfoLog("Сигнал на покупку");
nomersdelki++;
order_open_long = this.CreateOrder(OrderDirections.Buy, Security.LastTrade.Price + proskalz, volume);
order_open_long.Security = Security;
this.RegisterOrder(order_open_long);
order_open_long
.WhenMatched()
.Do(pos_change_long)
.Apply(this);
this.AddInfoLog(PnLManager.PnL.ToString());
//string vsql = string.Format("insert into Rez2 (nomer_sdelki, data_vxoda,vremya_vxoda, cena_vxoda, High, Low,stop_price) Values ({0}, {1}, {2}, {3}, {4}, {5}, {6})",
// (nomersdelki), (Security.LastTrade.Time.ToString("dd.MM")), (Security.LastTrade.Time.ToString("HH.mmss")), (order_open_long.Price.ToString()), (candle_high),(candle_low),(stop_price));
//OleDbCommand vcom = new OleDbCommand(vsql, vcon);
//vcom.ExecuteNonQuery();
}
private void Sell_Order(decimal volume)
{
EntryPrice = Security.LastTrade.Price;
this.AddInfoLog("Сигнал на продажу");
nomersdelki++;
order_open_short = this.CreateOrder(OrderDirections.Sell, Security.LastTrade.Price - proskalz, volume);
order_open_short.Security = Security;
this.RegisterOrder(order_open_short);
order_open_short
.WhenMatched()
.Do(pos_change_short)
.Apply(this);
//string vsql = string.Format("insert into Rez2 (nomer_sdelki, data_vxoda,vremya_vxoda, cena_vxoda, High, Low,stop_price) Values ({0}, {1}, {2}, {3}, {4}, {5}, {6})",
// (nomersdelki), (Security.LastTrade.Time.ToString("dd.MM")), (Security.LastTrade.Time.ToString("HH.mmss")), (order_open_long.Price.ToString()), (candle_high), (candle_low), (stop_price));
//OleDbCommand vcom = new OleDbCommand(vsql, vcon);
//vcom.ExecuteNonQuery();
}