IOG mode and strange backtester behaviour

Questions about MultiCharts .NET and user contributed studies.
dasepi
Posts: 4
Joined: 08 Aug 2014
Has thanked: 1 time

IOG mode and strange backtester behaviour

Postby dasepi » 12 Mar 2015

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

User avatar
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

Postby JoshM » 15 Mar 2015

Code: Select all

if (StrategyInfo.MarketPosition==0) {
orderLE.Send(dayOpen - pOffset);
orderSE.Send(dayOpen + pOffset);
GenerateProfitTarget(2*pOffset);
GenerateStopLoss(4*pOffset);
GenerateExitOnClose();
}
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);
}
else if (StrategyInfo.MarketPosition != 0)
{
GenerateProfitTarget(2*pOffset);
GenerateStopLoss(4*pOffset);
GenerateExitOnClose();
}
More information about these special kind of orders can be found here.

dasepi
Posts: 4
Joined: 08 Aug 2014
Has thanked: 1 time

Re: IOG mode and strange backtester behaviour

Postby dasepi » 16 Mar 2015

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

chosenek
Posts: 26
Joined: 01 Mar 2015
Has thanked: 2 times

Re: IOG mode and strange backtester behaviour

Postby chosenek » 18 Mar 2015

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

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: IOG mode and strange backtester behaviour

Postby Henry MultiСharts » 20 Mar 2015

as soon as I add GenerateProfitTarget, I see that in 30% of cases Backtester assumes entry on bar open instead of target.
Hello dasepi,

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.
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).
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.
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.
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.


Return to “MultiCharts .NET”