create order outside create function  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
gvandenbosch
Posts: 30
Joined: 24 Oct 2013
Has thanked: 9 times
Been thanked: 3 times

create order outside create function

Postby gvandenbosch » 24 Oct 2013

Hi,

I want to create an order with the volume value based on user input.

However if I try to create the order outside of the create function I get an error that it is only allowed to create an order in the construct function.

The problem is that when the construct function is executed the signal is not formatted yet so I don't have user input yet to create an order.

Is their an alternative way of doing this or a workaround?

Cheers,
Gerard

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

Re: create order outside create function  [SOLVED]

Postby JoshM » 24 Oct 2013

Is their an alternative way of doing this or a workaround?
You can also specify the position size as an input, and use that input when you send the order. 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 = 10; // default value
}

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

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

if (Bars.CurrentBar % 20 == 0)
{
sellOrder.Send(PositionSize);
}
}
}
}
Keep in mind that you'll need to use 'Contracts.UserSpecified' and not the default 'Contracts.Default' in the Create() method.

I don't think there's another way, since it seems you either have to use 'Contracts.UserSpecified' or 'Contracts.Default' when creating the order.

gvandenbosch
Posts: 30
Joined: 24 Oct 2013
Has thanked: 9 times
Been thanked: 3 times

Re: create order outside create function

Postby gvandenbosch » 25 Oct 2013

Thanks,

That did the trick, I already used userspecified but I thought you had to pass the value when creating the order.

I have it working now, however not very efficient yet because have to create all orders up front and maybe not using them all.

Cheers,
Gerard


Return to “MultiCharts .NET”