Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (MadJack, AndrewAMD, Quad), 540 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, 11honza11, ccorrea, sakolin, rajesh7827
19046 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
The PEEK flag and tradeMFE / tradeMAE #474333
10/07/18 14:57
10/07/18 14:57
Joined: Dec 2014
Posts: 206
Germany
Smon Offline OP
Member
Smon  Offline OP
Member

Joined: Dec 2014
Posts: 206
Germany
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.
Re: The PEEK flag and tradeMFE / tradeMAE [Re: Smon] #474335
10/07/18 15:16
10/07/18 15:16
Joined: Dec 2014
Posts: 206
Germany
Smon Offline OP
Member
Smon  Offline OP
Member

Joined: Dec 2014
Posts: 206
Germany
By the way, the plan is to predict a decent distance for SL and TP (two models, one for each) and enter a trade when the predicted risk/reward is high enough. I'll combine this with support and resistance. If you got a better idea of how to build the objective variable... I'm open to suggestions.

Re: The PEEK flag and tradeMFE / tradeMAE [Re: Smon] #474358
10/09/18 04:40
10/09/18 04:40
Joined: Dec 2014
Posts: 206
Germany
Smon Offline OP
Member
Smon  Offline OP
Member

Joined: Dec 2014
Posts: 206
Germany
Really? Did nobody ever try to predict this target?

Re: The PEEK flag and tradeMFE / tradeMAE [Re: Smon] #479596
04/09/20 13:40
04/09/20 13:40
Joined: Dec 2014
Posts: 206
Germany
Smon Offline OP
Member
Smon  Offline OP
Member

Joined: Dec 2014
Posts: 206
Germany
Solution:

Code
set(PEEK);
		
		var up_potential, down_potential = price();
		
		for(i= -20; i<=0; i++)
		{
			up_potential = max(up_potential, priceHigh(i));
			down_potential = min(down_potential, priceLow(i));
		}
   
//until here, up_potential / down_potential is ony the highest / lowest price during that upcoming period of 20 bars.

		up_potential = abs(up_potential - priceOpen())/ATR(30);
		down_potential = abs(down_potential - priceOpen())/ATR(30);


up_potential: how many ATRs the price will move up during the next 20 Bars.
up_potential: how many ATRs the price will move down during the next 20 Bars.


Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1