Hi, I am testing a model on daily bars with [IOGMode(IOGMode.Enabled)] set and bar magnifier set to 1-min resolution. While there is no position, I keep sending a pair of limit orders. Everything works as expected if I close them with GenerateExitOnCLose() order. However, as soon as I add GenerateProfitTarget, I see that in 30% of cases Backtester assumes entry on bar open instead of target. Am i doing something wrong ?
protected override void Create() {
orderLE = OrderCreator.Limit(new SOrderParameters(Contracts.Default, "LE", EOrderAction.Buy));
orderSE = OrderCreator.Limit(new SOrderParameters(Contracts.Default, "SE", EOrderAction.SellShort));
orderLT = OrderCreator.Limit(new SOrderParameters(Contracts.Default, "LT", EOrderAction.Sell));
orderST = OrderCreator.Limit(new SOrderParameters(Contracts.Default, "ST", EOrderAction.BuyToCover));
}
...
if (StrategyInfo.MarketPosition==0) {
orderLE.Send(dayOpen - pOffset);
orderSE.Send(dayOpen + pOffset);
GenerateProfitTarget(2*pOffset);
GenerateStopLoss(4*pOffset);
GenerateExitOnClose();
}
I am resubmitting both limit entry orders on each update, not just Bars.Status==EBarState.Open as per forums for as long as one of them entered. So entry should be either at open + offset or open - offset, however in some cases entry is exactly at the open of the daily bar.
The reason I am using IOGMode.Enabled is because I would like to program the logic where only one of the two limit orders is entered, and ProfitTarget, StoppLoss and TimedExit are attached to it.
On another note, is there an API for setting time-in-force on the order, or do I have to do it myself in the code (in which case I am also going to need IOGMode.Enabled to keep checking time constraints).
Thanks,
Dave
IOG mode and strange backtester behaviour
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: IOG mode and strange backtester behaviour
You're currently only submitting the stop-loss and profit targets when there is no open position. Have you tried something like the following?Code: Select all
if (StrategyInfo.MarketPosition==0) {
orderLE.Send(dayOpen - pOffset);
orderSE.Send(dayOpen + pOffset);
GenerateProfitTarget(2*pOffset);
GenerateStopLoss(4*pOffset);
GenerateExitOnClose();
}
Code: Select all
if (StrategyInfo.MarketPosition == 0)
{
orderLE.Send(dayOpen - pOffset);
orderSE.Send(dayOpen + pOffset);
}
else if (StrategyInfo.MarketPosition != 0)
{
GenerateProfitTarget(2*pOffset);
GenerateStopLoss(4*pOffset);
GenerateExitOnClose();
}
Re: IOG mode and strange backtester behaviour
I did try lots of different variations, including the one suggested, to test if there are open orders. I will be investigating further this issue, but preliminary determination is that under certain conditions GenerateExitOnClose will not close the signal, and carry it over to the next day. I will continue investigating this issue over the weekend. One aspect I wanted to test in further details is to see if Limit buy order fires on last minute (causing GenerateExitOnClose not to be fired), however, looking visually at charts it is a very low chance of this.
Is there an API to access programatically selected by user session start time and session end time to determine start of day and end of day ?
Thanks,
Dave
Is there an API to access programatically selected by user session start time and session end time to determine start of day and end of day ?
Thanks,
Dave
Re: IOG mode and strange backtester behaviour
Hi Dave,
you can access the session in two following ways.
Bars.Info.SessionName; //to get the session name
Bars.Sessions.First(); //to get the session object with properties you are looking for
Br,
Petr
you can access the session in two following ways.
Bars.Info.SessionName; //to get the session name
Bars.Sessions.First(); //to get the session object with properties you are looking for
Br,
Petr
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2957 times
Re: IOG mode and strange backtester behaviour
Hello dasepi,as soon as I add GenerateProfitTarget, I see that in 30% of cases Backtester assumes entry on bar open instead of target.
If an order is filled at Open of the bar then this price satisfies the order execution conditions for this order. For more information please see How Signals are Calculated.
There is no way to set the time-in-force for the strategy orders from the code. If broker supports different TIF values - you can set it in Format->Strategy properties->Auto trading tab->Select broker plugin->Settings.On another note, is there an API for setting time-in-force on the order, or do I have to do it myself in the code (in which case I am also going to need IOGMode.Enabled to keep checking time constraints).
In realtime trading GenerateExitOnClose conditions are not always met. There are two conditions that should be met: session end and a simultaneous with session end tick. The second condition is not always met unfortunately, this can happen if the market is slow and the position won’t close. You can close your positions using this script.I did try lots of different variations, including the one suggested, to test if there are open orders. I will be investigating further this issue, but preliminary determination is that under certain conditions GenerateExitOnClose will not close the signal, and carry it over to the next day. I will continue investigating this issue over the weekend. One aspect I wanted to test in further details is to see if Limit buy order fires on last minute (causing GenerateExitOnClose not to be fired), however, looking visually at charts it is a very low chance of this.