Gamestudio Links
Zorro Links
Newest Posts
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
Data from CSV not parsed correctly
by EternallyCurious. 04/25/24 10:20
Trading Journey
by howardR. 04/24/24 20:04
M1 Oversampling
by Petra. 04/24/24 10:34
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 827 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 3 1 2 3
MT4 vs. Zorro: Questions, Explanations and Comparing #411931
11/21/12 11:37
11/21/12 11:37
Joined: Sep 2012
Posts: 74
Niedersachsen, Germany
P
PriNova Offline OP
Junior Member
PriNova  Offline OP
Junior Member
P

Joined: Sep 2012
Posts: 74
Niedersachsen, Germany
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.
Re: MT4 vs. Zorro: Questions, Explanations and Comparing [Re: PriNova] #411938
11/21/12 12:33
11/21/12 12:33
Joined: Jul 2000
Posts: 27,982
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,982
Frankfurt
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.

Re: MT4 vs. Zorro: Questions, Explanations and Comparing [Re: jcl] #411944
11/21/12 13:18
11/21/12 13:18
Joined: Sep 2012
Posts: 74
Niedersachsen, Germany
P
PriNova Offline OP
Junior Member
PriNova  Offline OP
Junior Member
P

Joined: Sep 2012
Posts: 74
Niedersachsen, Germany
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.

Last edited by PriNova; 11/21/12 13:21.
Re: MT4 vs. Zorro: Questions, Explanations and Comparing [Re: PriNova] #411947
11/21/12 13:39
11/21/12 13:39
Joined: Sep 2012
Posts: 74
Niedersachsen, Germany
P
PriNova Offline OP
Junior Member
PriNova  Offline OP
Junior Member
P

Joined: Sep 2012
Posts: 74
Niedersachsen, Germany
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. :-)

Last edited by PriNova; 11/21/12 13:40.
Re: MT4 vs. Zorro: Questions, Explanations and Comparing [Re: PriNova] #411948
11/21/12 14:04
11/21/12 14:04
Joined: Jul 2000
Posts: 27,982
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,982
Frankfurt
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!

Re: MT4 vs. Zorro: Questions, Explanations and Comparing [Re: jcl] #411949
11/21/12 14:13
11/21/12 14:13
Joined: Jul 2000
Posts: 27,982
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,982
Frankfurt
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.

Re: MT4 vs. Zorro: Questions, Explanations and Comparing [Re: jcl] #411953
11/21/12 14:40
11/21/12 14:40
Joined: Sep 2012
Posts: 74
Niedersachsen, Germany
P
PriNova Offline OP
Junior Member
PriNova  Offline OP
Junior Member
P

Joined: Sep 2012
Posts: 74
Niedersachsen, Germany
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?

Last edited by PriNova; 11/21/12 14:51.
Re: MT4 vs. Zorro: Questions, Explanations and Comparing [Re: PriNova] #411963
11/21/12 15:17
11/21/12 15:17
Joined: Jul 2000
Posts: 27,982
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,982
Frankfurt
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.

Re: MT4 vs. Zorro: Questions, Explanations and Comparing [Re: jcl] #411965
11/21/12 15:19
11/21/12 15:19
Joined: Jul 2000
Posts: 27,982
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,982
Frankfurt
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.

Re: MT4 vs. Zorro: Questions, Explanations and Comparing [Re: jcl] #411971
11/21/12 15:47
11/21/12 15:47
Joined: Sep 2012
Posts: 74
Niedersachsen, Germany
P
PriNova Offline OP
Junior Member
PriNova  Offline OP
Junior Member
P

Joined: Sep 2012
Posts: 74
Niedersachsen, Germany
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;
}


Page 1 of 3 1 2 3

Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1