Close STOP order inside a candle

Questions about MultiCharts .NET and user contributed studies.
User avatar
svopex
Posts: 74
Joined: 16 Oct 2013
Has thanked: 7 times
Been thanked: 5 times
Contact:

Close STOP order inside a candle

Postby svopex » 11 Nov 2015

Hello,

exist way, how I close stop order inside a candle?

In this example they have close position inside candle:
http://www.tradingcode.net/multicharts- ... ior-close/

If I create stop order by this code:

Code: Select all

protected override void Create()
{
orderStop = OrderCreator.Stop(new SOrderParameters(Contracts.Default, EOrderAction.Buy));
}

protected override void CalcBar()
{
orderStop.Send(LongBreakout);
}
Exists way, how I close unfilled stop order inside candle (by ExecControl.RecalcLastBarAfter(...) and etc)?

Why? I have session without night seance and when create stop order on penultimate candle, this stop order is not closed at the close of the session and this stop order is active whole night session.

User avatar
svopex
Posts: 74
Joined: 16 Oct 2013
Has thanked: 7 times
Been thanked: 5 times
Contact:

Re: Close STOP order inside a candle

Postby svopex » 12 Nov 2015

Hello, I solve it:

SOLUTION1 - don't open stop order at penultimate candle:

Code: Select all

if (time <> CalcTime(SessionEndTime(0, 1), -1 * BarInterval)) then
begin
buy next bar at close + 30 stop;
end
SOLUTION2 - don't open stop order at one minute before close session. Intrabar order generation must be enabled.

Code: Select all

[intrabarordergeneration = true]
if CurrentTime < CalcTime(SessionEndTime(0, 1), -1) then
begin
buy next bar at close[1] + 30 stop;
end
Sorry code is in easylanguage...
Last edited by svopex on 13 Nov 2015, edited 4 times in total.

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

Re: Close STOP order inside a candle

Postby JoshM » 13 Nov 2015

exist way, how I close stop order inside a candle?

In this example they have close position inside candle:
http://www.tradingcode.net/multicharts- ... ior-close/

If I create stop order by this code:

Code: Select all

protected override void Create()
{
orderStop = OrderCreator.Stop(new SOrderParameters(Contracts.Default, EOrderAction.Buy));
}

protected override void CalcBar()
{
orderStop.Send(LongBreakout);
}
You're missing two things in this code snippet that are discussed in the article you reference:
Two things added to this example are important for exiting a position prior to the close. First, intra-bar order generation is turned on (line 9). This enables the strategy to send orders during the bar instead of just at the close of the bar. This prevents the issue where the session close happens at the same time as the bar close.

Second, by forcing the strategy to be recalculated at least once every 15 seconds (line 57), we ensure that our exit order is also send when the instrument is (relatively) illiquid and there are no incoming ticks.
Exists way, how I close unfilled stop order inside candle (by ExecControl.RecalcLastBarAfter(...) and etc)?
If you use managed orders, then you don't need to close unfilled orders yourself -- as soon as you stop resubmitting the order, the unfilled stop order will be closed automatically.
Why? I have session without night seance and when create stop order on penultimate candle, this stop order is not closed at the close of the session and this stop order is active whole night session.
If you stop resubmitting the stop order after the close of trading, then the stop order is cancelled and not active for the whole night session.

User avatar
svopex
Posts: 74
Joined: 16 Oct 2013
Has thanked: 7 times
Been thanked: 5 times
Contact:

Re: Close STOP order inside a candle

Postby svopex » 13 Nov 2015

Hello, thank, you write:
If you stop resubmitting the stop order after the close of trading, then the stop order is cancelled and not active for the whole night session.
If I have session in from 8:30am to 3:00pm, and when I create stop order at close of penultimate candle, stop order stay in stock after session close, by my opinion. Is it not true?

If found two solutions, that you can see above (SOLUTION 1 and SOLUTION2 in EasyLanguage, but in C# it would be similar).

This code caused, that stop order stays in stock at night seance:

Code: Select all

protected override void Create()
{
orderStop = OrderCreator.Stop(new SOrderParameters(Contracts.Default, EOrderAction.Buy));
}

protected override void CalcBar()
{
orderStop.Send(LongBreakout);
}
Please modify the code, if you know better solution.

Thank Petr

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

Re: Close STOP order inside a candle

Postby JoshM » 13 Nov 2015

If I have session in from 8:30am to 3:00pm, and when I create stop order at close of penultimate candle, stop order stay in stock after session close, by my opinion. Is it not true?
That's a good question. If you submit your stop order at the very last tick of the day, I do not know whether it keeps alive after the session close. I think it does not, because in this order engine thread it was suggested that pending orders are cancelled on bar close (and thus need to be resubmitted).

But this is something for MultiCharts Support to answer, given the possible strategy auto-trading settings and how MultiCharts communicates with the broker.
Please modify the code, if you know better solution.
I think you'll learn more if you try to modify the code yourself first. Then if you need help, please post the full code. That saves others time having to recreate a signal based on the snippet you posted.

User avatar
svopex
Posts: 74
Joined: 16 Oct 2013
Has thanked: 7 times
Been thanked: 5 times
Contact:

Re: Close STOP order inside a candle

Postby svopex » 13 Nov 2015

Yes, I test it with Oanda.
I am sorry for EasyLanguage code in .NET section, but the principle is the same in C#.
I use Oanda, Nasdaq (US Nas 100), session in Multichart (Chicago time) I set from 8:30am to 3:00pm.
Stock closes in 3:15pm (Chicago time).

If I use this code, stop order is active in night seance:

Code: Select all

buy next bar at close + 30 stop;
SOLUTION1 - don't open stop order at penultimate candle:

Code: Select all

if (time <> CalcTime(SessionEndTime(0, 1), -1 * BarInterval)) then
begin
buy next bar at close + 30 stop;
end
SOLUTION2 - don't open stop order at one minute before close session. Intrabar order generation must be enabled!

Code: Select all

[intrabarordergeneration = true]
if CurrentTime < CalcTime(SessionEndTime(0, 1), -1) then
begin
buy next bar at close[1] + 30 stop;
end
i test it, both solutions works.

I have only one question - is exist better solution?


Return to “MultiCharts .NET”