Page 1 of 1

Possible problem with IOrderPriced.send(price, size) ?

Posted: Oct 13 2013
by MidKnight
Hi there,

Been doing some FOREX exploration over the weekend. Trying to average down a position doesn't seem to let me adjust the trade size from the current system defaults. In the strategy properties I have set trade size to 2 million with a base size of 50, 000.

Code: Select all

private IOrderPriced buyOrder;
...
...
protected override void Create()
{
buyOrder = OrderCreator.Limit(new SOrderParameters(EOrderAction.Buy, "GStat_LE"));
}
...
...
protected override void CalcBar()
{
if (StrategyInfo.MarketPosition > 0)
{
buyOrder.Send(CurrentPosition.OpenTrades[CurrentPosition.OpenTrades.Count - 1].EntryOrder.Price - 0.002, CurrentPosition.OpenLots);
}
}
This should be placing new trades with a size equal to the current openposition (doubling up), but it is not. Instead it keeps entering at the default in the strategy properties. The strategy properties screen says: "Trade size (if not specified by signal)..." But I am specifying it in the signal, no?

Hope this explains my situation OK.

Version 8.5 build 6862

With kind regards,
MK

Re: Possible problem with IOrderPriced.send(price, size) ?

Posted: Oct 16 2013
by Henry MultiŠ”harts
Here is an example how to specify the amount of contracts in the code.

Re: Possible problem with IOrderPriced.send(price, size) ?

Posted: Oct 16 2013
by MidKnight
Henry,

Isn't that code what I'm already doing? Look at my code snippet again please. I'm using Send() in the same way you are in that example.

Lets use an example of the behaviour I am seeing:

Open a long position at 1.3200 with a size of 50,000
Set a buy limit at 1.3180 with a size of currentposition.openlots (this is 50,000)
Filled at 1.3180 for a total size of 100,000 and currentposition.openlots reports this as such
Set a buy limit for 1.3160 for currentposition.openlots (this is 100,000)
etc.

What instead is happening is that each subsequent buy order is only set to 50,000 rather than the currentposition.openlots value. currentposition.openlots is reporting the right total size but for some reason send doesn't seem to be accepting it.

Why doesn't it work on Forex instrument for me? Because Forex size is an amount of dollars to transact - is this size too big? My default size in the system properties is set to 50,000 and under my code, this could easily rise to 500,000.

Re: Possible problem with IOrderPriced.send(price, size) ?  [SOLVED]

Posted: Oct 17 2013
by JoshM
Why doesn't it work on Forex instrument for me? Because Forex size is an amount of dollars to transact - is this size too big? My default size in the system properties is set to 50,000 and under my code, this could easily rise to 500,000.
Good question. It does work for me however. Perhaps you need to specify the 'Contracts.UserSpecified' property in the 'Create()' method?

=====

Image

Code:

Code: Select all

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

namespace PowerLanguage.Strategy
{
public class StrategyExample_AveragingDown : SignalObject
{
private IOrderMarket buyOrder, sellOrder;
int orderSize = 0;
int maxEntriesInPosition = 10;
int maxOrderSize = 1000;

public StrategyExample_AveragingDown(object _ctx) : base(_ctx) { }

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 StartCalc()
{
Output.Clear();
}

protected override void CalcBar()
{
// Buy if flat or already long
if ((StrategyInfo.MarketPosition > -1) && (Positions[0].OpenTrades.Count < maxEntriesInPosition))
{
orderSize = Math.Min((CurrentPosition.OpenLots == 0) ? 1 : CurrentPosition.OpenLots * 2, maxOrderSize);

Output.WriteLine("{0} - Sending order for {1} contracts.",
Bars.TimeValue.ToString("dd-MM-yy HH:mm:ss"),
orderSize);

buyOrder.Send(orderSize);
}

// Close position every 20 bars
if (Bars.CurrentBar % 20 == 0)
{
sellOrder.Send(CurrentPosition.OpenLots);
Output.WriteLine("{0} - Sending SELL order for {1} contracts.",
Bars.TimeValue.ToString("dd-MM-yy HH:mm:ss"),
CurrentPosition.OpenLots);
}
}
}
}
Output:

Code: Select all

08-10-13 07:50:00 - Sending order for 1 contracts.
08-10-13 07:55:00 - Sending order for 2 contracts.
08-10-13 08:00:00 - Sending order for 6 contracts.
08-10-13 08:05:00 - Sending order for 18 contracts.
08-10-13 08:10:00 - Sending order for 54 contracts.
08-10-13 08:15:00 - Sending order for 162 contracts.
08-10-13 08:20:00 - Sending order for 486 contracts.
08-10-13 08:25:00 - Sending order for 1000 contracts.
08-10-13 08:30:00 - Sending order for 1000 contracts.
08-10-13 08:35:00 - Sending order for 1000 contracts.
08-10-13 09:25:00 - Sending SELL order for 3729 contracts.
08-10-13 09:30:00 - Sending order for 1 contracts.
08-10-13 09:35:00 - Sending order for 2 contracts.
08-10-13 09:40:00 - Sending order for 6 contracts.
08-10-13 09:45:00 - Sending order for 18 contracts.
08-10-13 09:50:00 - Sending order for 54 contracts.
08-10-13 09:55:00 - Sending order for 162 contracts.
08-10-13 10:00:00 - Sending order for 486 contracts.
08-10-13 10:05:00 - Sending order for 1000 contracts.
08-10-13 10:10:00 - Sending order for 1000 contracts.
08-10-13 10:15:00 - Sending order for 1000 contracts.
08-10-13 11:05:00 - Sending SELL order for 3729 contracts.
08-10-13 11:10:00 - Sending order for 1 contracts.
08-10-13 11:15:00 - Sending order for 2 contracts.
08-10-13 11:20:00 - Sending order for 6 contracts.
08-10-13 11:25:00 - Sending order for 18 contracts.
08-10-13 11:30:00 - Sending order for 54 contracts.
08-10-13 11:35:00 - Sending order for 162 contracts.
08-10-13 11:40:00 - Sending order for 486 contracts.
08-10-13 11:45:00 - Sending order for 1000 contracts.
08-10-13 11:50:00 - Sending order for 1000 contracts.
08-10-13 11:55:00 - Sending order for 1000 contracts.
08-10-13 12:45:00 - Sending SELL order for 3729 contracts.
==========

You can also use the ordersize of the last entry order:

Code: Select all

tradesCountOpenPos = Positions[0].OpenTrades.Count;

// Buy if flat or already long
if ((StrategyInfo.MarketPosition > -1) && (tradesCountOpenPos < maxEntriesInPosition))
{
orderSize = (tradesCountOpenPos == 0) ? 1 : Positions[0].OpenTrades[tradesCountOpenPos - 1].EntryOrder.Contracts * 2;
orderSize = Math.Min(orderSize, maxOrderSize);

Output.WriteLine("{0} - Sending order for {1} contracts.",
Bars.TimeValue.ToString("dd-MM-yy HH:mm:ss"),
orderSize);

buyOrder.Send(orderSize);
}
Gives:

Code: Select all

17-10-13 04:40:00 - Sending order for 1 contracts.
17-10-13 04:45:00 - Sending order for 2 contracts.
17-10-13 04:50:00 - Sending order for 4 contracts.
17-10-13 04:55:00 - Sending order for 8 contracts.
17-10-13 05:00:00 - Sending order for 16 contracts.
17-10-13 05:05:00 - Sending order for 32 contracts.
17-10-13 05:10:00 - Sending order for 64 contracts.
17-10-13 05:15:00 - Sending order for 128 contracts.
17-10-13 05:20:00 - Sending order for 256 contracts.
17-10-13 05:25:00 - Sending order for 512 contracts.
17-10-13 06:15:00 - Sending SELL order for 1023 contracts.

Re: Possible problem with IOrderPriced.send(price, size) ?

Posted: Oct 17 2013
by JoshM
Almost forget, the Strategy Properties (though I doubt they are that relevant):

Image

@Henry or @MultiCharts Support: is it possible to retrieve the 'allow up to x entry orders in the same position' from the code?

Re: Possible problem with IOrderPriced.send(price, size) ?

Posted: Oct 17 2013
by MidKnight
Thanks JoshM - That was the problem! I didn't have Contracts.UserSpecified set. Your C# skills are excellent - thank you for the answer.

With kind regards,
MK

Re: Possible problem with IOrderPriced.send(price, size) ?

Posted: Oct 17 2013
by JoshM
Thanks JoshM - That was the problem! I didn't have Contracts.UserSpecified set. Your C# skills are excellent - thank you for the answer.
I'm still a beginner so I would not call it 'excellent' myself.

I'm glad I could help, good luck! :)

Re: Possible problem with IOrderPriced.send(price, size) ?

Posted: Oct 17 2013
by Henry MultiŠ”harts
is it possible to retrieve the 'allow up to x entry orders in the same position' from the code?
Unfortunately there is no way to access this option from the code at the moment. You may want to submit a feature request to the Project Management of our web site to have your request evaluated: https://www.multicharts.com/pm/