I'm playing with some new features I got from the updated Workshop 5 tutorial (which will presumably appear in an upcoming Zorro version)...

Listed below are the small modifications I made to Workshop5_3 to play with this. But what I'm interested in at the moment is the result chart... look at these 2 charts. One implements the new function which limits max trades to 1. The other has no limits.

Look specifically at the timeframe of 2009. I would like to know why Zorro takes trades when there is no limit, but when trades are limited via the function it does not. Seems like it should at least take 1 trade during this period.

I'm just trying to understand the "why" about this. Thanks in advance if you can shed any light...

Code:
// Workshop 5: Counter trend trading, optimized ////////////////

function reverseShort(int MaxTrades)
{
// update the stops and profit targets of open trades
  if(Stop > 0) 
    exitShort(0,priceClose()+Stop);
  if(TakeProfit > 0) 
    exitShort(0,(priceClose()+TakeProfit));
 
// if MaxTrades is not reached, open a new trade
  if(NumOpenShort < MaxTrades)
    enterShort();
// otherwise, close all opposite trades
  else if(!mode(HEDGING))
    exitLong();
  return 0;
}

function reverseLong(int MaxTrades)
{
// update the stops and profit targets of open trades
  if(Stop > 0) 
    exitLong(0,priceClose()-Stop);
  if(TakeProfit > 0) 
    exitLong(0,-(priceClose()+TakeProfit));
 
// if MaxTrades is not reached, open a new trade
  if(NumOpenLong < MaxTrades)
    enterLong();
// otherwise, close all opposite trades
  else if(!mode(HEDGING))
    exitShort();
  return 0;
}

function run()
{
	set(PARAMETERS+NFA);  // generate and use optimized parameters
	BarPeriod = 240;	// 4 hour bars
	LookBack = 500;
	StartDate = 2002;
	NumWFOCycles = 5; // activate WFO

	if(ReTrain) {
		UpdateDays = -1;	// update price data from the server 
		SelectWFO = -1;	// select the last cycle for re-optimization
	}
	
// calculate the buy/sell signal
	vars Price = series(price());
	vars DomPeriod = series(DominantPeriod(Price,30));
	var LowPeriod = LowPass(DomPeriod,500);
	vars HP = series(HighPass(Price,LowPeriod*optimize(1,0.5,2)));
	vars Signal = series(Fisher(HP,500));
	var Threshold = optimize(1,0.5,2,0.1);

// buy and sell
	Stop = optimize(4,2,8) * ATR(100);
	Trail = 4*ATR(100);
	if(crossUnder(Signal,-Threshold))
		reverseLong(1); //max 1 trade, update stops
		//enterLong();
	else if(crossOver(Signal,Threshold))
		reverseShort(1); //max 1 trade, update stops
		//enterShort();

	PlotWidth = 800;
	PlotHeight1 = 300;
}


Attached Files
EURUSD_max1trade.png (19 downloads)
EURUSD_nolimit.png (18 downloads)