(...)
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?