Position management

Questions about MultiCharts .NET and user contributed studies.
mouceu4
Posts: 5
Joined: 30 Jun 2013
Has thanked: 1 time

Position management

Postby mouceu4 » 30 Jun 2013

Hi!

Could you help me to solve the position sizing problem?
For instance, I want to use 50% of my estimated balance to acquire stock N at market.

How can I do it?
And is it possible to use UserSpecified with IOrderMarket OrderCreator.MarketNextBar?


Here's the example of a simple price channel strategy:
using PowerLanguage.Function;
using System;

namespace PowerLanguage.Strategy
{
[IOGMode(IOGMode.Disabled)]
public class PriceChannelSimple : SignalObject
{
private HighestFC m_HighestFC;

private LowestFC m_LowestFC;

private IOrderPriced m_Entry;

private IOrderPriced m_Exit;



public PriceChannelSimple(object ctx) :
base(ctx)
{
LengthEntry = 20;
LengthExit = 20;

}

[Input]
public int LengthEntry { get; set; }

[Input]
public int LengthExit { get; set; }

protected override void Create()
{


m_HighestFC = new HighestFC(this);
m_LowestFC = new LowestFC(this);

m_Entry = OrderCreator.Limit(new SOrderParameters(Contracts.UserSpecified, EOrderAction.Buy));
m_Exit = OrderCreator.Limit(new SOrderParameters(Contracts.UserSpecified, EOrderAction.Sell, OrderExit.FromAll));


}

protected override void StartCalc()
{
m_HighestFC.pricevalue = Bars.High;
m_HighestFC.len = LengthEntry;

m_LowestFC.pricevalue = Bars.Low;
m_LowestFC.len = LengthEntry;

}



protected override void CalcBar()
{
//Estimated balance
double equity = InitialCapital + Portfolio.NetProfit - Portfolio.InvestedCapital;

//Number of contracts
int size = (int)( equity*0.5/Bars.Close[0]);

if(StrategyInfo.MarketPosition == 0)
{
//Is there any way to use MarketNextBar orders with UserSpecifiedContracts?
if (Bars.Close[2] < m_HighestFC[2] && Bars.Close[1] > m_HighestFC[1])
{
m_Entry.Send(Bars.Open[0], size);
}
}
if(StrategyInfo.MarketPosition != 0)
{
if(Bars.Close[2] > m_LowestFC[2] && Bars.Close[1] < m_LowestFC[1])
{
m_Exit.Send(Bars.Open[0]);
}
}
}
}
}

Thank you in advance!

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

Re: Position management

Postby Henry MultiСharts » 01 Jul 2013

Hello mouceu4,

Were you unable to achieve your goal with the code you have created?
What is the exact difficulty you have with it?
And is it possible to use UserSpecified with IOrderMarket OrderCreator.MarketNextBar?
Yes, that is possible to do that. Here is an example how to do that. If you do not specify the amount to buy/sell in the code then the value specified in the Properties tab of the Strategy Properties is used.

mouceu4
Posts: 5
Joined: 30 Jun 2013
Has thanked: 1 time

Re: Position management

Postby mouceu4 » 01 Jul 2013

Henry, thnanks for the prompt reply.
As far as I understand the problem refers to Porfolio.NetProfit function.
I've attached the text of the exception.

I get this exception every time I try to attach the signal to any chart.

Thank you!
Attachments
exception.png
(21.5 KiB) Downloaded 1053 times

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

Re: Position management

Postby Henry MultiСharts » 01 Jul 2013

This message appears because you are trying to access Portfolo Backtester functionality in MultiCharts.

Code: Select all

double equity = InitialCapital + Portfolio.NetProfit - Portfolio.InvestedCapital;
Do not use Portfolio. when using the code on a chart in MultiCharts.

mouceu4
Posts: 5
Joined: 30 Jun 2013
Has thanked: 1 time

Re: Position management

Postby mouceu4 » 02 Jul 2013

I see, now it's clear!

Thanks Henry!


Return to “MultiCharts .NET”