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!