Historical Order Entry Strategy Doesn't Allow Quantity

Questions about MultiCharts .NET and user contributed studies.
MidKnight
Posts: 343
Joined: 12 Aug 2012
Has thanked: 123 times
Been thanked: 56 times

Historical Order Entry Strategy Doesn't Allow Quantity

Postby MidKnight » 25 Oct 2013

Hi there,

In exploring the MC.net supplied Historical Entry Strategy, there is a user defined parameter of Quantity that appears it should be the trade size. However, it gets ignored and the default is used.

I looked at the code, is the problem in the Create() when OrderCreator is setting up the orders with Contracts.Default instead of Contracts.UserSpecified?

Code: Select all

m_StopBuy = OrderCreator.Stop(new SOrderParameters(Contracts.Default, "Buy", EOrderAction.Buy));
m_LimitBuy = OrderCreator.Limit(new SOrderParameters(Contracts.Default, "Buy#1", EOrderAction.Buy));
m_StopShort = OrderCreator.Stop(new SOrderParameters(Contracts.Default, "Short", EOrderAction.SellShort));
m_LimitShort =
OrderCreator.Limit(new SOrderParameters(Contracts.Default, "Short#1", EOrderAction.SellShort));
Or is there some trick to get it so it uses my entered quantity in the parameters?

With kind regards,
MK

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

Re: Historical Order Entry Strategy Doesn't Allow Quantity

Postby JoshM » 25 Oct 2013

(...)
I looked at the code, is the problem in the Create() when OrderCreator is setting up the orders with Contracts.Default instead of Contracts.UserSpecified?

(...)

Or is there some trick to get it so it uses my entered quantity in the parameters?
You can use the 'CreateUserSpecified()' method to specify the number of contracts in the Create() method. That method accepts an integer, so if you have an Input integer, you can pass that into that method (see below).

For example:

Code: Select all

using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;
using ATCenterProxy.interop;

namespace PowerLanguage.Strategy
{
public class Example_TestStrategy : SignalObject
{
private IOrderMarket buyOrder, sellOrder;

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

public Example_TestStrategy(object _ctx)
: base(_ctx)
{
PositionSize = 5; // default value
}

protected override void Create()
{
buyOrder = OrderCreator.MarketNextBar(new SOrderParameters(
Contracts.CreateUserSpecified(PositionSize), EOrderAction.Buy));
sellOrder = OrderCreator.MarketNextBar(new SOrderParameters(
Contracts.CreateUserSpecified(PositionSize), EOrderAction.Sell));
}

protected override void CalcBar()
{
if ((StrategyInfo.MarketPosition == 0) && (Bars.CurrentBar % 5 == 0))
{
buyOrder.Send();
}

if ((StrategyInfo.MarketPosition > 0) && (Bars.CurrentBar % 20 == 0))
{
sellOrder.Send();
}
}
}
}
(Thanks by the way for this question, since by answering it I learned something new.)

Edit: the drawback of the above example is that you can't change the order size after having applied the strategy to a chart, since the Create() method is only called when applying the strategy to a chart.

MC Support, can we also specify the order quantity of an order in the StartCalc() method?

MidKnight
Posts: 343
Joined: 12 Aug 2012
Has thanked: 123 times
Been thanked: 56 times

Re: Historical Order Entry Strategy Doesn't Allow Quantity

Postby MidKnight » 25 Oct 2013

G'day JoshM,

Thanks for the reply. My post was mainly to raise the issue with MC.net staff since this is one of their supplied strategies. However, I didn't know about Contracts.CreateUserSpecified() so thank you!

But why not just specify the quantity in the Send() after creating them with Contracts.UserSpecified set?

With kind regards,
MK

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

Re: Historical Order Entry Strategy Doesn't Allow Quantity

Postby Henry MultiСharts » 25 Oct 2013

I looked at the code, is the problem in the Create() when OrderCreator is setting up the orders with Contracts.Default instead of Contracts.UserSpecified?
Hello MidKnight,

Yes, that is the issue. The code should be:

Code: Select all

m_StopBuy = OrderCreator.Stop(new SOrderParameters(Contracts.UserSpecified, "Buy", EOrderAction.Buy));
m_LimitBuy = OrderCreator.Limit(new SOrderParameters(Contracts.UserSpecified, "Buy#1", EOrderAction.Buy));
m_StopShort = OrderCreator.Stop(new SOrderParameters(Contracts.UserSpecified, "Short", EOrderAction.SellShort));
m_LimitShort =
OrderCreator.Limit(new SOrderParameters(Contracts.UserSpecified, "Short#1", EOrderAction.SellShort));
We will fix the prebuilt code in the next version.
But why not just specify the quantity in the Send() after creating them with Contracts.UserSpecified set?
You can do that. That is what Josh has shown in his other code.
Please also keep in mind that IOrderMarket.Send Method has multiple overload methods (description from MC .Net 8.8 beta 2):
  • void Send()
    Generation of an order with 'num_lots' number of lots.
  • void Send(int)
    Generation of an order with new order name.
  • void Send(string)
    Generation of an order with 'num_lots' number of lots.
  • void Send(string,int)
Attached is another example.
Attachments
send_market.pln
(1.94 KiB) Downloaded 528 times


Return to “MultiCharts .NET”