Hello Zorro-Traders,

and those, who are joining from MT4.

To work with Zorro and compare or convert EA's to Zorro-Scripts you have to know the differences between the two platforms.

I'm explaining it from my point of view and as a new user of Zorro and an oldie trader and EA-Coder with MT4.

There are differences between backtesting in MT4 and Zorro. The main differences and features every MT4 User is waiting for:

Mutlitimeframing- and Multicurrency-Testing to name two.

First i have to mention the two different modes for backtesting in MT4 and than compare this with Zorro.

With MT4 there are 3 methods available for Backtesting:
Every Tick (Which is the most precise method)
Open Prices only (the fastest method to analyze the bar just completed)

With Zorro there is 1 method available for Backtesting:
Close Prices (a very fast method)

The differences an EA is executed in MT4 with the 'Open Prices Only'-Method is, that at the OPEN of a new candle the start()-function is executed and if the trade-conditions allow a trade an order is placed immediatly.
In Zorro the equivalent function run() is executed at the CLOSE of the current candle and if the trade-conditions allow a trade an order is placed at the OPEN of the following candle.

These leads to differences if you need price or indicator values from different candles or bars.
Be aware not to be confused with candle and bars. In Zorro they have different meanings. And has nothing to do with the visual representation of candles- and bar-charts, which are from the view of definition are the same, except, that they looks different in the chart.

Here is the definition of Bars and Candles in Zorro: Bars&Candles

Quote:
...several bars can be inside a candle...


This is because of the parameters: BarPeriod and TimeFrame.
But this later.

Now the differences of values of a bar in Zorro and MT4

In MT4 if you requesting values from indicators like a MA you use the bar-index 1 to get the value (crossing, breaking or touching), because, like I mentioned above, that MT4 execute the start()-function at the OPEN of the new candle.
In Zorro if you requesting values you you have to use the bar-index 0 to get the same value like in MT4, because Zorro execute the run()-function at the End of a bar.
This is the big differences i'd like to show with both scripts

Here is the MT4-Version:

Code:
int start()
  {
   double MAHigh  = iMA(Symbol(),0,5,0,MODE_EMA, PRICE_HIGH,1); //The Value of a MA-High at the candle-index 1
   double MALow = iMA(Symbol(),0,5,0,MODE_EMA, PRICE_LOW,1);   //The Value of a MA-Low at the candle-index 1
   double priceClose = Close[1];       //The Close-Price of the last Candle at Index 1
   double priceOpen = Open[1];         //The Open-Price of the last Candle at Index 1
   //Creating a Short Signal in MT4
   if( priceOpen > MAHigh
      && priceClose < MAHigh
      && priceClose > MALow)
   {
      OrderSend(Symbol(),OP_SELL, 0.1,Bid, 100,0,0,"",0,0,Green);
   }
   return(0);
  }



And here is code in Zorro (wrong one, because of the same candle-indices):

Code:
function run()
{
	var* priceH = series(priceHigh());
	var* priceL = series(priceLow());
	var *EMAHigh = series(EMA(priceH,5));
	var *EMALow = series(EMA(priceL, 5));
	
	//Short 0
	if(priceOpen(1) > EMAHigh[1]
	and priceClose(1) < EMAHigh[1]
	and priceClose(1) > EMALow[1])
	{
		{
		
			enterShort();
		}
	}
}



And here the picture, where i compare the trades (left MT4 / right Zorro):


MT4ZorroComparison

You see that, with that Zorro-Code, the trades will be executed one bar later than in MT4.
To solve this problem you have to change the indices in the Zorro-Code to have the same trade-executions like this:

Code:
function run()
{
	var* priceH = series(priceHigh());
	var* priceL = series(priceLow());
	var *EMAHigh = series(EMA(priceH,5));
	var *EMALow = series(EMA(priceL, 5));
	
	//Short 0
	if(priceOpen(0) > EMAHigh[0]
	and priceClose(0) < EMAHigh[0]
	and priceClose(0) > EMALow[0])
	{
			enterShort();
		}
	}
}



This is the first part of comparison and hints you have to know to use Zorro correctly.

Last edited by PriNova; 11/21/12 12:53.