Example #1
0
void plotTradeProfile(int bars)
{
	if(!is(TESTMODE) || !is(EXITRUN)) return; 
	if(!bars) bars = 50;

	var vWinMax = 0, vLossMax = 0;
	for(all_trades) { // calculate minimum & maximum profit in pips
		vWinMax = max(vWinMax,toPIP(TradeResult));
		vLossMax = max(vLossMax,-toPIP(TradeResult));
	}
	if(vWinMax == 0 && vLossMax == 0) return;
	
	var vStep;
	if(bars < 0) // bucket size in pips
		vStep = -bars;
	else
		vStep = 10*(int)((vWinMax+vLossMax)/bars/10);
	
	int n0 = ceil(vLossMax/vStep);
	for(all_trades) 
	{
		var vResult = toPIP(TradeResult);
		int n = floor(vResult/vStep);
		plotBar("Profit",2*(n+n0),n*vStep,abs(vResult),SUM|BARS|LBL2,COLOR_AVG);
		plotBar("Number",2*(n+n0)+1,0,1,SUM|BARS|AXIS2,COLOR_DEV);
	}
}
Example #2
0
void plotMAEGraph(int bars)
{
	if(!is(TESTMODE) || !is(EXITRUN)) return; 
	if(!bars) bars = 50;

	var vMaxMAE = 0;
	for(all_trades) // calculate maximum MAE in pips
		vMaxMAE = max(vMaxMAE,TradeMAE/TradePIP);
	//printf("\nMaxMAE: %.0f",vMaxMAE);

	var vStep;
	if(bars < 0) // bucket size in pips
		vStep = -bars;
	else
		vStep = 10*(int)(vMaxMAE/bars/10);
	
	for(all_trades) 
	{
		var vResult = toPIP(TradeResult);
		var vMAE = TradeMAE/TradePIP/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);
	}
}
Example #3
0
function plotSeason(int n,int label,int season,var value,int type)
{
	if(!is(TESTMODE)) return; // [Test] only

	static int lastseason = 0;
	static var value0 = 0;
	if(season != lastseason) {
		value0 = value;
		lastseason = season;
	} 

	plotBar("Value",n,label,value-value0,NEW|AVG|BARS|LBL2,COLOR_AVG);	
	plotBar("StdDev",n,0,(value-value0)/4,DEV|BARS,COLOR_DEV);	

	if(type&PDIFF) value0 = value;
}
Example #4
0
function run()
{
	NumYears = 3;
	BarPeriod = 1;
	LookBack = 1440;
	PlotScale = 15;	
	Commission = 0.6;
	Spread = 0.5*PIP;

	int Duration = 1, i = 0;
	if(!is(LOOKBACK))
		while(Duration <= 1440)
	{ 	
		var Win = abs(priceClose(Duration)-priceClose(0))*PIPCost/PIP;
		var Cost = Commission*LotAmount/10000. + Spread*PIPCost/PIP;
	
		//printf("\nWin %.2f Cost %.2f",Win,Cost);
	
// Breakeven:
// Profit = Cost = Rate * Win - (1.-Rate) * Win; 
// => Cost = (Rate - 0.5) * 2 * Win; 
		
		var Rate = ifelse(Win>Cost, Cost/(2*Win) + 0.5, 1.);

		plotBar("Min Rate",i,Duration,100*Rate,AVG+BARS,RED);	
		
		if(Duration < 10) Duration += 1;
		else if(Duration < 60) Duration += 5;
		else if(Duration < 180) Duration += 30;
		else Duration += 60;
		i++;
	}

	Bar += 100;
}
Example #5
0
// plot price difference profile
void plotPriceProfile(int bars,int type)
{
	if(!is(TESTMODE)) return; // [Test] only
	if(!bars) bars = 50;
	set(PLOTNOW+PEEK); // peek in the future 
	var vProfit;
	int count;
	for(count = 1; count < bars; count++) 
	{
		if(type&PDIFF) 
			vProfit = (price(-count-1)-price(-count))/PIP;
		else
			vProfit = (price(-count-1)-price(-1))/PIP;
		if(type&PMINUS) 
			vProfit = -vProfit;
		plotBar("Price",count,count,vProfit,NEW|AVG|BARS|LBL2,COLOR_AVG);
		plotBar("StdDev",count,0,vProfit/4,DEV|BARS,COLOR_DEV);
	}
}
Example #6
0
// generate a profit distribution chart
function run()
{
	BarPeriod = 1440;
	StartDate = 2012;
	NumYears = 1;
	LookBack = 0;
	asset("EUR/USD");

// run this simulation 3000 times	
	NumTotalCycles = 3000;
	strategy1();	

// plot the result of every run in a bar graph	
	if(is(EXITRUN)) {
		int Step = 250;
		int Result = floor(ProfitClosed/PIPCost/Step);
		plotBar("Profit",Result,Step*Result,1,SUM|BARS|LBL2,RED);	
	}
	
	PlotHeight1 = 320;
}
Example #7
0
void _plotHistogram(string Name,var Value,var Step,int Color)
{
  var Bucket = floor(Value/Step);
  plotBar(Name,Bucket,Step*Bucket,1,SUM+BARS+LBL2,Color);
}
Example #8
0
void main()
{
	byte *Content = file_content("Log\\TrendDaily.bin");
	if(!Content) {
		printf("\nFirst produce equity curves!");
		return;
	}
	int i,j,N = 0;
	int MaxN = 0;
	var MaxPerf = 0.0;
	
	while(N<CURVES && *Content) 
	{ 
// extract the next curve from the file
		string Name = Content;
		Content += strlen(Name)+1;
		int Size = *((int*)Content);
		int Length = Size/sizeof(var); // number of values
		Content += 4;
		var *Values = Content;
		Content += Size;

		if(!strstr(Name,SELECT)) continue;

// store the curve		
		Curve[N].Name = Name;
		Curve[N].Length = Length;
		Curve[N].Values = Values;
		var Performance = 1.0/ProfitFactor(Values,Length);
		if(MaxPerf < Performance) {
			MaxN = N;
			MaxPerf = Performance;
		}
		printf("\n%s: %.2f",Curve[N].Name,Performance);
		//_plotHistogram("Profit",Performance,BUCKET,RED);
		N++;
	}
	
	PlotScale = 10;
	PlotHeight1 = 300;
	printf("\n\nBenchmark: %s, %.2f", Curve[MaxN].Name,MaxPerf); 

#ifdef WRC
	plotBar("MaxPerf",MaxPerf/BUCKET,MaxPerf,50,BARS+LBL2,BLUE);	
	printf("\nBootstrap - please wait");
	int Worse = 0, Better = 0;
	for(i=0; i<SAMPLES; i++) {
		var MaxBootstrapPerf = 0;
		for(j=0; j<N; j++) {
			randomize(BOOTSTRAP|DETREND,Daily,Curve[j].Values,Curve[j].Length);
			var Performance = 1.0/ProfitFactor(Daily,Curve[j].Length);
			MaxBootstrapPerf = max(MaxBootstrapPerf,Performance);
		}
		printf(".");
		if(MaxPerf > MaxBootstrapPerf)
			Better++;
		else
			Worse++;
		_plotHistogram("Profit",MaxBootstrapPerf,BUCKET,RED);
		progress(100*i/SAMPLES,0);
	}
	printf("\nBenchmark beats %.0f%% of samples!",
		(var)Better*100./(Better+Worse));
#endif
}