I want to
keep track of the order entry time (not trade entry time) in a TMF
so I can
use order entry time when analyzing TradeProfit across many trades
and use order entry time as a globally unique identifier (recall that Zorro re-uses trade ids)

Order Time is not a tracked trade variable (recall a post of mine from long ago). As a work-around, I am encoding order entry time as a TradeVar. I tried this toy script:
Code:
var encode_date() {
  var ret = 0.;
  ret += minute();
  ret += hour() * 100.;
  ret += day() * 10000.;
  ret += month() * 1000000.;
  ret += year() * 100000000.;
  return ret;
}

int manage(var order_date, var mult) {
	if (TradeIsClosed) {
		printf("n%0.0f: %f", order_date, TradeProfit);
	}
	return 0;
}

function run() {
  if (is(INITRUN)) {
    assetList("AssetsNew.csv");
    set(OPENEND);
    set(TICKS);	 
    StartDate = 20110201;
    EndDate = 20110202;
    BarPeriod = 1;
    LookBack = 140;
    Hedge = 2;
    Margin = 250.;
    TradesPerBar = 2;
    MaxLong = 10000;
    MaxShort = 10000;
    Weekend = 1+8;
  }
  
  var p = fabs(random());
  if (p > 0.999) {
	  LifeTime = 1440 * 7;
	  EntryTime = 1;
	  var mult = ATR(100);
	  Stop = 3 * mult;
	  TakeProfit = 3 * mult;
	  
	  var ec = encode_date();
	  if (p > 0.9995) {
		  printf("n%0.0f enterLong", ec);
		  enterLong(manage, ec, mult);
	  } else {
		  printf("n%0.0f enterShort", ec);
		  enterShort(manage, ec, mult);
	  }
  }
}


Observed:
arg order_date always contains 201102016512, representing a nonsense datetime. (hour 65).
Code:
Test: trade_management_aai EUR/USD (TICKS) 2011
Assets AssetsNew.csv
201101312349 enterLong
201102010425 enterShort
201102016512: 1.642228
201102012004 enterShort
201102016512: -10.414859
201102020131 enterLong
201102016512: -6.834805
Loss -16$  MI -238$  DD 17$  Capital 302$
Trades 3  Win 33.3%  Avg -5.1p  Bars 40
AR -945%  PF 0.10  SR -11.84  UI 100%  R2 0.69


Expected:
I expected arg order_date to contain the encoded order entry times, such as 201101312349, as shown in the entry printf lines.

How thoroughly confused am I?

Last edited by GPEngine; 02/26/18 02:45.