Gamestudio Links
Zorro Links
Newest Posts
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
Deeplearning Script
by wolfi. 02/26/24 12:46
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 02/22/24 16:22
AssetAdd() vs. modern asset list?
by jcl. 02/21/24 15:01
How many still using A8
by Aku_Aku. 02/20/24 12:18
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (Quad, AndrewAMD), 567 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: Improving MAE [Re: Sphin] #459246
04/30/16 22:37
04/30/16 22:37
Joined: Feb 2015
Posts: 652
Milano, Italy
M
MatPed Offline OP
User
MatPed  Offline OP
User
M

Joined: Feb 2015
Posts: 652
Milano, Italy
yes, I have the same issue.

Re: Improving MAE [Re: MatPed] #459248
05/01/16 05:29
05/01/16 05:29
Joined: Nov 2013
Posts: 123
Mithrandir77 Offline
Member
Mithrandir77  Offline
Member

Joined: Nov 2013
Posts: 123
Matped, what period did you use to train? How many wfo cycles did you use? I ask you because I tried to reproduce your figures in order to help you but I got nowhere near, I used this script:

Code:
function TFM()
{
	/* Annual return 245%
	Profit factor 4.23 (PRR 3.61)
	Sharpe ratio 0.88
	Kelly criterion 0.31
	R2 coefficient 0.808
	Ulcer index 10.0%
	Prediction error 36%
	*/
	algo("TFM");
	var mmiPeriod = optimize(100, 25, 600, 25 );
	var lpPeriod = optimize( 90, 30, 150, 6 );
	Stop = optimize(4, 2, 8, 0.5) * ATR(100);
	
	var stopPip = Stop / PIP;
	var minPip = 10;
	Trail = stopPip * minPip;
	TrailSlope = (minPip * 100) / stopPip;
	TrailLock = optimize (0, 0, 75, 5);
	
	vars Price = series(price());
	vars Trend = series(LowPass(Price, lpPeriod));
	vars MMI_Raw = series(MMI(Price, mmiPeriod));
	vars MMI_Smooth = series(LowPass(MMI_Raw, mmiPeriod));
	
	if(Train && ParCycle <= 2) {
		Stop = 4 * ATR(100);
		TakeProfit = 8 * ATR(100);
		Trail = 0;
		TrailSlope = 100;
		TrailLock = 0;
	}
	
	if(falling(MMI_Smooth)) {
		if(valley(Trend)) {
			enterLong();
		}
		else if(peak(Trend)) {
			enterShort();
		}
	}
}

function run(){
	set(PARAMETERS);
	NumWFOCycles = 10;
	LookBack = 600;
	TFM();
	//plotMAEGraph(100);
}



And after I trained (Zorro 1.44) it produced this result:

Code:
Walk-Forward Test TFM EUR/USD

Simulated account   AssetsFix 
Bar period          1 hour (avg 86 min)
Simulation period   07.02.2011-26.04.2016 (31591 bars)
Test period         11.02.2013-26.04.2016 (19386 bars)
Lookback period     600 bars (5 weeks)
WFO test cycles     9 x 2154 bars (18 weeks)
Training cycles     10 x 12205 bars (105 weeks)
Monte Carlo cycles  200
Assumed slippage    10.0 sec
Spread              0.5 pips (roll -0.02/0.01)
Commission          0.60
Contracts per lot   1000.0

Gross win/loss      719$ / -952$ (-2675p)
Average profit      -73$/year, -6.06$/month, -0.28$/day
Max drawdown        -238$ -102% (MAE -245$ -105%)
Total down time     97% (TAE 66%)
Max down time       163 weeks from Mar 2013
Max open margin     40$
Max open risk       35$
Trade volume        493516$ (154060$/year)
Transaction costs   -20$ spr, -2.37$ slp, -0.49$ rol, -27$ com
Capital required    271$

Number of trades    456 (143/year, 3/week, 1/day)
Percent winning     22.8%
Max win/loss        47$ / -17$
Avg trade profit    -0.51$ -5.9p (+79.4p / -31.1p)
Avg trade slippage  -0.01$ -0.1p (+0.9p / -0.3p)
Avg trade bars      30 (+75 / -17)
Max trade bars      376 (22 days)
Time in market      72%
Max open trades     4
Max loss streak     19 (uncorrelated 26)

Annual return       -27%
Profit factor       0.76 (PRR 0.65)
Sharpe ratio        -0.87
Kelly criterion     -2.86
R2 coefficient      0.419
Ulcer index         100.0%
Prediction error    56%

Confidence level     AR   DDMax  Capital

 10%                -40%   147$  182$
 20%                -36%   166$  201$
 30%                -33%   189$  223$
 40%                -29%   216$  249$
 50%                -26%   245$  277$
 60%                -24%   277$  308$
 70%                -21%   313$  343$
 80%                -19%   351$  380$
 90%                -16%   415$  442$
 95%                -14%   482$  506$
100%                -11%   613$  633$

Portfolio analysis  OptF  ProF  Win/Loss  Wgt%  Cycles

EUR/USD:TFM         .000  0.76  104/352  100.0  \\X\XX\X\
EUR/USD:TFM:L       .000  0.63   49/186   89.2  \\/\\\\/\
EUR/USD:TFM:S       .000  0.94   55/166   10.8  \\\\//\\\



Anyway, looking at the manual about TradeMAE it says 'Maximum adverse excursion, the maximum price movement in adverse direction of the trade. Only valid when the trade is open. TradeMAE*TradeUnits is the highest loss of the trade while it was open (aside from trading costs). '

So maybe use

Code:
int maxMAE(var maxPIP){
    if (TradeIsOpen and TradeMAE*TradeUnits > maxPIP*PIP) 
        return 1;
    else 
        return 0;
}


Re: Improving MAE [Re: Mithrandir77] #459249
05/01/16 08:58
05/01/16 08:58
Joined: Feb 2015
Posts: 652
Milano, Italy
M
MatPed Offline OP
User
MatPed  Offline OP
User
M

Joined: Feb 2015
Posts: 652
Milano, Italy
Thank you.
You are really digging into this!
Attacched all the files I am use for experimenting. Keep in mind I am not a coding pro and I'm facing several difficulties in improving my Zorro's knowledge.
The workshop provided with the platform are great, but are just the top of the iceberg laugh

Ciao

Attached Files
FatStrategy.zip (152 downloads)
Re: Improving MAE [Re: MatPed] #459255
05/01/16 22:54
05/01/16 22:54
Joined: Nov 2013
Posts: 123
Mithrandir77 Offline
Member
Mithrandir77  Offline
Member

Joined: Nov 2013
Posts: 123
Originally Posted By: MatPed
Thank you.
You are really digging into this!
Attacched all the files I am use for experimenting. Keep in mind I am not a coding pro and I'm facing several difficulties in improving my Zorro's knowledge.
The workshop provided with the platform are great, but are just the top of the iceberg laugh

Ciao


No problem mate! But I downloaded the 2016 and 2015 history from FXCM and was about to train your strategy when I got:

Code:
Zorro 1.44.0 Trading Automaton
Made with Gamestudio by oP group 2015


FatStrategy compiling..............
Error in 'line 13: 
Include file strategy\fatstrategy\aunger.c not found
< #include "Strategy\FatStrategy\AUnger.c"
 >..
Error in 'line 26: 
'ptnBaseSet' undeclared identifier
< 	ptnBaseSet();
 >.



It seems you forgot to include the 'AUnger.c' file where ptnBaseSet() is defined, can you upload it? Or tell me if I can safely comment ptnBaseSet() without effecting the result.

In addition, I see that you defined
Code:
#define ASSETLOOP "AUD/USD", "EUR/USD", "GBP/USD", "GER30", "NAS100", "SPX500", "UK100", "US30", "USD/CAD", "USD/CHF", "USD/JPY", "XAG/USD", "XAU/USD" // ALL z12



I recall reading in the forum to start a loop with the asset with the most complete history and that asset is EUR/USD, maybe it wouldn't hurt to change that.

Last edited by Mithrandir77; 05/01/16 22:54.
Re: Improving MAE [Re: MatPed] #459264
05/03/16 02:31
05/03/16 02:31
Joined: Nov 2013
Posts: 123
Mithrandir77 Offline
Member
Mithrandir77  Offline
Member

Joined: Nov 2013
Posts: 123
I got really curious and think I nailed it. The problem was with the TICKS flag: when you don't set the ticks flag, in the simulation the TMF is called once per bar, so when using the default BarPeriod of 60 minutes for instance, you are evaluating the exit condition every 60 minutes, which isn't very 'granular' enough to stop the MAE from jumping past your limit!

So, try

Code:
set(TICKS);



at the beginning of the run() function and use as TMF (for instance if your objective MAE is 300 pips):

Code:
int maxMAE(){
   //return 0;
	
   if (TradeIsOpen and TradeMAE/PIP >= 300){
       printf("\nExit at %f MAE",(var)(TradeMAE/PIP));
       return 1;
   }
   else
       return 0;
}



Look at what is printed in the Zorro console when you don't use set(TICKS) and when you do. You should see the trades exited more closely to the limit you whant when you use TICKS flag than when you don't.

In my case, I tested with an script similar to Workshop 6, it has BarPeriod=60 and functions with TimeFrame=1 and TimeFrame=4. The data I have are m1 candles from FXCM.

PlotMAEGraph(-15) without setting the TICKS flag:



PlotMAEGraph(-15) setting TICKS flag:



The amount of losing trades lowered, anyway there are trades with 345 MAE although I wanted to stop them at 300...I guess that in a minute -with my m1 FXCM data, 1 tick=1 minute, remember Zorro glosary
Click to reveal..
Tick - event when a new price arrives and is evaluated by the trading software. Either triggered by receiving a price quote in live trading, or by reading the next price out of historical data in the simulation. Ticks in historical data files are stored with a time stamp and a price info. For keeping the files at a reasonable size, price quotes are normally combined to one tick per minute (M1 data), but for special purposes data containing all real price ticks (T1 data) can also be used.

- the trade bounced 45 pips, what intrigues me is that in my script I didn't define Lots -nor Margin nor Risk nor Capital- so the trade should use 1 lot...Is it plausible that in 1 minute 1 (FXCM micro)lot -I read AssetsFix.csv and it says LotAmount=1000 for EUR/USD- bounces 45 pips? Maybe someone else (jcl laugh ) can shed some light...

Also, another question that I have is that since TradeMAE is the MAE of a 'trade', the more Lots or Margin or Risk you assign to a trade the less sensitive it is going to be to changes in prices, isn't it? Say:

trader1 is long 1 lot in EUR/USD
trader2 is long in one trade with 2 lots of EUR/USD

Both trades are at 178 pips loss,the maxMAE is 180, EUR/USD drops 5 pips in a tick

trader1 is going to closehis/her 1 lot trade at 178+5=183 pips loss (3 pips more than the barrier)

trader2 is going to close his/her 2 lots trade at 178+2*5=188
pips loss (8 pips more than the barrier!)

Is there a way to make the TMF stop a trade with an accuracy independent of its trade size? I can see that it has something to do with TradeLots and PipCost or PIP but I haven't been able to derive it so far...

Last edited by Mithrandir77; 05/03/16 02:41. Reason: corrected example
Re: Improving MAE [Re: Mithrandir77] #459265
05/03/16 06:19
05/03/16 06:19
Joined: Feb 2015
Posts: 652
Milano, Italy
M
MatPed Offline OP
User
MatPed  Offline OP
User
M

Joined: Feb 2015
Posts: 652
Milano, Italy
A lot of things to work with.
Thank you. I am in a business trip. I will work on this during the weekend frown.
I'll be back!

Ciao

Re: Improving MAE [Re: MatPed] #459322
05/07/16 14:33
05/07/16 14:33
Joined: Feb 2015
Posts: 652
Milano, Italy
M
MatPed Offline OP
User
MatPed  Offline OP
User
M

Joined: Feb 2015
Posts: 652
Milano, Italy
Ok I have tested your function and something happens...
Regarding the ticks flag. I trade the strategy in normal 1h mode and test in the ticks mode.

As you mentioned the calculations seems correct, even some trade are slightly over the limit set. Unfortunately the MAE graph shows a totally different picture.
I can see only 2 Options:
- the trade are not stopped properly
- the MAE graph is incorrect.

The TradeMAE is price difference, accordingly with the manual. the TradeMAE should be size independent.

I will work on a TMF that will close the trade at a specific pip loss and see what happen should be the same than set Stop = 200* Pip;

ciao

Page 2 of 2 1 2

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