1. Welcome back! Thank you for being a part of this Traders Community. Let's discuss and share :)
    Selamat datang kembali! Trimakasih telah menjadi bagian dari Komunitas Trader ini. Mari berdiskusi dan berbagi :)
    Dismiss Notice

Suggestion Compare MQL and Zorro Trader

Discussion in 'Belajar MQL dari Nol' started by PCWalker, 01 Dec 2016.

  1. PCWalker

    PCWalker Member Credit Hunter

    Equity
    Credit
    Ref Point
    Dear Users, Traders, and Programmers.

    Here is a following Code for EA in MT4 written in MQL4 : And after you will find the same code for Zorro Trader, compared.

    __________________________________________________________________________
    // MT4 version
    // enter a trade when the RSI12 crosses over 75 or under 25

    int start()
    {
    // get the previous and current RSI values
    double current_rsi = iRSI(Symbol(), Period(), 12,
    PRICE_CLOSE, 1); // mind the '1' - candle '0' is incomplete!!
    double previous_rsi = iRSI(Symbol(), Period(), 12, PRICE_CLOSE, 2);

    // set up stop / profit levels

    double stop = 200*Point;
    double takeprofit = 200*Point;

    // correction for prices with 3, 5, or 6 digits
    int digits = MarketInfo(Symbol(), MODE_DIGITS);
    if (digits == 5 || digits == 3) {
    stop *= 10;
    takeprofit *= 10;
    } else
    if (digits == 6) {
    stop *= 100;
    takeprofit *= 100;
    }


    // find the number of trades
    int num_long_trades = 0;
    int num_short_trades = 0;
    int magic_number = 12345;
    // exit all trades in opposite direction
    for(int i = 0; i < OrdersTotal(); i++)
    {
    // use OrderSelect to get the info for each trade
    if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
    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 crosses below sell level, exit long trades
    if((current_rsi < 25.0) && (previous_rsi >= 25.0))
    OrderClose(OrderTicket(), OrderLots(),
    Bid, 3, Green);
    else
    // otherwise count the trades
    num_long_trades++;
    }

    if(OrderType() == OP_SELL) {
    // if rsi crosses over buy level, exit short trades
    if((current_rsi > 75.0) && (previous_rsi <= 75.0))
    OrderClose(OrderTicket(), OrderLots(),
    Ask, 3, Green);
    else
    // otherwise count the trades
    num_short_trades++;
    }
    }

    // if rsi crosses over buy level, enter long
    if((current_rsi > 75.0) && (previous_rsi <= 75.0)
    && (num_long_trades == 0)) {
    OrderSend(Symbol(), OP_BUY,
    1.0, Ask, 3,
    Ask-stop, Bid+takeprofit,
    "", magic_number,
    0, Green);
    }
    // if rsi crosses below sell level, enter short
    if((current_rsi < 25.0) && (previous_rsi >= 25.0)
    && (num_short_trades == 0)) {
    OrderSend(Symbol(), OP_SELL,
    1.0, Bid, 3,
    Bid+stop, Ask-takeprofit,
    "", magic_number,
    0, Green);
    }

    return(0);
    }
    ________________________________________________________________

    Now Compare it to the following code which does the same in Zorro Trader :
    ________________________________________________________________

    // Zorro version
    // enter a trade when the RSI12 crosses over 75 or under 25

    function run()
    {
    // get the RSI series
    vars Close = series(priceClose());
    vars rsi12 = series(RSI(Close,12));

    // set up stop / profit levels
    Stop = 200*PIP;
    TakeProfit = 200*PIP;

    // if rsi crosses over buy level, exit short and enter long
    if(crossOver(rsi12,75))
    reverseLong(1);
    // if rsi crosses below sell level, exit long and enter short
    if(crossUnder(rsi12,25))
    reverseShort(1);
    }
    ____________________________________________________

    How much time do you think it would take you to learn the above code compared to previous MQL4 version? By the way, The following Video show you, how to code a EA in less the 5 Minutes.

     
    • Like Like x 1
  2. Luis Carlos

    Luis Carlos Member Credit Hunter

    Equity
    Credit
    Ref Point
    Mr Walker, thank you for sharing this knowledge with us :ok::)
     

Share This Page