ATCenterProxy.interop Limit Order Cancel.  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
lstman
Posts: 18
Joined: 26 Feb 2013
Has thanked: 2 times
Been thanked: 1 time

ATCenterProxy.interop Limit Order Cancel.

Postby lstman » 12 Nov 2013

Hi

my strategy puts orders from "ATCenterProxy.interop".

In this case , if I make orders by "Limit order", I can cancel market orders as obsolete if not filled
within 10 seconds?

I want to increase "cancel market orders after 10 seconds" into the below code.

Code: Select all


S1570op.category = MTPA_OrdrCtgry.eMTPA_OC_Limit;
S1570op.action = MTPA_OrdrActn.eMTPA_OA_Buy;
S1570op.contracts = (int)T_Unit;
S1570op.limit_price = Bids_1570;
PlaceOrder(S1570, S1570Symbol, S1570Account, S1570op, S1570Exchange);

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

Re: ATCenterProxy.interop Limit Order Cancel.

Postby Henry MultiСharts » 13 Nov 2013

Hello lstman,

Your inquiry is being analyzed.

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

Re: ATCenterProxy.interop Limit Order Cancel.

Postby Henry MultiСharts » 14 Nov 2013

lstman, "cancel market orders as obsolete if not filled within N seconds" can be setup through MultiCharts GUI only. It is not accessible from the code. This option can be applied only to orders generated by MultiCharts in standard auto trading mode.
"Unmanaged" orders are not affected by this option and should be managed by your code.

lstman
Posts: 18
Joined: 26 Feb 2013
Has thanked: 2 times
Been thanked: 1 time

Re: ATCenterProxy.interop Limit Order Cancel.

Postby lstman » 15 Nov 2013

About Multicharts.Net programming guide.
4.7.5.3 Trading Functionality. TradingProfiles.

>void CancelOrder(int order_id);
> a) One Cancel Others means that the cancellation or execution of one order cancels all other orders.

This mean....
Strategy will cancel one order(the number of order_id) only, or all other orders without the number of order_id?

I want to cancel ALL orders without final status orders, before I put new order to TWS.
The below code...
System does not work well.
Sometime, TWS received multiple orders.
(System did not cancel all order, before new order)

Code: Select all

ITradingProfile S1570;

protected void SubmitOrder_Delete(String Profile, String Symbol)
{
IEnumerable<PowerLanguage.TradeManager.Order> ords = GetOrderList(Profile, Symbol, ETM_OrderState.eTM_OS_Submitted);
int _id = 0;

foreach (TradeManager.Order o in ords)
{
if(o.State == ETM_OrderState.eTM_OS_Submitted)
{
_id = o.OrderID;
S1570.CancelOrder(_id);
}
}
}

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

Re: ATCenterProxy.interop Limit Order Cancel.

Postby Henry MultiСharts » 15 Nov 2013

lstman, what exact version and build number of MultiCharts are you running? (in MultiCharts go to Help tab-> About)

lstman
Posts: 18
Joined: 26 Feb 2013
Has thanked: 2 times
Been thanked: 1 time

Re: ATCenterProxy.interop Limit Order Cancel.

Postby lstman » 15 Nov 2013

Hi Henry
Thanks for your kindly support.

And my version is the below.
MultiCharts .NET64 SE Version 8.7 Release (Build 7631)

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

Re: ATCenterProxy.interop Limit Order Cancel.

Postby Henry MultiСharts » 19 Nov 2013

lstman, your cancel command is incorrect. The order cannot be cancelled based on the broker order ID. You need to transfer the order ID returned by PlaceOrder into CancelOrder in order to cancel the order.

lstman
Posts: 18
Joined: 26 Feb 2013
Has thanked: 2 times
Been thanked: 1 time

Re: ATCenterProxy.interop Limit Order Cancel.

Postby lstman » 19 Nov 2013

Hi Henry

OrderID(IOrders collection/ public struct order) can not cancel order?
(this is not BrokerID, I think...)

If possible, please advise simple code.

B.RGDS
lstman
Attachments
WS000058.JPG
(11.63 KiB) Downloaded 1005 times

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

Re: ATCenterProxy.interop Limit Order Cancel.  [SOLVED]

Postby Henry MultiСharts » 20 Nov 2013

Here is a sample code:

Code: Select all

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

namespace PowerLanguage.Strategy
{
public class Test_TradeManager_5 : SignalObject
{
public Test_TradeManager_5(object _ctx):base(_ctx){}
private IOrderMarket buy_order;
protected override void Create()
{
}

protected override void StartCalc()
{
}

protected override void CalcBar()
{
foreach (TradeManager.ITradingProfile p in TradeManager.TradingProfiles)
{
if (p.PluginName.Contains("Interactive Brokers") && p.ConnectionState == ETM_ConnectionChanged.eTM_CC_Connected)
{
Output.WriteLine("Start");
MCSymbolInfo msymbInfo = new MCSymbolInfo();
msymbInfo.symbol.BigPointValue = Bars.Info.BigPointValue;
msymbInfo.symbol.MinMove = (int)Bars.Info.MinMove;
msymbInfo.symbol.PriceScale = Bars.Info.PriceScale;
msymbInfo.symbol.SymbolCategory = MTPA_MCSymbolCategories.eMTPA_MCSC_FUTURE;
msymbInfo.symbol.SymbolDescription = Bars.Info.Description; /*"USD DEC13 ES Futures ESZ3 MULT:50";*/
msymbInfo.data_feed = "Interactive Brokers";
msymbInfo.symbol.SymbolExchange = "GLOBEX";
msymbInfo.symbol.SymbolExpiry = Convert.ToDateTime("20.12.2013");
msymbInfo.symbol.SymbolName = Bars.Info.Name;
msymbInfo.symbol.SymbolRoot = "ES";
p.CurrentSymbol = msymbInfo;
OrderParams _pparam = new OrderParams();
_pparam.action = MTPA_OrdrActn.eMTPA_OA_Buy;

double _oPrice = Bars.LowValue - 0.5;


/*MTPA_SOrder3 _ord = new MTPA_SOrder3();
_ord.Action = MTPA_OrdrActn.eMTPA_OA_Buy;
_ord.Category = MTPA_OrdrCtgry.eMTPA_OC_Limit;
_ord.LimitPrice = Bars.LowValue;
_ord.Quantity = 10;
_ord.TIFType = MTPA_OrdrTimeInForce.eMTPA_TIF_DAY;
_ord.Type = MTPA_OrdrType.eMTPA_OT_Entry;*/

//_pparam.AsMTPA = _ord;
_pparam.category = MTPA_OrdrCtgry.eMTPA_OC_Limit;
_pparam.contracts = 10;
_pparam.tif = MTPA_OrdrTimeInForce.eMTPA_TIF_DAY;
_pparam.limit_price = _oPrice;

int _id = p.PlaceOrder(_pparam);
System.Threading.Thread.Sleep(100);
p.CancelOrder(_id);

Output.WriteLine("Success!");
}
}
}
}
}

lstman
Posts: 18
Joined: 26 Feb 2013
Has thanked: 2 times
Been thanked: 1 time

Re: ATCenterProxy.interop Limit Order Cancel.

Postby lstman » 20 Nov 2013

This is a very nice idea, and very cool also.

Thanks, it works!

lstman
Posts: 18
Joined: 26 Feb 2013
Has thanked: 2 times
Been thanked: 1 time

Re: ATCenterProxy.interop Limit Order Cancel.

Postby lstman » 16 Jan 2014

Hi

I have one more question for your sample code.

>int _id = p.PlaceOrder(_pparam);

"_id" is OrderID?

I want to get " ETM_OrderState", so I try the below code.
But, not good...

Code: Select all

{
int _id = p.PlaceOrder(_pparam);

IEnumerable<PowerLanguage.TradeManager.Order> ord = GetOrderList(_id);

foreach (TradeManager.Order o in ord)
{
if(o.OrderID == _id)
{
int _state = (int)o.State; // <- ETM OrderState

//Output.WriteLine( "Order Profile = {0}, Order ID = {1} , ExecPrice = {2},
//Generated = {3}, Filled\\Canceled = {4}, State = {5} ",
//o.Profile, o.OrderID, o.ExecPrice, o.GeneratedDT, o.FinalDT.Value, _state);

break;
}
}
}

protected IEnumerable<PowerLanguage.TradeManager.Order> GetOrderList(int id)
{
TradeManager.ProcessEvents();
return from o in TradeManager.TradingData.Orders.Items
where (o.OrderID == id)
select o;
}

If the above code is correct, I can get ETM OrderState(_state),I think...

Please advise.

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

Re: ATCenterProxy.interop Limit Order Cancel.

Postby Henry MultiСharts » 16 Jan 2014

Hi

I have one more question for your sample code.

>int _id = p.PlaceOrder(_pparam);

"_id" is OrderID?

I want to get " ETM_OrderState", so I try the below code.
But, not good...

If the above code is correct, I can get ETM OrderState(_state),I think...

Please advise.
lstman, this is an internal ID, not the broker order ID.

lstman
Posts: 18
Joined: 26 Feb 2013
Has thanked: 2 times
Been thanked: 1 time

Re: ATCenterProxy.interop Limit Order Cancel.

Postby lstman » 16 Jan 2014

Hi Henry.

Thanks for your kindly support.

And, your mean....

this internal ID is different from OrderID or BrokerID?

I think it's same number as OrderID...
Attachments
OrderID.JPG
(44.98 KiB) Downloaded 976 times

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

Re: ATCenterProxy.interop Limit Order Cancel.

Postby Henry MultiСharts » 16 Jan 2014

internal ID = OrderID, this is not = BrokerID


Return to “MultiCharts .NET”