Peper Trading in Playback mode

Questions about MultiCharts .NET and user contributed studies.
User avatar
orad
Posts: 121
Joined: 14 Nov 2012
Has thanked: 50 times
Been thanked: 20 times

Peper Trading in Playback mode

Postby orad » 24 Dec 2015

Hi, I'm trying to test my trades manually on Paper Trader profile when it is in playback mode, but trades get rejected. Is it possible to do manual trading in the playback mode (simulated) similar to Market Replay in OEC Trader?

Thanks!

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Peper Trading in Playback mode

Postby Henry MultiСharts » 28 Dec 2015

Hello orad,

Playback trading is not possible. If you manually place orders during the playback – they will be filled at the current market prices. If the orders are rejected please try clearing the symbol mapping and then placing the orders.

User avatar
orad
Posts: 121
Joined: 14 Nov 2012
Has thanked: 50 times
Been thanked: 20 times

Re: Peper Trading in Playback mode

Postby orad » 03 Jan 2016

Thanks. This would make a good feature specially for training purposes, and for manually trying strategies before writing code for them.

User avatar
orad
Posts: 121
Joined: 14 Nov 2012
Has thanked: 50 times
Been thanked: 20 times

Re: Peper Trading in Playback mode

Postby orad » 29 Jan 2016

Hi,

I tried to modify _ChartToolBar_Trading_ strategy to do this by making it to send orders using IOrderMarket orders like how we do for automated trading and backtesting. However, even though the lines to send orders are called but for some reason they won't take effect. What I wanted to accomplish was to run Data Playback and while it's running manually submit orders and have them show like backtesting orders.

Here's the code. Do you know why this is not working?
[+] _ChartToolBar_PlaybackTrading_.Strategy.CS

Code: Select all

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using ATCenterProxy.interop;
using PowerLanguage.TradeManager;

namespace PowerLanguage.Strategy
{
public class _ChartToolBar_PlaybackTrading_ : SignalObject
{
public _ChartToolBar_PlaybackTrading_(object _ctx) : base(_ctx)
{
}

private void AddItem2ToolStrip(ToolStrip tb, ToolStripItem item)
{
item.Tag = this;
tb.Items.Add(item);
}

private ToolStripButton m_info_panel;
private bool tool_bar_inited;

private IOrderMarket _marketLE;
private IOrderMarket _marketLX;
private IOrderMarket _marketSE;
private IOrderMarket _marketSX;

protected override void Create()
{
_marketLE = this.OrderCreator.MarketThisBar(new SOrderParameters(Contracts.UserSpecified, "LE", EOrderAction.Buy));
_marketLX = this.OrderCreator.MarketThisBar(new SOrderParameters(Contracts.UserSpecified, "LX", EOrderAction.Sell, OrderExit.Total));

_marketSE = this.OrderCreator.MarketThisBar(new SOrderParameters(Contracts.UserSpecified, "SE", EOrderAction.SellShort));
_marketSX = this.OrderCreator.MarketThisBar(new SOrderParameters(Contracts.UserSpecified, "SX", EOrderAction.BuyToCover, OrderExit.Total));
}

protected override void StartCalc()
{
if (!tool_bar_inited)
{
ChartToolBar.AccessToolBar(tb =>
{
var _tsi_b = new ToolStripButton
{
Text = "Buy Market",
BackColor = Color.DeepSkyBlue,
ToolTipText = "Click for send Buy 1 Market"
};
_tsi_b.Click += (_1, _2) => _tsi_b_Click(MTPA_OrdrActn.eMTPA_OA_Buy);
AddItem2ToolStrip(tb, _tsi_b);

m_info_panel = new ToolStripButton
{ToolTipText = "Click for Close Position"};
m_info_panel.Click += _info_panel_Click;
update_panel_info();
AddItem2ToolStrip(tb, m_info_panel);

var _tsi_s = new ToolStripButton
{
Text = "Sell Market",
BackColor = Color.LightCoral,
ToolTipText = "Click for send Sell 1 Market"
};
_tsi_s.Click += (_1, _2) => _tsi_b_Click(MTPA_OrdrActn.eMTPA_OA_Sell);
AddItem2ToolStrip(tb, _tsi_s);

AddItem2ToolStrip(tb, new ToolStripSeparator());
});

tool_bar_inited = true;
}


m_symbol = new MCSymbolInfo(Bars.Info.ASymbolInfo2, Bars.Info.DataFeed);
}

private void _info_panel_Click(object sender, EventArgs ev)
{
try
{
if (0 != PositionSide)
{
var contracts = Math.Abs(CurrentPosition.Value);
if (PositionSide > 0)
_marketSX.Send(contracts);
else
_marketLX.Send(contracts);

update_panel_info();
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}

private void update_panel_info()
{
int mp = tool_bar_inited ? CurrentPosition.Value : 0;
double opl = tool_bar_inited ? CurrentPosition.OpenProfit : 0;
ChartToolBar.AccessToolBarAsync(tb =>
{
m_info_panel.Enabled = 0 != mp;
m_info_panel.Text = MakeInfoPanelStr(mp, opl);
m_info_panel.BackColor = GetColor(opl);
});
}

private static string MakeInfoPanelStr(int mp, double opl)
{
string _mp_string;
if (0 < mp)
_mp_string = mp + " Long";
else if (0 > mp)
_mp_string = -mp + " Short";
else
_mp_string = "Flat";
return string.Format("{0} {1}", _mp_string, opl.ToString("C"));
}

private static Color GetColor(double opl)
{
return 0 > opl ? Color.OrangeRed : Color.LawnGreen;
}

private MCSymbolInfo m_symbol;

private void _tsi_b_Click(MTPA_OrdrActn action)
{
try
{
switch (action)
{
case MTPA_OrdrActn.eMTPA_OA_Buy:
_marketLE.Send(1);
break;
case MTPA_OrdrActn.eMTPA_OA_Sell:
_marketSE.Send(1);
break;
}
update_panel_info();
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}

protected override void CalcBar()
{
if (Bars.LastBarOnChart)
ExecControl.RecalcLastBarAfter(TimeSpan.FromSeconds(0.5));
}

protected override void OnRecalcLastBarAfterEvent()
{
TradeManager.ProcessEvents();
ExecControl.RecalcLastBarAfter(TimeSpan.FromSeconds(0.5));
}

protected override void Destroy()
{
if (tool_bar_inited)
{
ChartToolBar.AccessToolBar(tb =>
{
var _for_erase = new List<ToolStripItem>();

foreach (ToolStripItem item in tb.Items)
if (ReferenceEquals(this, item.Tag))
_for_erase.Add(item);

foreach (var item in _for_erase)
tb.Items.Remove(item);
});
}
}

}
}

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Peper Trading in Playback mode

Postby Henry MultiСharts » 29 Jan 2016

Hello orad,

My previous reply is still applicable:
Playback trading is not possible. If you manually place orders during the playback – they will be filled at the current market prices. If the orders are rejected please try clearing the symbol mapping and then placing the orders.

User avatar
orad
Posts: 121
Joined: 14 Nov 2012
Has thanked: 50 times
Been thanked: 20 times

Re: Peper Trading in Playback mode

Postby orad » 31 Jan 2016

Playback trading is not possible.
Well, I made it possible! This problem was that I needed to make sure orders where sent in the right thread, and now it works.

I posted the full code here under User Contributed Studies:

Simulate Manual Trading in Data Playback mode

Enjoy!

monexx
Posts: 87
Joined: 20 Feb 2014
Has thanked: 26 times
Been thanked: 7 times

Re: Peper Trading in Playback mode

Postby monexx » 01 Feb 2016

Playback trading is not possible.
Well, I made it possible! This problem was that I needed to make sure orders where sent in the right thread, and now it works.

I posted the full code here under User Contributed Studies:

Simulate Manual Trading in Data Playback mode

Enjoy!
Hello,
It is a great thing but too bad it's only for MC.NET

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Peper Trading in Playback mode

Postby JoshM » 01 Feb 2016

It is a great thing but too bad it's only for MC.NET
It can also be coded in MultiCharts PowerLanguage, but in that case you'll need to use text boxes on the chart for the position information (instead of a custom chart toolbar) and mouse click processing for the orders (instead of the toolbar buttons).

monexx
Posts: 87
Joined: 20 Feb 2014
Has thanked: 26 times
Been thanked: 7 times

Re: Peper Trading in Playback mode

Postby monexx » 01 Feb 2016

It is a great thing but too bad it's only for MC.NET
It can also be coded in MultiCharts PowerLanguage, but in that case you'll need to use text boxes on the chart for the position information (instead of a custom chart toolbar) and mouse click processing for the orders (instead of the toolbar buttons).
For me it is too difficult task ... :-)

bomberone1
Posts: 310
Joined: 02 Nov 2010
Has thanked: 26 times
Been thanked: 23 times

Re: Peper Trading in Playback mode

Postby bomberone1 » 20 Oct 2019

there is a vote request for multicharts easylangauge, in the while or someone post it a code or we waite again

https://www.multicharts.com/pm/public/m ... ues/mc-362

User avatar
Kate MultiCharts
Posts: 575
Joined: 21 Oct 2020
Has thanked: 7 times
Been thanked: 144 times

Re: Peper Trading in Playback mode

Postby Kate MultiCharts » 19 Mar 2024

Dear Users!

Simulated trading is now available in MultiCharts 15.
Please see our blog and the How to Use Simulated Trading Wiki for more info.


Return to “MultiCharts .NET”