Determine Open Positions for Strategy?

Questions about MultiCharts .NET and user contributed studies.
drolles
Posts: 50
Joined: 03 Dec 2012
Has thanked: 4 times

Determine Open Positions for Strategy?

Postby drolles » 28 Dec 2012

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

drolles
Posts: 50
Joined: 03 Dec 2012
Has thanked: 4 times

Re: Determine Open Positions for Strategy?

Postby drolles » 03 Jan 2013

Can I please have some support here?

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.

drolles
Posts: 50
Joined: 03 Dec 2012
Has thanked: 4 times

Re: Determine Open Positions for Strategy?

Postby drolles » 03 Jan 2013

I would have thought this would be the way to do it:

foreach (IMarketPosition x in Positions)
{


}

User avatar
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?

Postby JoshM » 04 Jan 2013

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 );
}
}
}
}

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

Re: Determine Open Positions for Strategy?

Postby Henry MultiСharts » 04 Jan 2013

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.

drolles
Posts: 50
Joined: 03 Dec 2012
Has thanked: 4 times

Re: Determine Open Positions for Strategy?

Postby drolles » 04 Jan 2013

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

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

Re: Determine Open Positions for Strategy?

Postby Henry MultiСharts » 09 Jan 2013

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.
IROListObjectEx interface is not yet implemeted. It will be finished in one of the future versions of MultiCharts.


Return to “MultiCharts .NET”