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 : ??
stopPrice >= limitPrice : OK
Relation between stopPrice and limitPrice
-
- Posts: 39
- Joined: 29 Nov 2007
- Has thanked: 8 times
- Been thanked: 2 times
- Angelina MultiСharts
- Posts: 260
- Joined: 28 Dec 2016
- Has thanked: 28 times
- Been thanked: 66 times
Re: Relation between stopPrice and limitPrice
Hello chi jeongki,
Your inquiry is analyzed. I will get back to you with the answer.
Your inquiry is analyzed. I will get back to you with the answer.
- Angelina MultiСharts
- Posts: 260
- Joined: 28 Dec 2016
- Has thanked: 28 times
- Been thanked: 66 times
Re: Relation between stopPrice and limitPrice
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.In buy order, if limitPrice < stopPrice, then no buy order is fullfilled.
In sellshort order, if stopPrice < limitPrice, then no sellshort order is fullfilled.
Some brokers might reject such order as "guaranteed to be executed" one.
-
- Posts: 39
- Joined: 29 Nov 2007
- Has thanked: 8 times
- Been thanked: 2 times
Re: Relation between stopPrice and limitPrice
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).
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).