Hi,
Could you please let me know how to determine the open positions for a strategy?
In OpenQuant it is done like such:
foreach (Position p in Positions)
{...}
What is equivlient for MC .Net?
Thanks and regards,
drolles
Determine Open Positions for Strategy?
Re: Determine Open Positions for Strategy?
Can I please have some support here?
Please help me understand why the Positions collection does not have a definition GetEnumerator?
Thanks,
drolles
Please help me understand why the Positions collection does not have a definition GetEnumerator?
Thanks,
drolles
Last edited by drolles on 03 Jan 2013, edited 1 time in total.
Re: Determine Open Positions for Strategy?
I would have thought this would be the way to do it:
foreach (IMarketPosition x in Positions)
{
}
foreach (IMarketPosition x in Positions)
{
}
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: Determine Open Positions for Strategy?
I'm a beginner still, so I can't answer your question Drolles. However, I did found some code examples which may point you into the right direction:
Code: Select all
protected override void CalcBar()
{
if (Bars.LastBarOnChart == true && Positions.Count > 0 && alreadyPrinted == false)
{
myMeth.Print("Trades count: " + Positions.Count);
for (int i = 0; i < Positions.Count; i++)
{
myMeth.Print("i = " + i.ToString());
IMarketPosition mp = Positions[Positions.Count - 1 - i];
// For every closed trade in this position
if (mp.ClosedTrades.Count > 0)
{
for (int j = 0; j < mp.ClosedTrades.Count; j++)
{
ITrade trd = mp.ClosedTrades[j];
myMeth.Print(string.Format("EntryTime: {0}\tEntryPrice: {1}\tEntryName: {2}\tExitTime: {3}\tExitPrice: {4}\tExitName: {5}",
trd.EntryOrder.Time.ToString("dd-MM-yyyy HH:mm:ss"),
trd.EntryOrder.Price,
trd.EntryOrder.Name,
trd.ExitOrder.Time.ToString("dd-MM-yyyy HH:mm:ss"),
trd.ExitOrder.Price,
trd.ExitOrder.Name
));
}
}
// Check for open trade
if (mp.OpenTrades.Count > 0)
{
myMeth.Print("There's an open trade!");
}
}
}
}
Code: Select all
namespace PowerLanguage.Strategy
{
public class Test_HistoryOrdersLookUp : SignalObject
{
public Test_HistoryOrdersLookUp(object _ctx):base(_ctx){}
protected override void Create()
{
}
protected override void StartCalc()
{
}
bool subscribed = false;
protected override void CalcBar()
{
if (!subscribed)
{
TradeManager.TradingData.Orders.FinishChanging += new EventHandler( Orders_FinishChanging );
subscribed = true;
}
if (Bars.CurrentBar == 1)
{
//TradeManager.TradingData.Orders.ProfileFltr.CurrentValue = "Interactive Brokers";
TradeManager.TradingData.Orders.SymbolFltr.CurrentValue = "CLV2";
}
TradeManager.ProcessEvents();
}
void Orders_FinishChanging( object sender, EventArgs e )
{
TradeManager.IOrders ord = sender as TradeManager.IOrders;
foreach (TradeManager.Order o in ord.Items)
{
Output.WriteLine( "Order ID = {0}, ExecPrice = {1} ", o.ID, o.ExecPrice );
}
}
}
}
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2958 times
Re: Determine Open Positions for Strategy?
Hello Drolles,
Thank you for your suggestion. GetEnumerator for Positions collection would be added in one of the future versions of MultiCharts.Net. In the meantime please use JoshM's solution.
Thank you for your suggestion. GetEnumerator for Positions collection would be added in one of the future versions of MultiCharts.Net. In the meantime please use JoshM's solution.
Re: Determine Open Positions for Strategy?
Thanks both for the reply here.
I’m wondering if the architects had something mind for the IROListObjectEx interface. This appears to have a GetEnumerator implemented, but how should it be used in conjunction with return value from Positions of the IROList return value.
Cheers,
drolles
I’m wondering if the architects had something mind for the IROListObjectEx interface. This appears to have a GetEnumerator implemented, but how should it be used in conjunction with return value from Positions of the IROList return value.
Cheers,
drolles
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2958 times
Re: Determine Open Positions for Strategy?
IROListObjectEx interface is not yet implemeted. It will be finished in one of the future versions of MultiCharts.I’m wondering if the architects had something mind for the IROListObjectEx interface. This appears to have a GetEnumerator implemented, but how should it be used in conjunction with return value from Positions of the IROList return value.