Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
3 registered members (NewbieZorro, TipmyPip, AndrewAMD), 14,749 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Converting EAs from MT4 #411753
11/19/12 15:06
11/19/12 15:06
Joined: Jul 2000
Posts: 28,024
Frankfurt
jcl Offline OP

Chief Engineer
jcl  Offline OP

Chief Engineer

Joined: Jul 2000
Posts: 28,024
Frankfurt
As an example how to convert MQL4 to lite-C, here's a simple EA and its lite-C equivalent. Usually EAs get much shorter when converted to Zorro.

MT4:
Code:
// trade when the RSI goes above or below a level
int start()
{
   string algo = "RSI"
   int rsi_period = 12;
   double rsi_buy_level = 75.0;
   double rsi_sell_level = 25.0;
 
// get the rsi value
   double rsi_value = iRSI(Symbol(), Period(), rsi_period, 
     PRICE_CLOSE, 1); // mind the '1' - the candle 0 can be incomplete
 
// set up stop / profit levels
   int stoploss = 200*Point;
   int takeprofit = 200*Point;
   int magic_number = 12345;
 
// number of open trades for this EA
   int num_long_trades = 0;
   int num_short_trades = 0;

// total number of trades for the entire account
   int all_trades = OrdersTotal();
    
// cycle through all open trades
   int i;
   for(i = 0; i < all_trades; i++)
   {
// use OrderSelect to get the info for each trade
     if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == false) 
       continue;

// Trades not belonging to our EA are also found, so it's necessary to
// compare the EA magic_number with the order's magic number
     if(magic_number != OrderMagicNumber()) 
       continue;

     if(OrderType() == OP_BUY)
     {
// if rsi is below sell level, exit long trades
       if(rsi_value < rsi_sell_level)
         OrderClose(OrderTicket(), OrderLots(), 
           Bid, 3, Green);
       else
// otherwise count the trades
         num_long_trades++;
     }
 
     if(OrderType() == OP_SELL)
     {
// if rsi is above buy level, exit short trades 
       if(rsi_value > rsi_buy_level))
         OrderClose(OrderTicket(), OrderLots(), 
           Ask, 3, Green);
       else
// otherwise count the trades
         num_short_trades++;
     }
   }
 
// if rsi is above buy level, enter long 
   if((rsi_value > rsi_buy_level) 
     && (num_long_trades == 0)) {
     OrderSend(Symbol(), OP_BUY, 
       1.0, Ask, 3,
       Ask - stoploss, Bid + takeprofit, 
       algo, magic_number, 
       0, Green);
   }
// if rsi is below sell level, enter short
   if((rsi_value < rsi_sell_level) 
     && (num_short_trades == 0)) {
     OrderSend(Symbol(), OP_SELL, 
       1.0, Bid, 3, 
       Bid + stoploss, Ask - takeprofit, 
       algo, magic_number, 
       0, Green);
   }
 
   return(0); 
}



Zorro 1.03:
Code:
// trade when the RSI goes above or below a level
function run()
{
  algo("RSI");
  var rsi_period = 12;
  var rsi_buy_level = 75;
  var rsi_sell_level = 25; 
 
// get the rsi value
  var rsi_value = RSI(series(priceClose()),rsi_period);
   
// set up stop / profit levels
  Stop = 200*PIP;
  TakeProfit = 200*PIP;
 
// if rsi is above buy level, exit short and enter long
  if(rsi_value > rsi_buy_level) {
    exitShort();
    if(NumOpenLong == 0) enterLong();
  }
// if rsi is below sell level, exit long and enter short
  if(rsi_value < rsi_sell_level) {
    exitLong();
    if(NumOpenShort == 0) enterShort();
  }
}


Re: Converting EAs from MT4 [Re: jcl] #411986
11/21/12 17:49
11/21/12 17:49
Joined: Aug 2012
Posts: 14
Wigston
L
leeb77 Offline
Newbie
leeb77  Offline
Newbie
L

Joined: Aug 2012
Posts: 14
Wigston
really useful example thanks

Re: Converting EAs from MT4 [Re: leeb77] #413069
12/07/12 12:29
12/07/12 12:29
Joined: Nov 2012
Posts: 209
S
SFF Offline
Member
SFF  Offline
Member
S

Joined: Nov 2012
Posts: 209
Thank you for an example.

MT4 version didn't work.

Re: Converting EAs from MT4 [Re: SFF] #413072
12/07/12 14:15
12/07/12 14:15
Joined: Jul 2000
Posts: 28,024
Frankfurt
jcl Offline OP

Chief Engineer
jcl  Offline OP

Chief Engineer

Joined: Jul 2000
Posts: 28,024
Frankfurt
There's a newer MT4 version in the help file:

http://zorro-trader.com/manual/en/conversion.htm

Re: Converting EAs from MT4 [Re: jcl] #413078
12/07/12 16:07
12/07/12 16:07
Joined: Nov 2012
Posts: 209
S
SFF Offline
Member
SFF  Offline
Member
S

Joined: Nov 2012
Posts: 209
Thank you. The new version works fine.
Do you know Jforex platform from Dukascopy?
It's code is Java based.

Last edited by SFF; 12/07/12 16:23.

Moderated by  Petra 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1