Hi,

I'd be grateful for an explanation as to whether the following is a misunderstanding or a bug.

I am running the following simple test script "sample.c" in order to understand run() and tick() and how a TMF (trade management function) is called:

Code:
static int position;

int myTMS ( var hour, var minute) {

  if (TradeIsOpen) {

    printf ("\nopen trade: %f %f %f %f",priceOpen (),priceHigh (),priceLow (),priceClose ());
    if (timeOffset (CET,0,hour,minute) >= 0) {
      position = 0;
      return (5);
    }
  }

  return (4);
}

function run () {

  set (LOGFILE + NFA);

  if (is (INITRUN)) {

    History = ".t6";
    Lots = 1;
    LookBack = 1200;
    BarPeriod = 1;
    TickTime = 1;
    StartDate = 20170701;
    EndDate = 20170705;
    Verbose = 7;
    
    //asset ("DAX-FUT-20171215-FDAX-DTB-EUR");
    asset ("EURUSD");

    position = 0;
    
    return;
  }

  if ((timeOffset (CET,0,10,5) >= 0) && (timeOffset (CET,0,10,15) < 0) && (position == 0)) {
    position = 1;
    enterLong (myTMS,10,20);
  }
}

function tick () {
  printf ("\ntick: %f %f %f %f",priceOpen (),priceHigh (),priceLow (),priceClose ());

  if (day () != day (1)) {
    position = 0;
  }
}


Here myTMF() simply prints all price ticks while the position is open and then closes it at a given time. The strategy coded in run() opens the position at 10:05 local time and closes it at 10:20 via said TMF.

Now here is the behaviour that I don't understand. When I run this strategy as a backtest with the builtin EURUSD minute data (.t6), I get, as expected the log file
Code:
<snip>
[8368: Mon 17-07-03 08:04] (1.13904)
tick: 1.139100 1.139250 1.139090 1.139150
[8369: Mon 17-07-03 08:05] (1.13910)
[EURUSD::L6901] Long 1@1.13927  at 08:05:00
open trade: 1.139150 1.139340 1.139090 1.139180
tick: 1.139150 1.139340 1.139090 1.139180

[8370: Mon 17-07-03 08:06] +0 -0 0/1  (1.13915)
open trade: 1.139180 1.139310 1.139150 1.139250
tick: 1.139180 1.139310 1.139150 1.139250
[8371: Mon 17-07-03 08:07] +0 -0 0/1  (1.13918)
open trade: 1.139250 1.139290 1.139110 1.139170
tick: 1.139250 1.139290 1.139110 1.139170
<snip>


I see that the TMF is called immediately before the tick() function and with the same OHLC prices.

Now I use the Interactive Brokers (IB) backend where I have real-time data for the Dax future and use the Download.c script to obtain historical minute data of DAX-FUT-20171215-FDAX-DTB-EUR. When I backtest the above sample strategy with the Dax future, however, the log file shows
Code:
<snip>
[5161: Mon 17-07-03 08:04] (12381.00)
tick: 12382.000000 12382.000000 12377.500000 12379.000000
[5162: Mon 17-07-03 08:05] (12382.00)
[::L6201] Long 1@12379.00  at 08:05:00
Error 015: trade [::L6201] bad exit price 0.0000
[::L6201] Sell 1@0.00000: -12379$ at 08:05:00
tick: 12379.000000 12386.500000 12379.000000 12384.000000

[5163: Mon 17-07-03 08:06] -12379 +0 0/1  (12379.00)
tick: 12384.000000 12386.500000 12384.000000 12384.500000
[5164: Mon 17-07-03 08:07] -12379 +0 0/1  (12384.00)
tick: 12384.500000 12384.500000 12379.500000 12381.000000
<snip>


i.e. the trade is again entered at 10:05 local time, but immediately produces a "Bad Exit Price 0.0000" error. The downloaded minute data is fine, by the way, as I can see when I export to CSV. There are *no* spurious zero prices or similar.

It finally becomes apparent where the zero prices originate from as soon as I run the script in live trading with the actual (sub-minute) Dax future ticks. I changed the entry time to 13:47 because that was when I made the test. I also added a "Entry=0; Stop=0; TakeProfit=0; Trail=0;" in order to suppress any other TMF logic for this test:
Code:
<snip>
[1498: Wed 17-09-13 11:46] 12534/1253412534/12534
tick: 12533.500003 12533.500003 12533.500003 12533.500003
tick: 12533.500003 12533.500003 12533.000003 12533.000003
tick: 12533.500003 12533.500003 12532.500000 12532.500000
tick: 12533.500003 12533.500003 12532.000000 12532.000000
tick: 12533.500003 12533.500003 12532.000000 12532.500000
tick: 12533.500003 12533.500003 12532.000000 12533.000003
tick: 12533.500003 12533.500003 12532.000000 12532.500000
tick: 12533.500003 12533.500003 12532.000000 12533.000010
tick: 12533.500003 12533.500003 12532.000000 12532.500000
tick: 12533.500003 12533.500003 12532.000000 12532.000004
tick: 12533.500003 12533.500003 12531.500007 12531.500007
tick: 12533.500003 12533.500003 12531.500007 12532.500000
tick: 12533.500003 12533.500003 12531.500007 12533.000004
tick: 12533.500003 12533.500003 12531.500007 12532.500004
tick: 12533.500003 12533.500003 12531.500007 12533.000007
tick: 12533.500003 12533.500003 12531.500007 12532.500000
tick: 12533.500003 12533.500003 12531.500007 12533.000006
tick: 12533.500003 12533.500003 12531.500007 12532.500010
tick: 12533.500003 12533.500003 12531.500007 12532.000000
tick: 12533.500003 12533.500003 12531.500007 12532.500006
tick: 12533.500003 12533.500003 12531.500007 12532.000000
[1499: Wed 17-09-13 11:47] 12534/1253412532/12532
Enter 1L DAX-FUT-2017121  at 11:47:01
BrokerBuy DAX-FUT-20171215-FDAX-DTB-EUR: 152 ms
[DAX-FUT-2017121::L8273] Long 1@12532.00  at 11:47:01
Units: 1.0000 Margin: 0.00 MCost: 12531.0000 PCost: 0.01000
open trade: 0.000000 0.000000 0.000000 0.000000
tick: 12532.000007 12532.000007 12532.000007 12532.000007
open trade: 0.000000 0.000000 0.000000 0.000000
tick: 12532.000007 12532.500000 12532.000007 12532.500000
open trade: 0.000000 0.000000 0.000000 0.000000
tick: 12532.000007 12532.500000 12531.500006 12531.500006
<snip>


You can see that the TMF is always called with all four prices equal to zero.

Now if this is a consequence of trading the Dax future as opposed to a currency pair, that would explain the "Bad Exit Price 0.0000" problem - the system TMF that runs even before mine, sees the zero price ticks, too, and the position is stopped out at price 0.00 even before myTMF() get called for the first time.

I wonder whether I am somehow using the futures in a wrong setting or whether there is perhaps still a bug?

This happens both with Zorro 1.54 and 1.60.

Thanks for your help. Kind Regard,

Gloria