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

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

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

Postby MidKnight » 13 Oct 2013

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

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

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

Postby Henry MultiСharts » 16 Oct 2013

Here is an example how to specify the amount of contracts in the code.

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

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

Postby MidKnight » 16 Oct 2013

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.

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

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

Postby JoshM » 17 Oct 2013

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.
Attachments
scr.17-10-2013 08.16.24.png
(14.64 KiB) Downloaded 1036 times

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

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

Postby JoshM » 17 Oct 2013

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?
Attachments
scr.17-10-2013 08.50.16.png
(38.69 KiB) Downloaded 1097 times

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

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

Postby MidKnight » 17 Oct 2013

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

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

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

Postby JoshM » 17 Oct 2013

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! :)

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

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

Postby Henry MultiСharts » 17 Oct 2013

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/


Return to “MultiCharts .NET”