I have this code (simplified):
protected override void Create()
{
…
order = OrderCreator.Stop(new SOrderParameters(Contracts.Default, EOrderAction.Buy));
…
}
…
if (StrategyInfo.MarketPosition == 0)
{
order.Send(LongBreakout);
}
How I by program code close pending Stop order?
Thank Petr
How I close stop pending order by program code?
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: How I close stop pending order by program code?
Stop orders are cancelled when you don't resubmit them. Also see this thread.How I by program code close pending Stop order?
Re: How I close stop pending order by program code?
Ok.
But use this session (9:45-16:15): And this code (simplification):
…
protected override void Create()
{
…
order = OrderCreator.Stop(new SOrderParameters(Contracts.Default, EOrderAction.Buy));
…
}
…
if (StrategyInfo.MarketPosition == 0)
{
order.Send(LongBreakout);
}
…
i have next problem (market position is 0).
Stop order is active after 16:15 still, and I don’t know why.
By my opinion should be stop order active from xxx to 16:14:59.999, here should be closed and reopen at 9:45 of the next day
(next candle after 16:00 by session is on the next day in 9:45).
But stop order is not canceled in 16:15.
Stop order cancel when exchange closed (at 18:00).
And in 9:45 order will be go to pending state, it's ok.
Petr
But use this session (9:45-16:15): And this code (simplification):
…
protected override void Create()
{
…
order = OrderCreator.Stop(new SOrderParameters(Contracts.Default, EOrderAction.Buy));
…
}
…
if (StrategyInfo.MarketPosition == 0)
{
order.Send(LongBreakout);
}
…
i have next problem (market position is 0).
Stop order is active after 16:15 still, and I don’t know why.
By my opinion should be stop order active from xxx to 16:14:59.999, here should be closed and reopen at 9:45 of the next day
(next candle after 16:00 by session is on the next day in 9:45).
But stop order is not canceled in 16:15.
Stop order cancel when exchange closed (at 18:00).
And in 9:45 order will be go to pending state, it's ok.
Petr
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: How I close stop pending order by program code?
Then you need to stop resubmitting the stop order prior to 16:14:59.999, with, for example, not resubmitting the stop order in the 10 seconds prior to the session close.(...)
By my opinion should be stop order active from xxx to 16:14:59.999, here should be closed and reopen at 9:45 of the next day
(next candle after 16:00 by session is on the next day in 9:45).
But stop order is not canceled in 16:15.
Stop order cancel when exchange closed (at 18:00).
And in 9:45 order will be go to pending state, it's ok.
Otherwise, if you send a stop order on the last tick of your session, there is no possibility to cancel the order after that last tick for the session, since the market would have closed by then (according to your session settings) and the CalcBar() method is not called any more.
You can try to use ExecControl.RecalcLastBarAfter to force a recalculation of your script after the 16:15 session close and to cancel the stop loss order prior to the actual close at 18:00, but keep in mind that the price bars won't be updated with fresh prices any more if the session close has been reached, so your strategy might make decisions based on old data in this case.
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2957 times
Re: How I close stop pending order by program code?
svopex, check this code to learn how to close the position at specified time. You can also adjust this code to cancel your orders at specified time.
Re: How I close stop pending order by program code?
JoshM write:
Then you need to stop resubmitting the stop order prior to 16:14:59.999, with, for example, not resubmitting the stop order in the 10 seconds prior to the session close.
I use this code, but don't work...
Does anyone know why?
Then you need to stop resubmitting the stop order prior to 16:14:59.999, with, for example, not resubmitting the stop order in the 10 seconds prior to the session close.
I use this code, but don't work...
Does anyone know why?
- …
protected override void Create()
{
…
order = OrderCreator.Stop(new SOrderParameters(Contracts.Default, EOrderAction.Buy));
…
}
…
protected override void CalcBar()
{
...
const int closeExchangeInterval = 3;
TimeSpan ts = Bars.Sessions[0].EndTime - Bars.StatusLine.Time.TimeOfDay;
...
if (
(ts.TotalMinutes > closeExchangeInterval || ts.TotalMinutes < -closeExchangeInterval)
&& StrategyInfo.MarketPosition == 0)
{
order.Send(LongBreakout);
}
…
}
Re: How I close stop pending order by program code?
This is still a mystery to me.
In the Multicharts.NET - ProgrammingGuide - v1.0 is written:
Calculation upon Close of each bar and filling of the generated orders collection on the next bar.
If I have close session on 16:15 and open in the next day 9:30,
stop order should be filled on the open 16:00 and after it on the open 9:30.
On the 16:15 candle does not render, therefore should be not open candle, but is.
In the Multicharts.NET - ProgrammingGuide - v1.0 is written:
Calculation upon Close of each bar and filling of the generated orders collection on the next bar.
If I have close session on 16:15 and open in the next day 9:30,
stop order should be filled on the open 16:00 and after it on the open 9:30.
On the 16:15 candle does not render, therefore should be not open candle, but is.
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2957 times
Re: How I close stop pending order by program code?
Hello svopex,
Have you ensured this condition is vald?
Have you ensured this condition is vald?
Have you tried using a simple condition - if current time is inside the specified "begin trading time" and "end trading time" (like if (time>=930 and time<1600) then begin) interval then execute trading logic?(ts.TotalMinutes > closeExchangeInterval || ts.TotalMinutes < -closeExchangeInterval)&& StrategyInfo.MarketPosition == 0)
Re: How I close stop pending order by program code?
take a look at the attached code;
It can be used to cancel open orders after a specific time.
It may work for what you need... (v9 RC)
Note: not tested live yet and I'm not sure if it works on "managed" trades...
It can be used to cancel open orders after a specific time.
It may work for what you need... (v9 RC)
Note: not tested live yet and I'm not sure if it works on "managed" trades...
- Attachments
-
- killOrders.pln
- (2.03 KiB) Downloaded 400 times