MT4 vs. Zorro: Questions, Explanations and Comparing

Posted By: PriNova

MT4 vs. Zorro: Questions, Explanations and Comparing - 11/21/12 11:37

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.
Posted By: jcl

Re: MT4 vs. Zorro: Questions, Explanations and Comparing - 11/21/12 12:33

Wow, that's a lot of confusion!

Of course trades happen at exactly the same time in Zorro and in MT4. I think the problem arises from some special MT4 issues, which require some re-thinking when switching from MT4 to another platform.

Most trade platforms count the candles with indices [0], [1], [2], where [0] is the last full candle. For MT4 however, [1] is the last full candle (I suppose), and [0] is an incomplete candle that is just building. So the close of the last full candle is Close[1] in MT4, but Close[0] in other platforms.

Indicators need full candles. So in MT4 the indicators probably ignore candle [0]. At least I hope this, otherwise MT4 would give incoherent results in the simulation. MT4 trade signals are thus generated from candle[1] and MT4 executes the trades at the begin of candle[0], at exactly the same time as Zorro and all other platforms.

I hope I have described this correctly, as I'm no MT4 expert.

- The TICKS flag does not cause Zorro's run function to run every tick, as in MT4. This would make no sense because Zorro supports pending trades. Instead, the TICKS flag causes a possible trade management function, which can be used for complex trade entry and exit conditions, to run every tick in the simulation.

- Testing with multiple currencies and time frames is explained in Workshop 6.

- If you want any feature that you think MQL4 can do and Zorro not, just request it on the future forum. MQL4 is very minimalistic and lacks many language features, so if it really has something that other platforms don't have, it should be easy to implement.
Posted By: PriNova

Re: MT4 vs. Zorro: Questions, Explanations and Comparing - 11/21/12 13:18

Yes, that's very confusing. Now you know, why i had to clarify things and this I want to give back to all, who choose to change from MT4 to Zorro, which in my eyes is very important to know.

To answer your question: yes, in MT4 is the candle[0] is the incomplete building candle. And MT4 does not ignore Candle[0], which includes the current calculations of every indicator. This is important, because some indicators needs Ticks for calculation.
Or how else could you simulate the exact breakout at the last Swing High/Low? Or how could you calculate the Momentum of the incomplete candle?
Please answer me this question.

Maybe you now Markttechnik from Michael Voigt or some knows 1-2-3 Pattern Trading, where an Order will be executed exactly at the breakout at Point 2.
This will not work in Zorro, because Zorro can not fetch Values from the incomplete candle and open an Order after the breakout, which could lead to fewer gain. Zorro is able to fetch the actual Tickprice and if i compare it, where just in these moment the Tick crosses the last High/Low. Very often the price become very strong momentum at these levels.
Posted By: PriNova

Re: MT4 vs. Zorro: Questions, Explanations and Comparing - 11/21/12 13:39

I uploaded a picture for those, who not knows what is 1-2-3 Pattern Breakout-Trading.

This scenario happens very often in every TimeFrame. And quick Order-Execution at Breakout is very important here.

If too late, the move is gone.


BreakoutTrade

And yes, i'm willing to make Zorro better than MT4 so we have the same goal. :-)
Posted By: jcl

Re: MT4 vs. Zorro: Questions, Explanations and Comparing - 11/21/12 14:04

Thanks for the example. Such a breakout strategy would normally place an entry stop at the breakout level - the (2) price in your chart above. Zorro will then execute the trade at the same "Breakout point 2" as MT4 in your chart above, regardless of the bar period. Just try it!
Posted By: jcl

Re: MT4 vs. Zorro: Questions, Explanations and Comparing - 11/21/12 14:13

By the way, are you sure that MT4 really uses incomplete candles for its indicators? This would be a severe bug in my opinion.

For instance, the ATR is a very often used indicator. It is based on the high and low of a candle. When prices follow a normal distribution, the high-low distance is proportional to the square root of the candle width. Incomplete candles have thus a smaller vertical size than full candles. They would cause false trade signals or wrong stop levels when used for an ATR. At the begin of the candle, the high-low distance would even be zero.

Many other indicators would also be wrong when incomplete candles are used.
Posted By: PriNova

Re: MT4 vs. Zorro: Questions, Explanations and Comparing - 11/21/12 14:40

yes, sure. here is the ATR code:

Code:
i=Bars-counted_bars-1;
   while(i>=0)
     {
      double high=High[i];
      double low =Low[i];
      if(i==Bars-1) TempBuffer[i]=high-low;
      else
        {
         double prevclose=Close[i+1];
         TempBuffer[i]=MathMax(high,prevclose)-MathMin(low,prevclose);
        }
      i--;
     }
//----
   if(counted_bars>0) counted_bars--;
   int limit=Bars-counted_bars;
   for(i=0; i<limit; i++)
      AtrBuffer[i]=iMAOnArray(TempBuffer,Bars,AtrPeriod,0,MODE_SMA,i);



in the first while()
it calculates the ATR of every candle into an arry, included the first incomplete
and later it smoothes the array with an MA which is the Period you choose for the ATR.

But, and this is what i mentioned above. For setting the Stop for an Order, it takes the ATR-value from the last closed candle ( candle[1], which is in Zorro candle[0] ), but the freedom has the developer of the EA to take index 0,1 or 15 to use ATR for Stop.
In an EA to get the value of an indicator it will look like this:

Code:
double = iATR(Symbol(), TF, Period, Shift)



The Shift-parameter here is from what history candle the ATR value should be taken. All indicators in MT4 has this shift parameter.
An EA-Developer should know that, if values are needed as Order-Conditions for TP, SL, BE, Trailing or Exit or whatever, that it is best to take the value at index 1 insteed 0, because of the incomplete candle. But this is also the freedom you have in MT4 and the possibilty to trade like in the example at my last post for breakouts.

And this is the difference between index-counting in MT4 and Zorro which is important to know.

I would not say wrong, they only reflect the realtime situation at the incomplete candle. But for decision-making it is better to take values from complete candles, except for breakout-trades, momentum-trading and to trade with pending orders at exactly at Support/Resistance-Levels.
So this is my call to the future of Zorro, let tick-based calculation involve.
If this will work, then Pending Orders, like Stops and Limits will work too.
Develope a global Parameter, where the user could define, if he needs this or not.
For setting Pending-Orders for entry's it is inevitable.

Another question:

How is it possible to trade a grid with the trend/countertrend (pyramiding/cost averaging) with exact x-Pips spacing between every order?
Posted By: jcl

Re: MT4 vs. Zorro: Questions, Explanations and Comparing - 11/21/12 15:17

It's a different design philosophy. Zorro is designed not after MT4, but more after TradeStation or similar tools. All high-end platforms support pending trades directly, and thus normally have no need for tick based price comparison with all those problems of incomplete candles and so on.

Anyway, I think it is good to know the different count of candles in MT4 and Zorro, as other users will run in the same issue.

Early Zorro versions had indeed a tick based run function, and we can certainly reactivate it when it's needed for a certain strategy and there is no other solution.
Posted By: jcl

Re: MT4 vs. Zorro: Questions, Explanations and Comparing - 11/21/12 15:19

As to grid trading, you normally use pending trades for that. A grid trader can place many trades with different entry levels at the same time. If you can give me a detailed example for the spacing algorithm I can tell you how it would be coded.
Posted By: PriNova

Re: MT4 vs. Zorro: Questions, Explanations and Comparing - 11/21/12 15:47

Pseudocode for pyramiding into a sell-off:

Code:
prevShortPrice = NULL;                            //this is were the last Order lies, could be stored into this variable or directly fedged from Order-Management-System
numShortLevels = 10;            //this is the maximum of orders allowed in one direction.

If (numShort() != 0 and prevShortPrice != NULL and numShort() <= numShortLevels)
{
   if( (prevShortPrice - Bid) >= 25_Pips )      //or ATR(x) instead 25 Pips
   {
       enterShort();
       prevShortPrice = currentlyEnteredOrderprice;    //currentlyEnteredOrderprice is the Openprice of the current enterShort()-execution
   }
}

If (numShort() == 0 and whatever_Condition == TRUE)
{
   enterShort();
   prevShortPrice = currentlyEnteredOrderprice;
}

Posted By: jcl

Re: MT4 vs. Zorro: Questions, Explanations and Comparing - 11/21/12 16:13

Code:
if(whatever_Condition == TRUE) {
  TimeWait = 1000; 
  for(i = NumOpenShort; i < numShortLevels; i++)
     enterShort(0,priceClose() - i*25*PIP);
}

Posted By: PriNova

Re: MT4 vs. Zorro: Questions, Explanations and Comparing - 11/21/12 16:31

you are brillant. i will check this out soon after i post my strange WFO-Report i found again. ;-)
Posted By: PriNova

Re: MT4 vs. Zorro: Questions, Explanations and Comparing - 11/21/12 19:00

oh, it doesn't work. sorry to bother you, but it opens more trades then in the numShortLevels defined and the spacing between is random.

here the code i use:

Code:
int numShortLevels = 10;
int numLongLevels = 2;
bool flg = TRUE;
int i;
function run()
{
	StartDate = 2012;
	//set(TICKS);
	if(numShort() == 0 and flg == TRUE)
	{
		enterShort();
		flg = FALSE;
	}
	
		TimeWait = 1000; 
		for(i = NumOpenShort; i < numShortLevels; i++)
		{
			enterShort(0, priceClose() - i*300*PIP);
		}
	 
}



maybe i'm doing something wrong. i think it has something to do with the priceClose() in the enterShort().
it doesnt need the priceClose(), what it needs is the OrderOpenPrice of the last opened order to calculate the spacing, but i don't know how to get this values.
i looked into the trading.h, but didn't get the TRADE struct to work.
Posted By: jcl

Re: MT4 vs. Zorro: Questions, Explanations and Comparing - 11/21/12 19:54

You're right. The price problem can be easily solved, but the more serious problem is that it opens up to 10 new pending trades with different price levels at each bar because it checks only the number of open trades, but not the number of pending trades.

We could cycle through all trades and check how many are pending, but the better solution is just to implement two variables NumPendingShort and NumPendingLong. This will be implemented in the next Zorro update.
Posted By: SFF

Re: MT4 vs. Zorro: Questions, Explanations and Comparing - 11/26/12 00:44

Is it possible in zorro to open or close trades at less than 1min?
For example I enter trade at 14:01:34 and close at 14:32:25.
Posted By: jcl

Re: MT4 vs. Zorro: Questions, Explanations and Comparing - 11/26/12 08:14

Yes, either with a trade function that checks the current time and opens or exits at a certain time, or just with an entry or exit limit. The trade is then opened when the limit condition is met.
Posted By: SFF

Re: MT4 vs. Zorro: Questions, Explanations and Comparing - 02/05/13 01:12

in current Zorro, is it possble to use incomplete bar which in MT4 is [0] index?

And I wanted to use current price which is in it just ASK or BID.
[0] of closeprice seems just only close price as Zorro just not use incomplete bar.

Thanks in advance.
Posted By: jcl

Re: MT4 vs. Zorro: Questions, Explanations and Comparing - 02/05/13 10:06

Yes. It's not recommended, but possible of course. There are several ways, for instance with a trade function. Let me know what you want to do with the current price and I'll tell you the best way for this.
Posted By: SFF

Re: MT4 vs. Zorro: Questions, Explanations and Comparing - 02/05/13 10:08

I want to use zigzag indicator for exit and want to see zigzag value in real time.
Posted By: jcl

Re: MT4 vs. Zorro: Questions, Explanations and Comparing - 02/05/13 10:45

Zigzag uses no incomplete candles. Aside from the fact that it repaints and thus can not be used for trade signals, you can implement it like any other indicator.
Posted By: SFF

Re: MT4 vs. Zorro: Questions, Explanations and Comparing - 02/05/13 10:52

How to see real time value for RSI?
I just see if RSI is now above/below 50 in real time.
Posted By: jcl

Re: MT4 vs. Zorro: Questions, Explanations and Comparing - 02/05/13 11:12

Zorro is a trading robot. It does not have real time chart windows. For a real time RSI curve, a conventional platform is better, for instance Ninja Trader.

If you want no chart but only see if RSI is above/below 50, you can use Zorro - it can display the real time RSI value in a slider. If you want that, I can show you how.
Posted By: SFF

Re: MT4 vs. Zorro: Questions, Explanations and Comparing - 02/05/13 12:42

I just want to use a incomplete current bar like MT4 to trade my way.
Is there any manual about it?
Posted By: jcl

Re: MT4 vs. Zorro: Questions, Explanations and Comparing - 02/05/13 15:49

Sure, here: http://manual.zorro-trader.com/trade.htm

Call enterLong(f), where f is your function that uses an incomplete candle for finding an entry. This function is called whenever a price quote arrives. The price() functions work as before, they are just in the middle of the candle now. When the entry condition is met, let f return with 2 to execute the trade, otherwise with 0.

Don't try this with normal strategies, though. Many indicators have wrong values when the last candle is incomplete, and using them for trade signals is not a good idea.
Posted By: SFF

Re: MT4 vs. Zorro: Questions, Explanations and Comparing - 02/05/13 22:50

Thank you, I will try.
Posted By: Sundance

Re: MT4 vs. Zorro: Questions, Explanations and Comparing - 05/25/13 14:13

Just my 2 cents: I mentioned the problem of the 'senseless' close[0] value already in Steve Hopwoods forum where he agreed that this was one of the problems of his EAs.

PS: Some late reply from me but i'am just three days a member here :-)
© 2024 lite-C Forums