Relation between stopPrice and limitPrice

Questions about MultiCharts .NET and user contributed studies.
chi jeongki
Posts: 39
Joined: 29 Nov 2007
Has thanked: 8 times
Been thanked: 2 times

Relation between stopPrice and limitPrice

Postby chi jeongki » 15 Jun 2017

I have begun learning MC.NET c# program.

In buy order, if limitPrice < stopPrice, then no buy order is fullfilled.
In sellshort order, if stopPrice < limitPrice, then no sellshort order is fullfilled.

It is my understanding of StopLimit order.

But in backtesting, I found one order is fullfilled on conditions above, both in buy ordr and shellshort order.
Is the behavior of MC.NET on such a condition undefined? So we should avoid such conditions in our program?

sellshort order test signal: set position limit to 1000

public class _s_StopLimit_sell : SignalObject
{
public _s_StopLimit_sell(object _ctx) : base(_ctx) { }
private IOrderStopLimit sellshort_order;
[Input]
public double stopPrice { get; set; }
[Input]
public double limitPrice { get; set; }
protected override void Create()
{
sellshort_order = OrderCreator.StopLimit(new SOrderParameters(Contracts.Default, EOrderAction.SellShort));
stopPrice = 0.77;
limitPrice = 0.80;
}
protected override void StartCalc()
{
}
protected override void CalcBar()
{
sellshort_order.Send(stopPrice, limitPrice);
}

stopPrice < limitPrice : ??
1.png
(76.32 KiB) Downloaded 907 times
stopPrice >= limitPrice : OK
2.png
(83.53 KiB) Downloaded 907 times

User avatar
Angelina MultiСharts
Posts: 260
Joined: 28 Dec 2016
Has thanked: 28 times
Been thanked: 66 times

Re: Relation between stopPrice and limitPrice

Postby Angelina MultiСharts » 20 Jun 2017

Hello chi jeongki,

Your inquiry is analyzed. I will get back to you with the answer.

User avatar
Angelina MultiСharts
Posts: 260
Joined: 28 Dec 2016
Has thanked: 28 times
Been thanked: 66 times

Re: Relation between stopPrice and limitPrice

Postby Angelina MultiСharts » 22 Jun 2017

In buy order, if limitPrice < stopPrice, then no buy order is fullfilled.
In sellshort order, if stopPrice < limitPrice, then no sellshort order is fullfilled.
Stop limit order logic remains the same: it will be executed at a specified price, or better, after a given stop price has been reached. Once the stop price is reached, the stop-limit order becomes a limit order.
Some brokers might reject such order as "guaranteed to be executed" one.

chi jeongki
Posts: 39
Joined: 29 Nov 2007
Has thanked: 8 times
Been thanked: 2 times

Re: Relation between stopPrice and limitPrice

Postby chi jeongki » 24 Jun 2017

I use MC.NET for backtesting only, so I do not know how brokers handle StopLimit order.
My interest is on the behavior of StopLimit order in backtesting which I can utilize to make orders fullfilled within a specified range of prices.

Both pictures are for SellShort order.
Second picture is for limitPrice = 0.77 < stopPrice = 0.80.
When price do not drop to 0.80, orders are not fullfilled. Once it drops under 0.80, orders begin to fullfilled, if it is over 0.77 the limitPrice.
If it is under 0.77, orders do not fullfill, since it is limited to SellShort over 0.77 the limitPrice.
When price go up 0.77, then orders begin to fullfilled until 0.80 the stopPrice.
Once price go above 0.80, then no more fullfilling of orders.

Looking at this behaviour in backtesting,
if ShellShort order is issued,
then it is fullfilled within the specified range of price Y, where limitPrice <= Y <= stopPrice

First picture is for limitPrice = 0.80 > 0.77 = stopPrice.
In this case, since there's no range of price Y, where limitPrice <= Y <= stopPrice, then there should be no orders fullfilled.
But the first picture shows one order fullfilled at price 0.80, futher more from then no more order is fullfilled even at price 0.80.

I guess, there should be no order fullfilled in the first picture.
Seems like a bug. There's no reason for the order in first picture be fullfilled.
The price is already out of stop-effective range (price under 0.77).


Return to “MultiCharts .NET”