Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
Trading Journey
by howardR. 04/24/24 20:04
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Scripts not found
by juergen_wue. 04/20/24 18:51
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, wandaluciaia, 1 invisible), 798 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
MultiCycle backtest report? #487111
01/20/23 01:55
01/20/23 01:55
Joined: Dec 2022
Posts: 6
G
Gheo Offline OP
Newbie
Gheo  Offline OP
Newbie
G

Joined: Dec 2022
Posts: 6
I am currently working on a script for Zorro that runs a strategy using random walk cycles, similar to the MRC.c script.

I am particularly interested in the text report generated by Zorro and would like to find a way to consolidate the results of multiple cycles into a single report.

Currently, my script produces one report per cycle.

I am looking for ways to display statistics that are more meaningful to me from all test cycles than the bar graph produced by MRC.c,
and also to know if it is possible to edit the formatting of the text report generated by Zorro or add additional fields.

Any help or suggestions would be greatly appreciated.

Code

//////////////////////////////////////////////////
#include <profile.c>
#define	run strategy
#include	"Android_19.c"	// <= your script
#undef	run
#define CYCLES		10

function run()
{
	set(INITRUN|TESTNOW|LOGFILE);			// for training
	NumCores = 3;  // set desired number of cpu cores up to 72
        setf(PlotMode,PL_FINE+PL_DIFF+PL_LONG+PL_ALL+PL_BENCHMARK); //+PL_ALLTRADES
	PlotScale = 8;

	NumTotalCycles = CYCLES;
	LogNumber = TotalCycle; // used to generate logs for each backtest cycle
	
#ifdef RANDOMIZE
		Detrend = RANDOMWALK;
	set(PRELOAD);
#endif
	strategy();
	 if(TotalCycle <= NumTotalCycles-1) {
		
		plot(strf("Randomwalk%d", TotalCycle),priceOpen(),MAIN|LINE,GREY); 
	/*	if(OpenBuys[0] > OpenBuys[2]) {plot(strf("Buy%d",TotalCycle),priceOpen(),MAIN|TRIANGLE,color(100*TotalCycle/NumTotalCycles,BLUE,YELLOW,GREEN,SILVER));} // plots triangles where Buy orders will be enterd on each randomwalk cycle
		if(OpenSells[0] > OpenSells[2]) {plot(strf("Sell%d",TotalCycle),priceOpen(),MAIN|TRIANGLE4,color(100*TotalCycle/NumTotalCycles,RED,PURPLE,ORANGE,MAGENTA));}  // plots triangles where Sell orders will be enterd on each randomwalk cycle
		plot(strf("DrawDown%d",TotalCycle),(DrawDownMax*-1),NEW|LINE,color(100*TotalCycle/NumTotalCycles,RED,MAGENTA,PURPLE,ORANGE)); // plots new chart DrawDown for each randomwalk cycle
		plot(strf("Equity%d",TotalCycle),Equity,LINE,color(100*TotalCycle/NumTotalCycles,BLUE,CYAN,YELLOW,GREEN)); // plots Equity for each randomwalk cycle
		plot(strf("Balance%d",TotalCycle),Balance,LINE,GREEN+TRANSP); // plots Balance for each randomwalk cycle
	*/	

	}

}




Last edited by Gheo; 01/20/23 14:25.
Re: MultiCycle backtest report? [Re: Gheo] #487149
01/28/23 21:41
01/28/23 21:41
Joined: Dec 2022
Posts: 6
G
Gheo Offline OP
Newbie
Gheo  Offline OP
Newbie
G

Joined: Dec 2022
Posts: 6
I've had some progress with my all cycles evaluate function.

The intent is to test any particular strategy over many assets to better simulate a portfolio being run with Zorro rather than a single asset and strategy.

I am however having some difficulties.

I am looking for guidance on how to also log the statistics separately for all the assets listed for each cycle as is visible in the cycle report txt when enabled.

Both the reports and trade logs show that orders are being entered and closed on all assets.

Also to this point I haven't been able to get Zorro to run more than 8751 cycles. This looks to be due to available RAM? Is there a way to clear the memory and run more cycles with out stopping Zorro?


Code
/////////////////////  All Cycle Log  /////////////////////////////
#include <profile.c>
#define	run strategy
#include	"Android_19.c"	// <= your script LOGFILE flage must be disabled or removed from your script for maximum cycle speed
#undef	run
#define CYCLES		5
#define RANDOMIZE	RANDOMWALK	

var B[74]; // statistics value array. must be a global variable.

function run()
{	set(NOFACTORS|TESTNOW|ALLCYCLES|COMMONSTART|PRELOAD);	//NOFACTORS must be removed if you are using OptimalF in your script. add PLOTNOW for single asset allCycles randomwalk plot. 
	MonteCarlo = 0; // Monte Carlo analysis disabled to speed up cycle time
	NumWFOCycles = CYCLES *-1; 
	DataSkip = 0;
	DataSplit = 0; // 100% test cycle. The intent is to force the stratagy to run the full backtest time period aganst all assets
	DataSlope = 1;  // no weight to data
	setf(PlotMode,PL_FINE+PL_DIFF+PL_LONG+PL_ALL+PL_BENCHMARK); 
	NumCores = -1;  // set desired number of cpu cores up to 72. -1 uses all but 1 avalable cpu core.
	NumTotalCycles = CYCLES;
//	set(LOGFILE); LogNumber = TotalCycle; // THIS WILL MAKE THE TEST CYCLES TAKE MUCH LONGER.  Uncomment this line and set the LOGFILE flag in your included stratagy script to generate logs and Zorro performance reports for each backtest cycle
	Hedge = 1; // set as needed for your backtest
	asset("EUR/USD"); // List all assets to be tested.
	asset("AUD/USD");
	asset("USD/JPY");
	asset("GBP/USD");
	asset("USD/CAD");
	asset("NZD/USD");
	asset("USD/CHF");


#ifdef RANDOMIZE
	seed = 1234;
	Detrend = RANDOMWALK; // set your preferred detrend method
#endif
	for(used_assets) // this loop used to run your script on all assets listed above
	{	strategy();
	}
								// this plot function only works with single asset testing //
/*		stratagy();
		if(TotalCycle <= NumTotalCycles-1) {
		plot(strf("Randomwalk%d",TotalCycle),priceOpen(),MAIN|LINE,GREY); 
	/*	plot(strf("DrawDown%d",TotalCycle),DrawDownMax,LINE,color(100*TotalCycle/NumTotalCycles,RED,MAGENTA,PURPLE,ORANGE)); 
		plot(strf("Equity%d",TotalCycle),Equity,LINE,color(100*TotalCycle/NumTotalCycles,BLUE,CYAN,YELLOW,GREEN)); // plots Equity for each randomwalk cycle
		plot(strf("Balance%d",TotalCycle),Balance,LINE,GREEN+TRANSP); // plots Balance for each randomwalk cycle	
	}*/

}
function evaluate()
{	
	B[0] = WinLong;		// lines 42-96 Trade statistics from https://zorro-project.com/manual/en/winloss.htm
	B[1] = WinShort;
	B[2] = WinTotal;
	B[3] = LossLong;
	B[4] = LossShort;
	B[5] = LossTotal;
	B[6] = WinValLong;
	B[7] = WinValShort;
	B[8] = WinValTotal;
	B[9] = LossValLong;
	B[10] = LossValShort;
	B[11] = LossValTotal;
	B[12] = ProfitClosed;
	B[13] = ProfitOpen;
	B[14] = ProfitTotal;
	B[15] = BalanceLong;
	B[16] = BalanceShort;
	B[17] = EquityLong;
	B[18] = EquityShort;
	B[19] = WinMaxLong;
	B[20] = WinMaxShort;
	B[21] = WinMaxTotal;
	B[22] = LossMaxLong;
	B[23] = LossMaxShort;
	B[24] = LossMaxTotal;
	B[25] = NumWinLong;
	B[26] = NumWinShort;
	B[27] = NumWinTotal;
	B[28] = NumLossLong;
	B[29] = NumLossShort;
	B[30] = NumLossTotal;
	B[31] = LossStreakLong;
	B[32] = LossStreakShort;
	B[33] = LossStreakTotal;
	B[34] = WinStreakLong;
	B[35] = WinStreakShort;
	B[36] = WinStreakTotal;
	B[37] = LossStreakValLong;
	B[38] = LossStreakValShort;
	B[39] = LossStreakValTotal;
	B[40] = WinStreakValLong;
	B[41] = WinStreakValShort;
	B[42] = WinStreakValTotal;
	B[43] = NumWinLong;
	B[44] = NumWinShort;
	B[45] = NumLosingLong;
	B[46] = NumLosingShort;
	B[47] = NumOpenLong;
	B[48] = NumOpenShort;
	B[49] = NumOpenMax;
	B[50] = NumOpenPhantom;
	B[51] = NumPendingLong;
	B[52] = NumPendingShort;
	B[53] = NumPendingTotal;
	B[54] = NumRejected;
	B[55] = DrawDownMax; //line 97-115 Strategy performance statistics https://zorro-project.com/manual/en/statistics.htm
	B[56] = MAE; // still looking for a way to plot MAE for each asset per cycle that is more convenient than many many many png files.
	B[57] = MarginMax;
	B[58] = RiskMax;
	B[59] = SpreadCost;
	B[60] = SlippageCost;
	B[61] = RollCost;
	B[62] = CommissionCost;
	B[63] = ReturnMean;
	B[64] = ReturnStdDev;
	B[65] = ReturnUlcer;
	B[66] = ReturnR2;
	B[67] = ReturnCBI;
	B[68] = DrawDownBars;
	B[69] = DrawDownBarsMax;
	B[70] = LossStreakMax;
	B[71] = NumOpenMax;
	B[72] = InMarketBars;
	B[73] = InMarketSum;			//	ProfileAtBar, DrawDownAtBar, and ResultsDaily do not work with this script yet

	string csv = "Data\\08_TEST_Report_0104.csv"; // Edit name and output location of CSV file for all cycles. 
	
	string EndTime = strdate("All_Cycle_Report_End_Time_%d.%m.%Y %a %H:%M:%S\n",ldate(UTC,NOW));
	string StartTime = strdate("All_Cycle_Report_Start_Time_%d.%m.%Y %a %H:%M:%S\n",ldate(UTC,NOW));
	string CycleTime = strdate("%d.%m.%Y%H:%M:%S",ldate(UTC,NOW));
	string HDR = strf("CycleTime,TestCycleNum,AssetName,WinLong,WinShort,WinTotal,LossLong,LossShort,LossTotal,WinValLong,WinValShort,WinValTotal,LossValLong,LossValShort,LossValTotal,ProfitClosed,ProfitOpen,ProfitTotal,BalanceLong,BalanceShort,EquityLong,EquityShort,WinMaxLong,WinMaxShort,WinMaxTotal,LossMaxLong,LossMaxShort,LossMaxTotal,NumWinLong,NumWinShort,NumWinTotal,NumLossLong,NumLossShort,NumLossTotal,LossStreakLong,LossStreakShort,LossStreakTotal,WinStreakLong,WinStreakShort,WinStreakTotal,LossStreakValLong,LossStreakValShort,LossStreakValTotal,WinStreakValLong,WinStreakValShort,WinStreakValTotal,NumWinLong,NumWinShort,NumLosingLong,NumLosingShort,NumOpenLong,NumOpenShort,NumOpenMax,NumOpenPhantom,NumPendingLong,NumPendingShort,NumPendingTotal,NumRejected,DrawDownMax,MAE,MarginMax,RiskMax,SpreadCost,SlippageCost,RollCost,CommissionCost,ReturnMean,ReturnStdDev,ReturnUlcer,ReturnR2,ReturnCBI,DrawDownBars,DrawDownBarsMax,LossStreakMax,NumOpenMax,InMarketBars,InMarketSum\n");
	string AssetName = strf("%i",asset); // exparament to string the asset name for the 
	string CycleStatistics = strf("%s,%i,%i,$ %.2f,$ %.2f,$ %.2f,$ %.2f,$ %.2f,$ %.2f,$ %u,$ %u,$ %u,$ %u,$ %u,$ %u,$ %.2f,$ %.2f,$%.2f,$ %.2f,$ %.2f,$ %.2f,$ %.2f,$ %.2f,$ %.2f,$ %.2f,$ %.2f,$ %.2f,$ %.2f, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %.2f, %x, %p, %p, $%.2f, $%.2f, $%.2f, $%.2f, $%.2f, $%u, %u, %u, %u, %u, %u, %u, %u, %u, %.2f\n",CycleTime,TotalCycle,AssetName,B[0],B[1],B[2],B[3],B[4],B[5],B[6],B[7],B[8],B[9],B[10],B[11],B[12],B[13],B[14],B[15],B[16],B[17],B[18],B[19],B[20],B[21],B[22],B[23],B[24],B[25],B[26],B[27],B[28],B[29],B[30],B[31],B[32],B[33],B[34],B[35],B[36],B[37],B[38],B[39],B[40],B[41],B[42],B[43],B[44],B[45],B[46],B[47],B[48],B[49],B[50],B[51],B[52],B[53],B[54],B[55],B[56],B[57],B[58],B[58],B[60],B[61],B[62],B[63],B[64],B[65],B[66],B[67],B[68],B[69],B[70],B[71],B[72],B[73]);

	if(TotalCycle == 1) {
//	file_write(csv,HDR,0);
	file_append(csv,StartTime,0);
	file_append(csv,HDR,0);
	} 
	file_append(csv,CycleStatistics,0);
	
	if(TotalCycle == CYCLES) {
	file_append(EndTime,0);
	}

}

Attached Files
testtrades_2.zip (1 downloads)
Last edited by Gheo; 01/28/23 21:59.

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