I'm trying to export signals for Deep Learning with this script and I have an issue:

I want to predict the maximum favorable excursion of a trade (TradeMFE). So I export only long trades and if the trade was a loser, I take the maximum adverse excursion instead (TradeMAE). What I get seems to be the data from the trade before. The data I exported is now in this format:

DateTime | EMA200 (D1) | TradeMFE | TradeMAE | My Objective | Trade Return (for comparison)

The second last column (MAE / MFE) should always have the same sign as the last column (Profit). However, if the last column changes its sign, the second last column reacts with a delay of one row:

Code:
function run()
{
	set(RULES+PEEK);
	StartDate = 20150101;
	EndDate = 20150115;
	BarPeriod = 15; 

	while(asset(loop("EUR/USD")))
		
	{
		//Append asset name to csv file to avoid overwriting when exporting with SIGNALS
	
		static string prevAsset;
		if (is(INITRUN)) {
				char dest[50];
				string ass = strx(prevAsset,"/","");
				sprintf(dest,"Data%s_%d_target.csv",ass,BarPeriod);
				if(file_length("Datatarget.csv") != 0)
				{
					file_copy(dest,"Datatarget.csv");
				}
				prevAsset = Asset;
		}
		
		
		Spread = RollLong = RollShort = Commission = Slippage = 0;
		
		LifeTime = 1;
	
		vars myMFE = series(TradeMFE);
		vars myMAE = series(TradeMAE);
		
		int Offset = ifelse(Train,-1,0);
		
		var Objective;
		if(TradeProfit >= 0) Objective = myMFE[Offset];
		if(TradeProfit <  0) Objective = -myMAE[Offset];
		
		
		// generate the signals
		adviseLong(SIGNALS, 0, wdate(0), myMFE[Offset], myMAE[Offset], Objective);
		enterLong();
	}
}



I set Objective = 0 in the adviseLong call just for debugging purposes.

With Offset = -1, I get only Zero values.

Without this PEEK and Offset attempt, I'm getting this (see attached screenshot for better readability:


Quote:

42006 0 0 0 -0.24987
42006.01042 0.00018 0.00033 -0.00033 0.11199
42006.02083 0.00031 0.00001 0.00031 -1.15484
42006.03125 0.00002 0.00163 -0.00163 -0.44817
42006.04167 0.00002 0.00057 -0.00057 0.09483
42006.05208 0.00047 0.00043 0.00047 -1.02569
42006.0625 0 0.0015 -0.0015 0.87918
42006.07292 0.00102 0.00052 0.00102 -0.00863
42006.08333 0.00028 0.0004 -0.0004 -0.37923


It's evident, that by default, tradeMFE and tradeMAE don't relate to the trade that gets opened at the current bar, but to the next trade. So the whole Objective column lags by 1 row. I will use a non-fixed LifeTime in my final script and I already learned that rows are written to the file in the sequence of the closed trades. Therefore I'm a little hesitant to just work around and shift the whole Objective column. Any help/suggestions highly appreciated!

Attached Files
MFEMAE.PNG (94 downloads)
Last edited by sdh309795gaas; 10/07/18 15:03.