Get Data from internal functions, eg plotMAEGraph

Posted By: dr_panther

Get Data from internal functions, eg plotMAEGraph - 10/30/16 18:26

I wonder how I could get the data which is used to do some graphs like
plotMAEGraph. I was thinking if there is a simple possibility to get it as csv for example.

I could visualize to track the status of each trade in a variable and write it into a file at the close, but is there a more elegant way?
Posted By: dr_panther

Re: Get Data from internal functions, eg plotMAEGraph - 10/30/16 18:39

Just found the solution: the profile.c has all the code:



Code:
void plotMAEGraph(int bars)
{
	if(!is(TESTMODE)) return; 
	g->dwStatus |= PLOTSTATS;
	if(is(EXITRUN))
	{
		if(!bars) bars = 50;
	
		var vMaxMAE = 0;
		for(all_trades) // calculate maximum MAE in pips
			vMaxMAE = max(vMaxMAE,TradeMAE/PIP);
		//printf("\nMaxMAE: %.0f",vMaxMAE);
	
		var vStep;
		if(bars < 0) // bucket size in pips
			vStep = -bars;
		else
			vStep = 10*(int)max(1.,vMaxMAE/bars/10);
		printf("  Step: %.0f",vStep);
		
		for(all_trades) 
		{
			var vResult = toPIP(TradeResult);
			var vMAE = TradeMAE/PIP/vStep;
			int n = floor(vMAE);
			plotBar("Profit",n,n*vStep,0,AVG|BARS|LBL2,COLOR_DEV);
			if(vResult > 0)
				plotGraph("Win",vMAE,vResult,DOT,GREEN);
			else
				plotGraph("Loss",vMAE,vResult,DOT,RED);
		}
	}
}



Which leads to the next question: does someone have written more graph functions and is willing to share them?
Posted By: boatman

Re: Get Data from internal functions, eg plotMAEGraph - 10/31/16 01:21

Here's one that I use to plot Sharpe ratios from different cycles with the same script.

An example of where I use this is in machine learning research where the learning algorithm has a non-deterministic component (for example, the initial weights of a neural network), and I want to test the stability of performance. Also, if you set the BALANCED argument of adviseLong(), Zorro can generate different training data for your machine learning models in each training run. Testing them over several cycles can help assess the stability of the model.

Code:
void plotSharpeCycles() // calculate sharpe ratio of individual trade cycles via Welford algorithm
{
	if(is(EXITRUN)) 
	{
		var n = 0;
		var mean = 0;
		var M2 = 0;
		var delta;
		var variance = 0;
		for(all_trades)
		{
			n += 1;
			delta = TradeProfit - mean;
			mean += delta/n;
			M2 += delta*(TradeProfit - mean);
			variance = M2/(n-1);			
		}
		var sharpe = sqrt(252)*mean/sqrt(variance);
		plotBar("",TotalCycle,TotalCycle,0,SUM|BARS|LBL2,BLUE);
		plotGraph("Sharpe",TotalCycle,sharpe,LINE,RED);
	}
}

© 2024 lite-C Forums